{"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s665088990", "group_id": "codeNet:p02536", "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 :cp/util) :silent t)\n #+swank (use-package :cp/util :cl-user)\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 (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 (define-int-types (&rest bits) `(progn ,@(mapcar (lambda (b) `(def ,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;;; 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(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/disjoint-set :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (dset (make-disjoint-set n))\n (comp n))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (when (ds-unite! dset a b)\n (decf comp))))\n (println (- comp 1))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(progn\n (defparameter *lisp-file-pathname* (uiop:current-lisp-file-pathname))\n (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *lisp-file-pathname*))\n (defparameter *problem-url* \"https://atcoder.jp/contests/abl/tasks/abl_c\"))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-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 (or (> sb-c::*compiler-warning-count* 0)\n sb-c::*undefined-warnings*)\n (error \"count: ~D, undefined warnings: ~A\"\n sb-c::*compiler-warning-count*\n sb-c::*undefined-warnings*)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(5am:test :sample\n (5am:is\n (equal \"1\n\"\n (run \"3 1\n1 2\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1601168595, "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/s665088990.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s665088990", "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 :cp/util) :silent t)\n #+swank (use-package :cp/util :cl-user)\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 (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 (define-int-types (&rest bits) `(progn ,@(mapcar (lambda (b) `(def ,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;;; 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(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/disjoint-set :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (dset (make-disjoint-set n))\n (comp n))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (when (ds-unite! dset a b)\n (decf comp))))\n (println (- comp 1))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(progn\n (defparameter *lisp-file-pathname* (uiop:current-lisp-file-pathname))\n (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *lisp-file-pathname*))\n (defparameter *problem-url* \"https://atcoder.jp/contests/abl/tasks/abl_c\"))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-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 (or (> sb-c::*compiler-warning-count* 0)\n sb-c::*undefined-warnings*)\n (error \"count: ~D, undefined warnings: ~A\"\n sb-c::*compiler-warning-count*\n sb-c::*undefined-warnings*)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(5am:test :sample\n (5am:is\n (equal \"1\n\"\n (run \"3 1\n1 2\n\" nil))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6037, "cpu_time_ms": 41, "memory_kb": 26248}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s447904325", "group_id": "codeNet:p02538", "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 :cp/util) :silent t)\n #+swank (use-package :cp/util :cl-user)\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 (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 (define-int-types (&rest bits) `(progn ,@(mapcar (lambda (b) `(def ,b)) bits))))\n (define-int-types 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 998244353)\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;; DEFINE-INTEGER-PACK and DEFINE-CONS-PACK are so to say poor man's variants of\n;; DEFSTRUCT. Both \"structures\" can only have slots of fixed unsigned\n;; bytes. DEFINE-INTEGER-PACK handles the concatenated slots as UNSIGNED-BYTE\n;; and DEFINE-CONS-PACK handles them as (CONS (UNSIGNED-BYTE 62) (UNSIGNED-BYTE\n;; 62)).\n\n;; Example:\n;; The following form defines the type NODE as (UNSIGNED-BYTE 9):\n;; (define-integer-pack node (slot1 3) (slot2 5) (slot3 1))\n;; This macro in addition defines relevant utilities: NODE-SLOT1, NODE-SLOT2,\n;; NODE-SLOT3, setters and getters, PACK-NODE, the constructor, and\n;; WITH-UNPACKING-NODE, the destructuring-bind-style macro.\n;; \n;; DEFINE-CONS-PACK is almost the same as DEFINE-INTEGER-PACK though it will be\n;; suitable for the total bits in the range [63, 124].\n\n(defpackage :cp/integer-pack\n (:use :cl)\n (:export #:define-integer-pack #:define-cons-pack))\n(in-package :cp/integer-pack)\n\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-integer-pack (name &rest slot-descriptions)\n (assert slot-descriptions () \"~A has no slots.\" name)\n (let* ((packer-name (intern (%concat-name \"PACK\" name)))\n (unpacker-macro-name (intern (%concat-name \"WITH-UNPACKING\" name)))\n (total-size 0)\n (slots (loop with position = 0\n for (slot-name slot-size) in slot-descriptions\n collect (progn (check-type slot-name symbol)\n (check-type slot-size (integer 1))\n (list slot-name slot-size position))\n do (incf position slot-size)\n finally (setq total-size position)))\n (revslots (reverse slots))\n (new-value (gensym \"NEW-VALUE\"))\n (tmp (gensym)))\n `(progn\n (deftype ,name () '(unsigned-byte ,total-size))\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-name slot-size slot-position) in slots\n for accessor-name = (intern (%concat-name name slot-name))\n append `((declaim (inline ,accessor-name\n (setf ,accessor-name)))\n (defun ,accessor-name (,name)\n (declare (type ,name ,name))\n (ldb (byte ,slot-size ,slot-position) ,name))\n (defun (setf ,accessor-name) (,new-value ,name)\n (declare (type ,name ,name))\n (setf (ldb (byte ,slot-size ,slot-position) ,name) ,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 _) in slots\n collect `(type (unsigned-byte ,slot-size) ,slot-name )))\n (let ((,tmp ,(caar revslots)))\n (declare (type (unsigned-byte ,total-size) ,tmp))\n ,@(loop for (slot-name slot-size _) in (cdr revslots)\n collect `(setq ,tmp (logxor ,slot-name\n (the (unsigned-byte ,total-size)\n (ash ,tmp ,slot-size)))))\n ,tmp))\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 (declare (type (unsigned-byte ,,total-size) ,',tmp))\n (let* ,(loop for var in vars\n for rest on ',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) ,',tmp))\n ,@(when (cdr rest)\n `((setq ,',tmp (ash ,',tmp ,(- slot-size))))))))\n ,@body))))))\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 violated: 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(defpackage :cp/mod-power-table\n (:use :cl)\n (:export #:make-mod-power-table))\n(in-package :cp/mod-power-table)\n\n(declaim (inline make-mod-power-table))\n(defun make-mod-power-table (base length modulus &optional (element-type '(unsigned-byte 31)))\n \"Returns a vector of the given length: VECTOR[x] := BASE^x mod MODULUS.\"\n (declare (fixnum base)\n ((integer 0 #.most-positive-fixnum) length)\n ((integer 1 #.most-positive-fixnum) modulus))\n (let ((res (make-array length :element-type element-type)))\n (unless (zerop length)\n (setf (aref res 0) 1)\n (loop for i from 1 below length\n do (setf (aref res i)\n (mod (* base (aref res (- i 1))) modulus))))\n res))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defpackage :cp/mod-operations\n (:use :cl)\n (:export #:define-mod-operations))\n(in-package :cp/mod-operations)\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\n(defmacro define-mod-operations (divisor &optional (package (sb-int:sane-package)))\n (let ((mod* (intern \"MOD*\" package))\n (mod+ (intern \"MOD+\" package))\n (incfmod (intern \"INCFMOD\" package))\n (decfmod (intern \"DECFMOD\" package))\n (mulfmod (intern \"MULFMOD\" package)))\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 (sb-ext: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(define-mod-operations cl-user::+mod+ :cl-user)\n\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; TODO: abstraction\n\n(defpackage :cp/implicit-treap\n (:use :cl :cp/mod-operations :cp/mod-power-table :cp/integer-pack)\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 #:pack-node #:node-x))\n(in-package :cp/implicit-treap)\n\n;; Note:\n;; - An empty treap is NIL.\n\n(define-mod-operations cl-user::+mod+)\n\n(declaim ((simple-array (unsigned-byte 31) (*)) *power10*))\n(declaim ((simple-array (unsigned-byte 31) (* *)) *table*))\n(sb-ext:define-load-time-global *power10*\n (make-mod-power-table 10 200001 cl-user::+mod+))\n(sb-ext:define-load-time-global *table*\n (make-array '(10 200001) :element-type '(unsigned-byte 31) :initial-element 0))\n\n(loop for d from 1 to 9\n do (loop for i from 1 to 200000\n do (setf (aref *table* d i)\n (mod+ d (mod* (aref *table* d (- i 1)) 10)))))\n\n(define-integer-pack node (x 31) (l 31))\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (declare (node a b))\n (with-unpacking-node (x1 l1) a\n (with-unpacking-node (x2 l2) b\n (pack-node (mod+ (mod* x1 (aref *power10* l2))\n x2)\n (mod+ l1 l2)))))\n\n(sb-int:defconstant-eqx +op-identity+ 0 #'equal\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 (if (zerop x)\n lazy\n x))\n\n(defconstant +updater-identity+ 0\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 (node acc))\n (if (zerop lazy)\n acc\n (let ((l (node-l acc)))\n (pack-node (aref *table* lazy l) l))))\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 (unsigned-byte 8))\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-element)\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 (or initial-element\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/integer-pack :cl-user))\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/mod-power-table :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/implicit-treap :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-operations :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((n (read))\n (q (read))\n (itreap (make-itreap n :initial-element (pack-node 1 1))))\n (declare (uint31 n q))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ q)\n (let ((l (- (read-fixnum) 1))\n (r (read-fixnum))\n (d (read-fixnum)))\n (setq itreap (itreap-update itreap d l r))\n (println (node-x (itreap-accumulator itreap)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(progn\n (defparameter *lisp-file-pathname* (uiop:current-lisp-file-pathname))\n (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *lisp-file-pathname*))\n (defparameter *problem-url* \"https://atcoder.jp/contests/abl/tasks/abl_e\"))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-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 (or (> sb-c::*compiler-warning-count* 0)\n sb-c::*undefined-warnings*)\n (error \"count: ~D, undefined warnings: ~A\"\n sb-c::*compiler-warning-count*\n sb-c::*undefined-warnings*)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(5am:test :sample\n (5am:is\n (equal \"11222211\n77772211\n77333333\n72333333\n72311333\n\"\n (run \"8 5\n3 6 2\n1 4 7\n3 8 3\n2 2 2\n4 5 1\n\" nil)))\n (5am:is\n (equal \"641437905\n\"\n (run \"200000 1\n123 456 7\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1601192406, "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/s447904325.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s447904325", "user_id": "u352600849"}, "prompt_components": {"gold_output": "11222211\n77772211\n77333333\n72333333\n72311333\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 :cp/util) :silent t)\n #+swank (use-package :cp/util :cl-user)\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 (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 (define-int-types (&rest bits) `(progn ,@(mapcar (lambda (b) `(def ,b)) bits))))\n (define-int-types 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 998244353)\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;; DEFINE-INTEGER-PACK and DEFINE-CONS-PACK are so to say poor man's variants of\n;; DEFSTRUCT. Both \"structures\" can only have slots of fixed unsigned\n;; bytes. DEFINE-INTEGER-PACK handles the concatenated slots as UNSIGNED-BYTE\n;; and DEFINE-CONS-PACK handles them as (CONS (UNSIGNED-BYTE 62) (UNSIGNED-BYTE\n;; 62)).\n\n;; Example:\n;; The following form defines the type NODE as (UNSIGNED-BYTE 9):\n;; (define-integer-pack node (slot1 3) (slot2 5) (slot3 1))\n;; This macro in addition defines relevant utilities: NODE-SLOT1, NODE-SLOT2,\n;; NODE-SLOT3, setters and getters, PACK-NODE, the constructor, and\n;; WITH-UNPACKING-NODE, the destructuring-bind-style macro.\n;; \n;; DEFINE-CONS-PACK is almost the same as DEFINE-INTEGER-PACK though it will be\n;; suitable for the total bits in the range [63, 124].\n\n(defpackage :cp/integer-pack\n (:use :cl)\n (:export #:define-integer-pack #:define-cons-pack))\n(in-package :cp/integer-pack)\n\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-integer-pack (name &rest slot-descriptions)\n (assert slot-descriptions () \"~A has no slots.\" name)\n (let* ((packer-name (intern (%concat-name \"PACK\" name)))\n (unpacker-macro-name (intern (%concat-name \"WITH-UNPACKING\" name)))\n (total-size 0)\n (slots (loop with position = 0\n for (slot-name slot-size) in slot-descriptions\n collect (progn (check-type slot-name symbol)\n (check-type slot-size (integer 1))\n (list slot-name slot-size position))\n do (incf position slot-size)\n finally (setq total-size position)))\n (revslots (reverse slots))\n (new-value (gensym \"NEW-VALUE\"))\n (tmp (gensym)))\n `(progn\n (deftype ,name () '(unsigned-byte ,total-size))\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-name slot-size slot-position) in slots\n for accessor-name = (intern (%concat-name name slot-name))\n append `((declaim (inline ,accessor-name\n (setf ,accessor-name)))\n (defun ,accessor-name (,name)\n (declare (type ,name ,name))\n (ldb (byte ,slot-size ,slot-position) ,name))\n (defun (setf ,accessor-name) (,new-value ,name)\n (declare (type ,name ,name))\n (setf (ldb (byte ,slot-size ,slot-position) ,name) ,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 _) in slots\n collect `(type (unsigned-byte ,slot-size) ,slot-name )))\n (let ((,tmp ,(caar revslots)))\n (declare (type (unsigned-byte ,total-size) ,tmp))\n ,@(loop for (slot-name slot-size _) in (cdr revslots)\n collect `(setq ,tmp (logxor ,slot-name\n (the (unsigned-byte ,total-size)\n (ash ,tmp ,slot-size)))))\n ,tmp))\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 (declare (type (unsigned-byte ,,total-size) ,',tmp))\n (let* ,(loop for var in vars\n for rest on ',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) ,',tmp))\n ,@(when (cdr rest)\n `((setq ,',tmp (ash ,',tmp ,(- slot-size))))))))\n ,@body))))))\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 violated: 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(defpackage :cp/mod-power-table\n (:use :cl)\n (:export #:make-mod-power-table))\n(in-package :cp/mod-power-table)\n\n(declaim (inline make-mod-power-table))\n(defun make-mod-power-table (base length modulus &optional (element-type '(unsigned-byte 31)))\n \"Returns a vector of the given length: VECTOR[x] := BASE^x mod MODULUS.\"\n (declare (fixnum base)\n ((integer 0 #.most-positive-fixnum) length)\n ((integer 1 #.most-positive-fixnum) modulus))\n (let ((res (make-array length :element-type element-type)))\n (unless (zerop length)\n (setf (aref res 0) 1)\n (loop for i from 1 below length\n do (setf (aref res i)\n (mod (* base (aref res (- i 1))) modulus))))\n res))\n\n;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defpackage :cp/mod-operations\n (:use :cl)\n (:export #:define-mod-operations))\n(in-package :cp/mod-operations)\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\n(defmacro define-mod-operations (divisor &optional (package (sb-int:sane-package)))\n (let ((mod* (intern \"MOD*\" package))\n (mod+ (intern \"MOD+\" package))\n (incfmod (intern \"INCFMOD\" package))\n (decfmod (intern \"DECFMOD\" package))\n (mulfmod (intern \"MULFMOD\" package)))\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 (sb-ext: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(define-mod-operations cl-user::+mod+ :cl-user)\n\n;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n;; TODO: abstraction\n\n(defpackage :cp/implicit-treap\n (:use :cl :cp/mod-operations :cp/mod-power-table :cp/integer-pack)\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 #:pack-node #:node-x))\n(in-package :cp/implicit-treap)\n\n;; Note:\n;; - An empty treap is NIL.\n\n(define-mod-operations cl-user::+mod+)\n\n(declaim ((simple-array (unsigned-byte 31) (*)) *power10*))\n(declaim ((simple-array (unsigned-byte 31) (* *)) *table*))\n(sb-ext:define-load-time-global *power10*\n (make-mod-power-table 10 200001 cl-user::+mod+))\n(sb-ext:define-load-time-global *table*\n (make-array '(10 200001) :element-type '(unsigned-byte 31) :initial-element 0))\n\n(loop for d from 1 to 9\n do (loop for i from 1 to 200000\n do (setf (aref *table* d i)\n (mod+ d (mod* (aref *table* d (- i 1)) 10)))))\n\n(define-integer-pack node (x 31) (l 31))\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (declare (node a b))\n (with-unpacking-node (x1 l1) a\n (with-unpacking-node (x2 l2) b\n (pack-node (mod+ (mod* x1 (aref *power10* l2))\n x2)\n (mod+ l1 l2)))))\n\n(sb-int:defconstant-eqx +op-identity+ 0 #'equal\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 (if (zerop x)\n lazy\n x))\n\n(defconstant +updater-identity+ 0\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 (node acc))\n (if (zerop lazy)\n acc\n (let ((l (node-l acc)))\n (pack-node (aref *table* lazy l) l))))\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 (unsigned-byte 8))\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-element)\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 (or initial-element\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/integer-pack :cl-user))\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/mod-power-table :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/implicit-treap :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-operations :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.cl-user::opt)\n (let* ((n (read))\n (q (read))\n (itreap (make-itreap n :initial-element (pack-node 1 1))))\n (declare (uint31 n q))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ q)\n (let ((l (- (read-fixnum) 1))\n (r (read-fixnum))\n (d (read-fixnum)))\n (setq itreap (itreap-update itreap d l r))\n (println (node-x (itreap-accumulator itreap)))))))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(progn\n (defparameter *lisp-file-pathname* (uiop:current-lisp-file-pathname))\n (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *lisp-file-pathname*))\n (defparameter *problem-url* \"https://atcoder.jp/contests/abl/tasks/abl_e\"))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-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 (or (> sb-c::*compiler-warning-count* 0)\n sb-c::*undefined-warnings*)\n (error \"count: ~D, undefined warnings: ~A\"\n sb-c::*compiler-warning-count*\n sb-c::*undefined-warnings*)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(5am:test :sample\n (5am:is\n (equal \"11222211\n77772211\n77333333\n72333333\n72311333\n\"\n (run \"8 5\n3 6 2\n1 4 7\n3 8 3\n2 2 2\n4 5 1\n\" nil)))\n (5am:is\n (equal \"641437905\n\"\n (run \"200000 1\n123 456 7\n\" nil))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 43265, "cpu_time_ms": 537, "memory_kb": 51992}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s929493404", "group_id": "codeNet:p02539", "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 :cp/util) :silent t)\n #+swank (use-package :cp/util :cl-user)\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 (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 (define-int-types (&rest bits) `(progn ,@(mapcar (lambda (b) `(def ,b)) bits))))\n (define-int-types 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 998244353)\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;;; Arithmetic operations with static modulus\n;;;\n\n(defpackage :cp/mod-operations\n (:use :cl)\n (:export #:define-mod-operations))\n(in-package :cp/mod-operations)\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\n(defmacro define-mod-operations (divisor &optional (package (sb-int:sane-package)))\n (let ((mod* (intern \"MOD*\" package))\n (mod+ (intern \"MOD+\" package))\n (incfmod (intern \"INCFMOD\" package))\n (decfmod (intern \"DECFMOD\" package))\n (mulfmod (intern \"MULFMOD\" package)))\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 (sb-ext: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(define-mod-operations cl-user::+mod+ :cl-user)\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n(defpackage :cp/binomial-coefficient-mod\n (:use :cl)\n (:export #:binom #:perm #:multinomial #:stirling2 #:catalan #:+binom-mod+\n #:*fact* #:*fact-inv* #:*inv*))\n(in-package :cp/binomial-coefficient-mod)\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 510000)\n(defconstant +binom-mod+ (if (boundp 'cl-user::+mod+)\n (symbol-value 'cl-user::+mod+)\n #.(+ (expt 10 9) 7)))\n\n(sb-ext:define-load-time-global *fact*\n (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of factorials\")\n(sb-ext:define-load-time-global *fact-inv*\n (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of inverses of factorials\")\n(sb-ext:define-load-time-global *inv*\n (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of inverses of non-negative integers\")\n(declaim ((simple-array (unsigned-byte 31) (*)) *fact* *fact-inv* *inv*))\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 stirling2))\n(defun stirling2 (n k)\n \"Returns the stirling number of the second kind S2(n, k). Time complexity is\nO(klog(n)).\"\n (declare ((integer 0 #.most-positive-fixnum) n k))\n (labels ((mod-power (base exp)\n (declare ((integer 0 #.most-positive-fixnum) base exp))\n (loop with res of-type (integer 0 #.most-positive-fixnum) = 1\n while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) +binom-mod+))\n do (setq base (mod (* base base) +binom-mod+)\n exp (ash exp -1))\n finally (return res))))\n (loop with result of-type fixnum = 0\n for i from 0 to k\n for delta = (mod (* (binom k i) (mod-power i n)) +binom-mod+)\n when (evenp (- k i))\n do (incf result delta)\n (when (>= result +binom-mod+)\n (decf result +binom-mod+))\n else\n do (decf result delta)\n (when (< result 0)\n (incf result +binom-mod+))\n finally (return (mod (* result (aref *fact-inv* k)) +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;;;\n;;; Fast Number Theoretic Transform\n;;; Reference:\n;;; https://github.com/ei1333/library/blob/master/math/fft/number-theoretic-transform-friendly-mod-int.cpp\n;;; https://github.com/atcoder/ac-library/tree/master/atcoder\n;;;\n\n(defpackage :cp/ntt\n (:use :cl)\n (:export #:define-ntt #:check-ntt-vector #:ntt-int #:ntt-vector #:+ntt-mod+))\n(in-package :cp/ntt)\n\n(deftype ntt-int () '(unsigned-byte 31))\n(deftype ntt-vector () '(simple-array ntt-int (*)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (declaim (inline %tzcount))\n (defun %tzcount (x)\n \"Returns the number of trailing zero bits. Note that (%TZCOUNT 0) = -1.\"\n (- (integer-length (logand x (- x))) 1))\n (defun %mod-power (base exp modulus)\n (declare (ntt-int base exp modulus))\n (let ((res 1))\n (declare (ntt-int res))\n (loop while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) modulus))\n do (setq base (mod (* base base) modulus)\n exp (ash exp -1)))\n res))\n (defun %mod-inverse (x modulus)\n (%mod-power x (- modulus 2) modulus))\n (defun %calc-generator (modulus)\n \"MODULUS must be prime.\"\n (declare (ntt-int modulus))\n (assert (>= modulus 2))\n (case modulus\n (2 1)\n (167772161 3)\n (469762049 3)\n (754974721 11)\n (998244353 3)\n (otherwise\n (let ((divs (make-array 20 :element-type 'ntt-int :initial-element 0))\n (count 1)\n (x (floor (- modulus 1) 2)))\n (declare ((integer 0 #.most-positive-fixnum) x))\n (setf (aref divs 0) 2)\n (loop while (evenp x)\n do (setq x (floor x 2)))\n (loop for i of-type ntt-int from 3 by 2\n while (<= (* i i) x)\n when (zerop (mod x i))\n do (setf (aref divs count) i)\n (incf count)\n (loop while (zerop (mod x i))\n do (setq x (floor x i))))\n (when (> x 1)\n (setf (aref divs count) x)\n (incf count))\n (loop for g of-type ntt-int from 2\n for ok = t\n do (dotimes (i count)\n (when (= 1 (%mod-power g (floor (- modulus 1) (aref divs i)) modulus))\n (setq ok nil)\n (return)))\n when ok\n do (return g)))))))\n\n;; KLUDGE: This function depends on SBCL's behaviour. Actually ADJUST-ARRAY\n;; isn't guaranteed to preserve the given VECTOR.\n(declaim (ftype (function * (values ntt-vector &optional)) %adjust-array))\n(defun %adjust-array (vector length)\n (declare (vector vector))\n (let ((vector (coerce vector 'ntt-vector)))\n (if (= (length vector) length)\n (copy-seq vector)\n (adjust-array vector length :initial-element 0))))\n\n(defun check-ntt-vector (vector)\n (declare (optimize (speed 3))\n (vector vector))\n (let ((len (length vector)))\n (assert (zerop (logand len (- len 1)))) ;; power of two\n (check-type len ntt-int)))\n\n(defmacro define-ntt (modulus &key ntt inverse-ntt convolve mod-inverse mod-power)\n (let* ((ntt (or ntt (intern \"NTT!\")))\n (inverse-ntt (or inverse-ntt (intern \"INVERSE-NTT!\")))\n (convolve (or convolve (intern \"CONVOLVE\")))\n (mod-power (or mod-power (gensym \"MOD-POWER\")))\n (mod-inverse (or mod-inverse (gensym \"MOD-INVERSE\")))\n (ntt-base (gensym \"*NTT-BASE*\"))\n (ntt-inv-base (gensym \"*NTT-INV-BASE*\"))\n (base-size (%tzcount (- modulus 1)))\n (root (%calc-generator modulus)))\n (assert (typep modulus 'ntt-int))\n `(progn\n (declaim (inline ,mod-power))\n (defun ,mod-power (base exp)\n (declare (ntt-int base)\n ((integer 0 #.most-positive-fixnum) exp))\n (let ((res 1))\n (declare (ntt-int res))\n (loop while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) ,modulus))\n do (setq base (mod (* base base) ,modulus)\n exp (ash exp -1)))\n res))\n (declaim (inline ,mod-inverse))\n (defun ,mod-inverse (x)\n (,mod-power x (- ,modulus 2)))\n (declaim (ntt-vector ,ntt-base ,ntt-inv-base))\n (sb-ext:define-load-time-global ,ntt-base\n (make-array ,base-size :element-type 'ntt-int))\n (sb-ext:define-load-time-global ,ntt-inv-base\n (make-array ,base-size :element-type 'ntt-int))\n (dotimes (i ,base-size)\n (setf (aref ,ntt-base i)\n (mod (- (%mod-power ,root (ash (- ,modulus 1) (- (+ i 2))) ,modulus))\n ,modulus)\n (aref ,ntt-inv-base i)\n (%mod-inverse (aref ,ntt-base i) ,modulus)))\n\n (declaim (ftype (function * (values ntt-vector &optional)) ,ntt))\n (defun ,ntt (vector)\n (declare (optimize (speed 3) (safety 0))\n (vector vector))\n (check-ntt-vector vector)\n (labels ((mod* (x y) (mod (* x y) ,modulus))\n (mod+ (x y)\n (let ((res (+ x y)))\n (if (>= res ,modulus)\n (- res ,modulus)\n res)))\n (mod- (x y) (mod+ x (- ,modulus y))))\n (declare (inline mod* mod+ mod-))\n (let* ((vector (coerce vector 'ntt-vector))\n (len (length vector))\n (base ,ntt-base))\n (declare (ntt-vector vector base)\n (ntt-int len))\n (when (<= len 1)\n (return-from ,ntt vector))\n (loop for m of-type ntt-int = (ash len -1) then (ash m -1)\n while (> m 0)\n for w of-type ntt-int = 1\n for k of-type ntt-int = 0\n do (loop for s of-type ntt-int from 0 below len by (* 2 m)\n do (loop for i from s below (+ s m)\n for j from (+ s m)\n for x = (aref vector i)\n for y = (mod* (aref vector j) w)\n do (setf (aref vector i) (mod+ x y)\n (aref vector j) (mod- x y)))\n (incf k)\n (setq w (mod* w (aref base (%tzcount k))))))\n vector)))\n\n (declaim (ftype (function * (values ntt-vector &optional)) ,inverse-ntt))\n (defun ,inverse-ntt (vector &optional inverse)\n (declare (optimize (speed 3) (safety 0))\n (vector vector))\n (check-ntt-vector vector)\n (labels ((mod* (x y)\n (declare (ntt-int x y))\n (mod (* x y) ,modulus))\n (mod+ (x y)\n (declare (ntt-int x y))\n (let ((res (+ x y)))\n (if (>= res ,modulus)\n (- res ,modulus)\n res)))\n (mod- (x y)\n (declare (ntt-int x y))\n (mod+ x (- ,modulus y))))\n (declare (inline mod* mod+ mod-))\n (let* ((vector (coerce vector 'ntt-vector))\n (len (length vector))\n (base ,ntt-inv-base))\n (declare (ntt-vector vector base)\n (ntt-int len))\n (when (<= len 1)\n (return-from ,inverse-ntt vector))\n (loop for m of-type ntt-int = 1 then (ash m 1)\n while (< m len)\n for w of-type ntt-int = 1\n for k of-type ntt-int = 0\n do (loop for s of-type ntt-int from 0 below len by (* 2 m)\n do (loop for i from s below (+ s m)\n for j from (+ s m)\n for x = (aref vector i)\n for y = (aref vector j)\n do (setf (aref vector i) (mod+ x y)\n (aref vector j) (mod* (mod- x y) w)))\n (incf k)\n (setq w (mod* w (aref base (%tzcount k))))))\n (when inverse\n (let ((inv-len (,mod-power len (- ,modulus 2))))\n (dotimes (i len)\n (setf (aref vector i) (mod* inv-len (aref vector i))))))\n vector)))\n\n (declaim (ftype (function * (values ntt-vector &optional)) ,convolve))\n (defun ,convolve (vector1 vector2)\n (declare (optimize (speed 3))\n (vector vector1 vector2))\n (let ((len1 (length vector1))\n (len2 (length vector2)))\n (when (or (zerop len1) (zerop len2))\n (return-from ,convolve (make-array 0 :element-type 'ntt-int)))\n (let* ((mul-len (max 0 (- (+ len1 len2) 1)))\n ;; power of two ceiling\n (required-len (ash 1 (integer-length (max 0 (- mul-len 1)))))\n (vector1 (,ntt (%adjust-array vector1 required-len)))\n (vector2 (,ntt (%adjust-array vector2 required-len))))\n (declare ((mod #.array-total-size-limit) mul-len))\n (dotimes (i required-len)\n (setf (aref vector1 i)\n (mod (* (aref vector1 i) (aref vector2 i)) ,modulus)))\n (adjust-array (,inverse-ntt vector1 t) mul-len)))))))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defconstant +ntt-mod+ 998244353))\n\n#+(or)\n(define-ntt #.+ntt-mod+)\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(defpackage :cp/polynomial-ntt\n (:use :cl :cp/ntt)\n (:export #:poly-multiply #:poly-inverse #:poly-floor #:poly-mod #:poly-sub #:poly-add\n #:multipoint-eval #:poly-total-prod))\n(in-package :cp/polynomial-ntt)\n\n(define-ntt #.+ntt-mod+\n :convolve poly-multiply\n :mod-inverse %mod-inverse)\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-inverse))\n(defun poly-inverse (poly &optional result-length)\n (declare (optimize (speed 3))\n (vector poly)\n ((or null fixnum) result-length))\n (let* ((poly (coerce poly 'ntt-vector))\n (n (length poly)))\n (declare (ntt-vector poly))\n (when (or (zerop n)\n (zerop (aref poly 0)))\n (error 'division-by-zero\n :operation #'poly-inverse\n :operands poly))\n (let ((res (make-array 1\n :element-type 'ntt-int\n :initial-element (%mod-inverse (aref poly 0))))\n (result-length (or result-length n)))\n (declare (ntt-vector res))\n (loop for i of-type ntt-int = 1 then (ash i 1)\n while (< i result-length)\n for decr = (poly-multiply (poly-multiply res res)\n (subseq poly 0 (min (length poly) (* 2 i))))\n for decr-len = (length decr)\n do (setq res (adjust-array res (* 2 i) :initial-element 0))\n (dotimes (j (* 2 i))\n (setf (aref res j)\n (mod (the ntt-int\n (+ (mod (* 2 (aref res j)) +ntt-mod+)\n (if (>= j decr-len) 0 (- +ntt-mod+ (aref decr j)))))\n +ntt-mod+))))\n (adjust-array res result-length))))\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-floor))\n(defun poly-floor (poly1 poly2)\n (declare (optimize (speed 3))\n (vector poly1 poly2))\n (let* ((poly1 (coerce poly1 'ntt-vector))\n (poly2 (coerce poly2 'ntt-vector))\n (deg1 (+ 1 (or (position 0 poly1 :from-end t :test-not #'eql) -1)))\n (deg2 (+ 1 (or (position 0 poly2 :from-end t :test-not #'eql) -1))))\n (when (> deg2 deg1)\n (return-from poly-floor (make-array 0 :element-type 'ntt-int)))\n (setq poly1 (nreverse (subseq poly1 0 deg1))\n poly2 (nreverse (subseq poly2 0 deg2)))\n (let* ((res-len (+ 1 (- deg1 deg2)))\n (res (adjust-array (poly-multiply poly1 (poly-inverse poly2 res-len))\n res-len)))\n (nreverse res))))\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-sub))\n(defun poly-sub (poly1 poly2)\n (declare (optimize (speed 3))\n (vector poly1 poly2))\n (let* ((poly1 (coerce poly1 'ntt-vector))\n (poly2 (coerce poly2 'ntt-vector))\n (len (max (length poly1) (length poly2)))\n (res (make-array len :element-type 'ntt-int :initial-element 0)))\n (replace res poly1)\n (dotimes (i (length poly2))\n (let ((value (+ (aref res i)\n (the ntt-int (- +ntt-mod+ (aref poly2 i))))))\n (setf (aref res i)\n (if (>= value +ntt-mod+)\n (- value +ntt-mod+)\n value))))\n res))\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-add))\n(defun poly-add (poly1 poly2)\n (declare (optimize (speed 3))\n (vector poly1 poly2))\n (let* ((poly1 (coerce poly1 'ntt-vector))\n (poly2 (coerce poly2 'ntt-vector))\n (len (max (length poly1) (length poly2)))\n (res (make-array len :element-type 'ntt-int :initial-element 0)))\n (replace res poly1)\n (dotimes (i (length poly2))\n (let ((value (+ (aref res i) (aref poly2 i))))\n (setf (aref res i)\n (if (>= value +ntt-mod+)\n (- value +ntt-mod+)\n value))))\n res))\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-mod))\n(defun poly-mod (poly1 poly2)\n (declare (optimize (speed 3))\n (vector poly1 poly2))\n (let ((poly1 (coerce poly1 'ntt-vector))\n (poly2 (coerce poly2 'ntt-vector)))\n (when (loop for x across poly1 always (zerop x))\n (return-from poly-mod (make-array 0 :element-type 'ntt-int)))\n (let* ((res (poly-sub poly1 (poly-multiply (poly-floor poly1 poly2) poly2)))\n (end (+ 1 (or (position 0 res :from-end t :test-not #'eql) -1))))\n (subseq res 0 end))))\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-total-prod))\n(defun poly-total-prod (polys)\n \"Returns the total polynomial product: polys[0] * polys[1] * ... * polys[n-1].\"\n (declare (vector polys))\n (let* ((n (length polys))\n (dp (make-array n :element-type t)))\n (declare ((mod #.array-total-size-limit) n))\n (when (zerop n)\n (return-from poly-total-prod (make-array 1 :element-type 'ntt-int :initial-element 1)))\n (replace dp polys)\n (loop for width of-type (mod #.array-total-size-limit) = 1 then (ash width 1)\n while (< width n)\n do (loop for i of-type (mod #.array-total-size-limit) from 0 by (* width 2)\n while (< (+ i width) n)\n do (setf (aref dp i)\n (poly-multiply (aref dp i) (aref dp (+ i width))))))\n (coerce (aref dp 0) 'ntt-vector)))\n\n(declaim (ftype (function * (values ntt-vector &optional)) multipoint-eval))\n(defun multipoint-eval (poly points)\n (declare (optimize (speed 3))\n (vector poly points)\n #+sbcl (sb-ext:muffle-conditions style-warning))\n (check-ntt-vector points)\n (let* ((poly (coerce poly 'ntt-vector))\n (points (coerce points 'ntt-vector))\n (len (length points))\n (table (make-array (max 0 (- (* 2 len) 1)) :element-type 'ntt-vector))\n (res (make-array len :element-type 'ntt-int)))\n (unless (zerop len)\n (sb-int:named-let %build ((l 0) (r len) (pos 0))\n (declare ((integer 0 #.most-positive-fixnum) l r pos))\n (if (= (- r l) 1)\n (let ((lin (make-array 2 :element-type 'ntt-int)))\n (setf (aref lin 0) (- +ntt-mod+ (aref points l)) ;; NOTE: non-zero\n (aref lin 1) 1)\n (setf (aref table pos) lin))\n (let ((mid (ash (+ l r) -1)))\n (%build l mid (+ 1 (* pos 2)))\n (%build mid r (+ 2 (* pos 2)))\n (setf (aref table pos)\n (poly-multiply (aref table (+ 1 (* pos 2)))\n (aref table (+ 2 (* pos 2))))))))\n (sb-int:named-let %eval ((poly poly) (l 0) (r len) (pos 0))\n (declare ((integer 0 #.most-positive-fixnum) l r pos))\n (if (= (- r l) 1)\n (let ((tmp (poly-mod poly (aref table pos))))\n (setf (aref res l) (if (zerop (length tmp)) 0 (aref tmp 0))))\n (let ((mid (ash (+ l r) -1)))\n (%eval (poly-mod poly (aref table (+ (* 2 pos) 1))) l mid (+ (* 2 pos) 1))\n (%eval (poly-mod poly (aref table (+ (* 2 pos) 2))) mid r (+ (* 2 pos) 2))))))\n res))\n\n(defpackage :cp/mod-inverse\n (:use :cl)\n (:export #:mod-inverse))\n(in-package :cp/mod-inverse)\n\n;; TODO: signal DIVISION-BY-ZERO for non-coprime input when safety >= 1\n(declaim (inline mod-inverse)\n (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 ((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 (mod u modulus)))\n\n(defpackage :cp/mod-power-table\n (:use :cl)\n (:export #:make-mod-power-table))\n(in-package :cp/mod-power-table)\n\n(declaim (inline make-mod-power-table))\n(defun make-mod-power-table (base length modulus &optional (element-type '(unsigned-byte 31)))\n \"Returns a vector of the given length: VECTOR[x] := BASE^x mod MODULUS.\"\n (declare (fixnum base)\n ((integer 0 #.most-positive-fixnum) length)\n ((integer 1 #.most-positive-fixnum) modulus))\n (let ((res (make-array length :element-type element-type)))\n (unless (zerop length)\n (setf (aref res 0) 1)\n (loop for i from 1 below length\n do (setf (aref res i)\n (mod (* base (aref res (- i 1))) modulus))))\n res))\n\n;;;\n;;; Binary heap\n;;;\n\n(defpackage :cp/abstract-heap\n (:use :cl)\n (:export #:heap-empty-error #:define-binary-heap))\n(in-package :cp/abstract-heap)\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, -CLEAR, -EMPTY-P,\n-COUNT, and -PEEK.\n\nIf ORDER is not given, heap for dynamic order is defined instead: -PUSH and -POP\nfunctions take order as an argument.\"\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-clear (intern (format nil \"~A-CLEAR\" 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 (order (or order 'order)))\n `(progn\n (locally\n ;; prevent style warnings\n (declare #+sbcl (sb-ext: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 ,@(when (eql order 'order) '(order)))\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 ,@(when (eql order 'order) '(order)))\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-clear))\n (defun ,fname-clear (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. Signals HEAP-EMPTY-ERROR if HEAP\nis empty.\"\n (if (= 1 (,acc-position heap))\n (error 'heap-empty-error :heap heap)\n (aref (,acc-data heap) 1))))))\n\n#+(or)\n(define-binary-heap heap\n :order #'>\n :element-type fixnum)\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/abstract-heap :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-power-table :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-inverse :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/polynomial-ntt :cl-user))\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/ntt :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/binomial-coefficient-mod :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-operations :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(define-binary-heap heap\n :order (lambda (poly1 poly2)\n (< (length poly1) (length poly2)))\n :element-type ntt-vector)\n\n(defun main ()\n (let* ((n (read))\n (hcounter (make-array 100000 :element-type 'uint31 :initial-element 0))\n (powers (make-mod-power-table 499122177 100001 +mod+))\n (fs (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i (* 2 n))\n (incf (aref hcounter (- (read-fixnum) 1))))\n (dotimes (i (+ n 1))\n (setf (aref fs i) (mod* (aref *fact* (* 2 i))\n (aref powers i)\n (aref *fact-inv* i))))\n (let* ((hcounter (delete 0 hcounter))\n (que (make-heap n)))\n (dotimes (j (length hcounter))\n (let* ((k (aref hcounter j))\n (poly (make-array (+ 1 (floor k 2)) :element-type 'uint31)))\n (loop for i from 0 below (length poly)\n do (setf (aref poly i)\n (mod* (binom k (* 2 i)) (aref fs i))))\n (dbg k poly)\n (heap-push poly que)))\n (loop while (>= (heap-count que) 2)\n for poly1 = (heap-pop que)\n for poly2 = (heap-pop que)\n do (heap-push (poly-multiply poly1 poly2) que))\n (let ((poly (heap-pop que))\n (res 0))\n #>poly\n (loop for i from 0 below (length poly)\n for sign = 1 then (* sign -1)\n ;; while (<= (* 2 i) n)\n do (incfmod res (mod* (aref poly i) (aref fs (- n i)) sign)))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(progn\n (defparameter *lisp-file-pathname* (uiop:current-lisp-file-pathname))\n (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *lisp-file-pathname*))\n (defparameter *problem-url* \"https://atcoder.jp/contests/abl/tasks/abl_f\"))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-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 (or (> sb-c::*compiler-warning-count* 0)\n sb-c::*undefined-warnings*)\n (error \"count: ~D, undefined warnings: ~A\"\n sb-c::*compiler-warning-count*\n sb-c::*undefined-warnings*)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(5am:test :sample\n (5am:is\n (equal \"2\n\"\n (run \"2\n1\n1\n2\n3\n\" nil)))\n (5am:is\n (equal \"516\n\"\n (run \"5\n30\n10\n20\n40\n20\n10\n10\n30\n50\n60\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1601188406, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02539.html", "problem_id": "p02539", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02539/input.txt", "sample_output_relpath": "derived/input_output/data/p02539/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02539/Lisp/s929493404.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s929493404", "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 :cp/util) :silent t)\n #+swank (use-package :cp/util :cl-user)\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 (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 (define-int-types (&rest bits) `(progn ,@(mapcar (lambda (b) `(def ,b)) bits))))\n (define-int-types 2 4 7 8 15 16 31 32 62 63 64))\n\n(defconstant +mod+ 998244353)\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;;; Arithmetic operations with static modulus\n;;;\n\n(defpackage :cp/mod-operations\n (:use :cl)\n (:export #:define-mod-operations))\n(in-package :cp/mod-operations)\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\n(defmacro define-mod-operations (divisor &optional (package (sb-int:sane-package)))\n (let ((mod* (intern \"MOD*\" package))\n (mod+ (intern \"MOD+\" package))\n (incfmod (intern \"INCFMOD\" package))\n (decfmod (intern \"DECFMOD\" package))\n (mulfmod (intern \"MULFMOD\" package)))\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 (sb-ext: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(define-mod-operations cl-user::+mod+ :cl-user)\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n(defpackage :cp/binomial-coefficient-mod\n (:use :cl)\n (:export #:binom #:perm #:multinomial #:stirling2 #:catalan #:+binom-mod+\n #:*fact* #:*fact-inv* #:*inv*))\n(in-package :cp/binomial-coefficient-mod)\n\n;; TODO: non-global handling\n\n(defconstant +binom-size+ 510000)\n(defconstant +binom-mod+ (if (boundp 'cl-user::+mod+)\n (symbol-value 'cl-user::+mod+)\n #.(+ (expt 10 9) 7)))\n\n(sb-ext:define-load-time-global *fact*\n (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of factorials\")\n(sb-ext:define-load-time-global *fact-inv*\n (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of inverses of factorials\")\n(sb-ext:define-load-time-global *inv*\n (make-array +binom-size+ :element-type '(unsigned-byte 31))\n \"table of inverses of non-negative integers\")\n(declaim ((simple-array (unsigned-byte 31) (*)) *fact* *fact-inv* *inv*))\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 stirling2))\n(defun stirling2 (n k)\n \"Returns the stirling number of the second kind S2(n, k). Time complexity is\nO(klog(n)).\"\n (declare ((integer 0 #.most-positive-fixnum) n k))\n (labels ((mod-power (base exp)\n (declare ((integer 0 #.most-positive-fixnum) base exp))\n (loop with res of-type (integer 0 #.most-positive-fixnum) = 1\n while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) +binom-mod+))\n do (setq base (mod (* base base) +binom-mod+)\n exp (ash exp -1))\n finally (return res))))\n (loop with result of-type fixnum = 0\n for i from 0 to k\n for delta = (mod (* (binom k i) (mod-power i n)) +binom-mod+)\n when (evenp (- k i))\n do (incf result delta)\n (when (>= result +binom-mod+)\n (decf result +binom-mod+))\n else\n do (decf result delta)\n (when (< result 0)\n (incf result +binom-mod+))\n finally (return (mod (* result (aref *fact-inv* k)) +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;;;\n;;; Fast Number Theoretic Transform\n;;; Reference:\n;;; https://github.com/ei1333/library/blob/master/math/fft/number-theoretic-transform-friendly-mod-int.cpp\n;;; https://github.com/atcoder/ac-library/tree/master/atcoder\n;;;\n\n(defpackage :cp/ntt\n (:use :cl)\n (:export #:define-ntt #:check-ntt-vector #:ntt-int #:ntt-vector #:+ntt-mod+))\n(in-package :cp/ntt)\n\n(deftype ntt-int () '(unsigned-byte 31))\n(deftype ntt-vector () '(simple-array ntt-int (*)))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (declaim (inline %tzcount))\n (defun %tzcount (x)\n \"Returns the number of trailing zero bits. Note that (%TZCOUNT 0) = -1.\"\n (- (integer-length (logand x (- x))) 1))\n (defun %mod-power (base exp modulus)\n (declare (ntt-int base exp modulus))\n (let ((res 1))\n (declare (ntt-int res))\n (loop while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) modulus))\n do (setq base (mod (* base base) modulus)\n exp (ash exp -1)))\n res))\n (defun %mod-inverse (x modulus)\n (%mod-power x (- modulus 2) modulus))\n (defun %calc-generator (modulus)\n \"MODULUS must be prime.\"\n (declare (ntt-int modulus))\n (assert (>= modulus 2))\n (case modulus\n (2 1)\n (167772161 3)\n (469762049 3)\n (754974721 11)\n (998244353 3)\n (otherwise\n (let ((divs (make-array 20 :element-type 'ntt-int :initial-element 0))\n (count 1)\n (x (floor (- modulus 1) 2)))\n (declare ((integer 0 #.most-positive-fixnum) x))\n (setf (aref divs 0) 2)\n (loop while (evenp x)\n do (setq x (floor x 2)))\n (loop for i of-type ntt-int from 3 by 2\n while (<= (* i i) x)\n when (zerop (mod x i))\n do (setf (aref divs count) i)\n (incf count)\n (loop while (zerop (mod x i))\n do (setq x (floor x i))))\n (when (> x 1)\n (setf (aref divs count) x)\n (incf count))\n (loop for g of-type ntt-int from 2\n for ok = t\n do (dotimes (i count)\n (when (= 1 (%mod-power g (floor (- modulus 1) (aref divs i)) modulus))\n (setq ok nil)\n (return)))\n when ok\n do (return g)))))))\n\n;; KLUDGE: This function depends on SBCL's behaviour. Actually ADJUST-ARRAY\n;; isn't guaranteed to preserve the given VECTOR.\n(declaim (ftype (function * (values ntt-vector &optional)) %adjust-array))\n(defun %adjust-array (vector length)\n (declare (vector vector))\n (let ((vector (coerce vector 'ntt-vector)))\n (if (= (length vector) length)\n (copy-seq vector)\n (adjust-array vector length :initial-element 0))))\n\n(defun check-ntt-vector (vector)\n (declare (optimize (speed 3))\n (vector vector))\n (let ((len (length vector)))\n (assert (zerop (logand len (- len 1)))) ;; power of two\n (check-type len ntt-int)))\n\n(defmacro define-ntt (modulus &key ntt inverse-ntt convolve mod-inverse mod-power)\n (let* ((ntt (or ntt (intern \"NTT!\")))\n (inverse-ntt (or inverse-ntt (intern \"INVERSE-NTT!\")))\n (convolve (or convolve (intern \"CONVOLVE\")))\n (mod-power (or mod-power (gensym \"MOD-POWER\")))\n (mod-inverse (or mod-inverse (gensym \"MOD-INVERSE\")))\n (ntt-base (gensym \"*NTT-BASE*\"))\n (ntt-inv-base (gensym \"*NTT-INV-BASE*\"))\n (base-size (%tzcount (- modulus 1)))\n (root (%calc-generator modulus)))\n (assert (typep modulus 'ntt-int))\n `(progn\n (declaim (inline ,mod-power))\n (defun ,mod-power (base exp)\n (declare (ntt-int base)\n ((integer 0 #.most-positive-fixnum) exp))\n (let ((res 1))\n (declare (ntt-int res))\n (loop while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) ,modulus))\n do (setq base (mod (* base base) ,modulus)\n exp (ash exp -1)))\n res))\n (declaim (inline ,mod-inverse))\n (defun ,mod-inverse (x)\n (,mod-power x (- ,modulus 2)))\n (declaim (ntt-vector ,ntt-base ,ntt-inv-base))\n (sb-ext:define-load-time-global ,ntt-base\n (make-array ,base-size :element-type 'ntt-int))\n (sb-ext:define-load-time-global ,ntt-inv-base\n (make-array ,base-size :element-type 'ntt-int))\n (dotimes (i ,base-size)\n (setf (aref ,ntt-base i)\n (mod (- (%mod-power ,root (ash (- ,modulus 1) (- (+ i 2))) ,modulus))\n ,modulus)\n (aref ,ntt-inv-base i)\n (%mod-inverse (aref ,ntt-base i) ,modulus)))\n\n (declaim (ftype (function * (values ntt-vector &optional)) ,ntt))\n (defun ,ntt (vector)\n (declare (optimize (speed 3) (safety 0))\n (vector vector))\n (check-ntt-vector vector)\n (labels ((mod* (x y) (mod (* x y) ,modulus))\n (mod+ (x y)\n (let ((res (+ x y)))\n (if (>= res ,modulus)\n (- res ,modulus)\n res)))\n (mod- (x y) (mod+ x (- ,modulus y))))\n (declare (inline mod* mod+ mod-))\n (let* ((vector (coerce vector 'ntt-vector))\n (len (length vector))\n (base ,ntt-base))\n (declare (ntt-vector vector base)\n (ntt-int len))\n (when (<= len 1)\n (return-from ,ntt vector))\n (loop for m of-type ntt-int = (ash len -1) then (ash m -1)\n while (> m 0)\n for w of-type ntt-int = 1\n for k of-type ntt-int = 0\n do (loop for s of-type ntt-int from 0 below len by (* 2 m)\n do (loop for i from s below (+ s m)\n for j from (+ s m)\n for x = (aref vector i)\n for y = (mod* (aref vector j) w)\n do (setf (aref vector i) (mod+ x y)\n (aref vector j) (mod- x y)))\n (incf k)\n (setq w (mod* w (aref base (%tzcount k))))))\n vector)))\n\n (declaim (ftype (function * (values ntt-vector &optional)) ,inverse-ntt))\n (defun ,inverse-ntt (vector &optional inverse)\n (declare (optimize (speed 3) (safety 0))\n (vector vector))\n (check-ntt-vector vector)\n (labels ((mod* (x y)\n (declare (ntt-int x y))\n (mod (* x y) ,modulus))\n (mod+ (x y)\n (declare (ntt-int x y))\n (let ((res (+ x y)))\n (if (>= res ,modulus)\n (- res ,modulus)\n res)))\n (mod- (x y)\n (declare (ntt-int x y))\n (mod+ x (- ,modulus y))))\n (declare (inline mod* mod+ mod-))\n (let* ((vector (coerce vector 'ntt-vector))\n (len (length vector))\n (base ,ntt-inv-base))\n (declare (ntt-vector vector base)\n (ntt-int len))\n (when (<= len 1)\n (return-from ,inverse-ntt vector))\n (loop for m of-type ntt-int = 1 then (ash m 1)\n while (< m len)\n for w of-type ntt-int = 1\n for k of-type ntt-int = 0\n do (loop for s of-type ntt-int from 0 below len by (* 2 m)\n do (loop for i from s below (+ s m)\n for j from (+ s m)\n for x = (aref vector i)\n for y = (aref vector j)\n do (setf (aref vector i) (mod+ x y)\n (aref vector j) (mod* (mod- x y) w)))\n (incf k)\n (setq w (mod* w (aref base (%tzcount k))))))\n (when inverse\n (let ((inv-len (,mod-power len (- ,modulus 2))))\n (dotimes (i len)\n (setf (aref vector i) (mod* inv-len (aref vector i))))))\n vector)))\n\n (declaim (ftype (function * (values ntt-vector &optional)) ,convolve))\n (defun ,convolve (vector1 vector2)\n (declare (optimize (speed 3))\n (vector vector1 vector2))\n (let ((len1 (length vector1))\n (len2 (length vector2)))\n (when (or (zerop len1) (zerop len2))\n (return-from ,convolve (make-array 0 :element-type 'ntt-int)))\n (let* ((mul-len (max 0 (- (+ len1 len2) 1)))\n ;; power of two ceiling\n (required-len (ash 1 (integer-length (max 0 (- mul-len 1)))))\n (vector1 (,ntt (%adjust-array vector1 required-len)))\n (vector2 (,ntt (%adjust-array vector2 required-len))))\n (declare ((mod #.array-total-size-limit) mul-len))\n (dotimes (i required-len)\n (setf (aref vector1 i)\n (mod (* (aref vector1 i) (aref vector2 i)) ,modulus)))\n (adjust-array (,inverse-ntt vector1 t) mul-len)))))))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (defconstant +ntt-mod+ 998244353))\n\n#+(or)\n(define-ntt #.+ntt-mod+)\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(defpackage :cp/polynomial-ntt\n (:use :cl :cp/ntt)\n (:export #:poly-multiply #:poly-inverse #:poly-floor #:poly-mod #:poly-sub #:poly-add\n #:multipoint-eval #:poly-total-prod))\n(in-package :cp/polynomial-ntt)\n\n(define-ntt #.+ntt-mod+\n :convolve poly-multiply\n :mod-inverse %mod-inverse)\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-inverse))\n(defun poly-inverse (poly &optional result-length)\n (declare (optimize (speed 3))\n (vector poly)\n ((or null fixnum) result-length))\n (let* ((poly (coerce poly 'ntt-vector))\n (n (length poly)))\n (declare (ntt-vector poly))\n (when (or (zerop n)\n (zerop (aref poly 0)))\n (error 'division-by-zero\n :operation #'poly-inverse\n :operands poly))\n (let ((res (make-array 1\n :element-type 'ntt-int\n :initial-element (%mod-inverse (aref poly 0))))\n (result-length (or result-length n)))\n (declare (ntt-vector res))\n (loop for i of-type ntt-int = 1 then (ash i 1)\n while (< i result-length)\n for decr = (poly-multiply (poly-multiply res res)\n (subseq poly 0 (min (length poly) (* 2 i))))\n for decr-len = (length decr)\n do (setq res (adjust-array res (* 2 i) :initial-element 0))\n (dotimes (j (* 2 i))\n (setf (aref res j)\n (mod (the ntt-int\n (+ (mod (* 2 (aref res j)) +ntt-mod+)\n (if (>= j decr-len) 0 (- +ntt-mod+ (aref decr j)))))\n +ntt-mod+))))\n (adjust-array res result-length))))\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-floor))\n(defun poly-floor (poly1 poly2)\n (declare (optimize (speed 3))\n (vector poly1 poly2))\n (let* ((poly1 (coerce poly1 'ntt-vector))\n (poly2 (coerce poly2 'ntt-vector))\n (deg1 (+ 1 (or (position 0 poly1 :from-end t :test-not #'eql) -1)))\n (deg2 (+ 1 (or (position 0 poly2 :from-end t :test-not #'eql) -1))))\n (when (> deg2 deg1)\n (return-from poly-floor (make-array 0 :element-type 'ntt-int)))\n (setq poly1 (nreverse (subseq poly1 0 deg1))\n poly2 (nreverse (subseq poly2 0 deg2)))\n (let* ((res-len (+ 1 (- deg1 deg2)))\n (res (adjust-array (poly-multiply poly1 (poly-inverse poly2 res-len))\n res-len)))\n (nreverse res))))\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-sub))\n(defun poly-sub (poly1 poly2)\n (declare (optimize (speed 3))\n (vector poly1 poly2))\n (let* ((poly1 (coerce poly1 'ntt-vector))\n (poly2 (coerce poly2 'ntt-vector))\n (len (max (length poly1) (length poly2)))\n (res (make-array len :element-type 'ntt-int :initial-element 0)))\n (replace res poly1)\n (dotimes (i (length poly2))\n (let ((value (+ (aref res i)\n (the ntt-int (- +ntt-mod+ (aref poly2 i))))))\n (setf (aref res i)\n (if (>= value +ntt-mod+)\n (- value +ntt-mod+)\n value))))\n res))\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-add))\n(defun poly-add (poly1 poly2)\n (declare (optimize (speed 3))\n (vector poly1 poly2))\n (let* ((poly1 (coerce poly1 'ntt-vector))\n (poly2 (coerce poly2 'ntt-vector))\n (len (max (length poly1) (length poly2)))\n (res (make-array len :element-type 'ntt-int :initial-element 0)))\n (replace res poly1)\n (dotimes (i (length poly2))\n (let ((value (+ (aref res i) (aref poly2 i))))\n (setf (aref res i)\n (if (>= value +ntt-mod+)\n (- value +ntt-mod+)\n value))))\n res))\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-mod))\n(defun poly-mod (poly1 poly2)\n (declare (optimize (speed 3))\n (vector poly1 poly2))\n (let ((poly1 (coerce poly1 'ntt-vector))\n (poly2 (coerce poly2 'ntt-vector)))\n (when (loop for x across poly1 always (zerop x))\n (return-from poly-mod (make-array 0 :element-type 'ntt-int)))\n (let* ((res (poly-sub poly1 (poly-multiply (poly-floor poly1 poly2) poly2)))\n (end (+ 1 (or (position 0 res :from-end t :test-not #'eql) -1))))\n (subseq res 0 end))))\n\n(declaim (ftype (function * (values ntt-vector &optional)) poly-total-prod))\n(defun poly-total-prod (polys)\n \"Returns the total polynomial product: polys[0] * polys[1] * ... * polys[n-1].\"\n (declare (vector polys))\n (let* ((n (length polys))\n (dp (make-array n :element-type t)))\n (declare ((mod #.array-total-size-limit) n))\n (when (zerop n)\n (return-from poly-total-prod (make-array 1 :element-type 'ntt-int :initial-element 1)))\n (replace dp polys)\n (loop for width of-type (mod #.array-total-size-limit) = 1 then (ash width 1)\n while (< width n)\n do (loop for i of-type (mod #.array-total-size-limit) from 0 by (* width 2)\n while (< (+ i width) n)\n do (setf (aref dp i)\n (poly-multiply (aref dp i) (aref dp (+ i width))))))\n (coerce (aref dp 0) 'ntt-vector)))\n\n(declaim (ftype (function * (values ntt-vector &optional)) multipoint-eval))\n(defun multipoint-eval (poly points)\n (declare (optimize (speed 3))\n (vector poly points)\n #+sbcl (sb-ext:muffle-conditions style-warning))\n (check-ntt-vector points)\n (let* ((poly (coerce poly 'ntt-vector))\n (points (coerce points 'ntt-vector))\n (len (length points))\n (table (make-array (max 0 (- (* 2 len) 1)) :element-type 'ntt-vector))\n (res (make-array len :element-type 'ntt-int)))\n (unless (zerop len)\n (sb-int:named-let %build ((l 0) (r len) (pos 0))\n (declare ((integer 0 #.most-positive-fixnum) l r pos))\n (if (= (- r l) 1)\n (let ((lin (make-array 2 :element-type 'ntt-int)))\n (setf (aref lin 0) (- +ntt-mod+ (aref points l)) ;; NOTE: non-zero\n (aref lin 1) 1)\n (setf (aref table pos) lin))\n (let ((mid (ash (+ l r) -1)))\n (%build l mid (+ 1 (* pos 2)))\n (%build mid r (+ 2 (* pos 2)))\n (setf (aref table pos)\n (poly-multiply (aref table (+ 1 (* pos 2)))\n (aref table (+ 2 (* pos 2))))))))\n (sb-int:named-let %eval ((poly poly) (l 0) (r len) (pos 0))\n (declare ((integer 0 #.most-positive-fixnum) l r pos))\n (if (= (- r l) 1)\n (let ((tmp (poly-mod poly (aref table pos))))\n (setf (aref res l) (if (zerop (length tmp)) 0 (aref tmp 0))))\n (let ((mid (ash (+ l r) -1)))\n (%eval (poly-mod poly (aref table (+ (* 2 pos) 1))) l mid (+ (* 2 pos) 1))\n (%eval (poly-mod poly (aref table (+ (* 2 pos) 2))) mid r (+ (* 2 pos) 2))))))\n res))\n\n(defpackage :cp/mod-inverse\n (:use :cl)\n (:export #:mod-inverse))\n(in-package :cp/mod-inverse)\n\n;; TODO: signal DIVISION-BY-ZERO for non-coprime input when safety >= 1\n(declaim (inline mod-inverse)\n (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 ((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 (mod u modulus)))\n\n(defpackage :cp/mod-power-table\n (:use :cl)\n (:export #:make-mod-power-table))\n(in-package :cp/mod-power-table)\n\n(declaim (inline make-mod-power-table))\n(defun make-mod-power-table (base length modulus &optional (element-type '(unsigned-byte 31)))\n \"Returns a vector of the given length: VECTOR[x] := BASE^x mod MODULUS.\"\n (declare (fixnum base)\n ((integer 0 #.most-positive-fixnum) length)\n ((integer 1 #.most-positive-fixnum) modulus))\n (let ((res (make-array length :element-type element-type)))\n (unless (zerop length)\n (setf (aref res 0) 1)\n (loop for i from 1 below length\n do (setf (aref res i)\n (mod (* base (aref res (- i 1))) modulus))))\n res))\n\n;;;\n;;; Binary heap\n;;;\n\n(defpackage :cp/abstract-heap\n (:use :cl)\n (:export #:heap-empty-error #:define-binary-heap))\n(in-package :cp/abstract-heap)\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, -CLEAR, -EMPTY-P,\n-COUNT, and -PEEK.\n\nIf ORDER is not given, heap for dynamic order is defined instead: -PUSH and -POP\nfunctions take order as an argument.\"\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-clear (intern (format nil \"~A-CLEAR\" 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 (order (or order 'order)))\n `(progn\n (locally\n ;; prevent style warnings\n (declare #+sbcl (sb-ext: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 ,@(when (eql order 'order) '(order)))\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 ,@(when (eql order 'order) '(order)))\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-clear))\n (defun ,fname-clear (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. Signals HEAP-EMPTY-ERROR if HEAP\nis empty.\"\n (if (= 1 (,acc-position heap))\n (error 'heap-empty-error :heap heap)\n (aref (,acc-data heap) 1))))))\n\n#+(or)\n(define-binary-heap heap\n :order #'>\n :element-type fixnum)\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/abstract-heap :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-power-table :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-inverse :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/polynomial-ntt :cl-user))\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/ntt :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/binomial-coefficient-mod :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-operations :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(define-binary-heap heap\n :order (lambda (poly1 poly2)\n (< (length poly1) (length poly2)))\n :element-type ntt-vector)\n\n(defun main ()\n (let* ((n (read))\n (hcounter (make-array 100000 :element-type 'uint31 :initial-element 0))\n (powers (make-mod-power-table 499122177 100001 +mod+))\n (fs (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i (* 2 n))\n (incf (aref hcounter (- (read-fixnum) 1))))\n (dotimes (i (+ n 1))\n (setf (aref fs i) (mod* (aref *fact* (* 2 i))\n (aref powers i)\n (aref *fact-inv* i))))\n (let* ((hcounter (delete 0 hcounter))\n (que (make-heap n)))\n (dotimes (j (length hcounter))\n (let* ((k (aref hcounter j))\n (poly (make-array (+ 1 (floor k 2)) :element-type 'uint31)))\n (loop for i from 0 below (length poly)\n do (setf (aref poly i)\n (mod* (binom k (* 2 i)) (aref fs i))))\n (dbg k poly)\n (heap-push poly que)))\n (loop while (>= (heap-count que) 2)\n for poly1 = (heap-pop que)\n for poly2 = (heap-pop que)\n do (heap-push (poly-multiply poly1 poly2) que))\n (let ((poly (heap-pop que))\n (res 0))\n #>poly\n (loop for i from 0 below (length poly)\n for sign = 1 then (* sign -1)\n ;; while (<= (* 2 i) n)\n do (incfmod res (mod* (aref poly i) (aref fs (- n i)) sign)))\n (println res)))))\n\n#-swank (main)\n\n;;;\n;;; Test and benchmark\n;;;\n\n#+swank\n(progn\n (defparameter *lisp-file-pathname* (uiop:current-lisp-file-pathname))\n (defparameter *dat-pathname* (uiop:merge-pathnames* \"test.dat\" *lisp-file-pathname*))\n (defparameter *problem-url* \"https://atcoder.jp/contests/abl/tasks/abl_f\"))\n\n#+swank\n(defun gen-dat ()\n (uiop:with-output-file (out *dat-pathname* :if-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 (or (> sb-c::*compiler-warning-count* 0)\n sb-c::*undefined-warnings*)\n (error \"count: ~D, undefined warnings: ~A\"\n sb-c::*compiler-warning-count*\n sb-c::*undefined-warnings*)))\n\n;; To run: (5am:run! :sample)\n#+swank\n(5am:test :sample\n (5am:is\n (equal \"2\n\"\n (run \"2\n1\n1\n2\n3\n\" nil)))\n (5am:is\n (equal \"516\n\"\n (run \"5\n30\n10\n20\n40\n20\n10\n10\n30\n50\n60\n\" nil))))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are 2N people numbered 1 through 2N.\nThe height of Person i is h_i.\n\nHow many ways are there to make N pairs of people such that the following conditions are satisfied?\nCompute the answer modulo 998,244,353.\n\nEach person is contained in exactly one pair.\n\nFor each pair, the heights of the two people in the pair are different.\n\nTwo ways are considered different if for some p and q, Person p and Person q are paired in one way and not in the other.\n\nConstraints\n\n1 \\leq N \\leq 50,000\n\n1 \\leq h_i \\leq 100,000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nh_1\n:\nh_{2N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2\n1\n1\n2\n3\n\nSample Output 1\n\n2\n\nThere are two ways:\n\nForm the pair (Person 1, Person 3) and the pair (Person 2, Person 4).\n\nForm the pair (Person 1, Person 4) and the pair (Person 2, Person 3).\n\nSample Input 2\n\n5\n30\n10\n20\n40\n20\n10\n10\n30\n50\n60\n\nSample Output 2\n\n516", "sample_input": "2\n1\n1\n2\n3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02539", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are 2N people numbered 1 through 2N.\nThe height of Person i is h_i.\n\nHow many ways are there to make N pairs of people such that the following conditions are satisfied?\nCompute the answer modulo 998,244,353.\n\nEach person is contained in exactly one pair.\n\nFor each pair, the heights of the two people in the pair are different.\n\nTwo ways are considered different if for some p and q, Person p and Person q are paired in one way and not in the other.\n\nConstraints\n\n1 \\leq N \\leq 50,000\n\n1 \\leq h_i \\leq 100,000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nh_1\n:\nh_{2N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2\n1\n1\n2\n3\n\nSample Output 1\n\n2\n\nThere are two ways:\n\nForm the pair (Person 1, Person 3) and the pair (Person 2, Person 4).\n\nForm the pair (Person 1, Person 4) and the pair (Person 2, Person 3).\n\nSample Input 2\n\n5\n30\n10\n20\n40\n20\n10\n10\n30\n50\n60\n\nSample Output 2\n\n516", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 36128, "cpu_time_ms": 276, "memory_kb": 47752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s660132710", "group_id": "codeNet:p02542", "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/max-flow\n (:use :cl)\n (:export #:edge #:add-edge #:reinitialize-flow-network #:max-flow-overflow\n #:edge-to #:edge-capacity #:edge-default-capacity #:edge-reversed))\n(in-package :cp/max-flow)\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(defstruct (edge (:constructor %make-edge\n (to capacity reversed\n &aux (default-capacity capacity))))\n (to nil :type (integer 0 #.most-positive-fixnum))\n (capacity 0 :type (integer 0 #.most-positive-fixnum))\n (default-capacity 0 :type (integer 0 #.most-positive-fixnum))\n (reversed nil :type (or null edge)))\n\n(defmethod print-object ((edge edge) stream)\n (let ((*print-circle* t))\n (call-next-method)))\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, ADD-EDGE adds the reversed edge of the same\ncapacity in addition.\"\n (declare (optimize (speed 3))\n ((simple-array list (*)) graph))\n (let* ((dep (%make-edge to-idx capacity nil))\n (ret (%make-edge from-idx\n (if bidirectional capacity 0)\n dep)))\n (setf (edge-reversed dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n(declaim (inline reinitialize-flow-network))\n(defun reinitialize-flow-network (graph)\n \"Sets the current CAPACITY of every edge in GRAPH to the default\ncapacity. That is, this function reinitialize the graph network to the state\nprior to sending flow.\"\n (loop for edges across graph\n do (dolist (edge edges)\n (setf (edge-capacity edge) (edge-default-capacity edge)))))\n\n;;;\n;;; Minimum cost flow (SSP)\n;;;\n\n(defpackage :cp/min-cost-flow\n (:use :cl :cp/max-flow)\n (:export #:cedge #:cedge-p #:copy-cedge #:add-cedge #:+inf-cost+ #:cost-type\n #:cedge-reversed #:cedge-cost #:cedge-capacity #:cedge-to #:cedge-default-capacity\n #:not-enough-capacity-error #:not-enough-capacity-error-graph\n #:not-enough-capacity-error-flow #:not-enough-capacity-error-score))\n(in-package :cp/min-cost-flow)\n\n;; COST-TYPE and +INF-COST+ may be changed. (A supposed use case is to adopt\n;; bignum).\n\n(deftype cost-type () 'fixnum)\n(defconstant +inf-cost+ most-positive-fixnum)\n(assert (and (typep +inf-cost+ 'cost-type)\n (subtypep 'cost-type 'integer)))\n\n(defstruct (cedge (:constructor %make-cedge)\n (:include edge))\n (cost 0 :type cost-type))\n\n(define-condition not-enough-capacity-error (error)\n ((graph :initarg :graph :reader not-enough-capacity-error-graph)\n (flow :initarg :flow :reader not-enough-capacity-error-flow)\n (score :initarg :score :reader not-enough-capacity-error-score))\n (:report\n (lambda (c s)\n (format s \"Cannot send ~A units of flow on graph ~A due to not enough capacity.\"\n (not-enough-capacity-error-flow c)\n (not-enough-capacity-error-graph c)))))\n\n(defmethod print-object ((cedge cedge) stream)\n (let ((*print-circle* t))\n (call-next-method)))\n\n(defun add-cedge (graph from-idx to-idx cost capacity)\n \"FROM-IDX, TO-IDX := index of vertex\nGRAPH := vector of list of all the edges that goes from the vertex\"\n (declare ((simple-array list (*)) graph)\n (cost-type cost))\n (let* ((dep (%make-cedge :to to-idx :capacity capacity :cost cost))\n (ret (%make-cedge :to from-idx :capacity 0 :cost (- cost) :reversed dep)))\n (setf (cedge-reversed dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n(defpackage :cp/ssp\n (:use :cl :cp/min-cost-flow)\n (:export #:min-cost-flow!))\n(in-package :cp/ssp)\n\n;; binary heap for Dijkstra's algorithm\n(defstruct (heap (:constructor make-heap\n (size\n &aux (costs (make-array (1+ size) :element-type 'cost-type))\n (vertices (make-array (1+ size) :element-type 'fixnum))))\n (:copier nil)\n (:predicate nil))\n (costs nil :type (simple-array cost-type (*)))\n (vertices nil :type (simple-array fixnum (*)))\n (position 1 :type (integer 1 #.most-positive-fixnum)))\n\n(defun heap-push (cost vertex heap)\n (declare (optimize (speed 3)))\n (symbol-macrolet ((position (heap-position heap)))\n (when (>= position (length (heap-costs heap)))\n (setf (heap-costs heap)\n (adjust-array (heap-costs heap) (* position 2))\n (heap-vertices heap)\n (adjust-array (heap-vertices heap) (* position 2))))\n (let ((costs (heap-costs heap))\n (vertices (heap-vertices heap)))\n (labels ((heapify (pos)\n (declare (optimize (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (< (aref costs pos) (aref costs parent-pos))\n (rotatef (aref costs pos) (aref costs parent-pos))\n (rotatef (aref vertices pos) (aref vertices parent-pos))\n (heapify parent-pos))))))\n (setf (aref costs position) cost\n (aref vertices position) vertex)\n (heapify position)\n (incf position)\n heap))))\n\n(defun heap-pop (heap)\n (declare (optimize (speed 3)))\n (symbol-macrolet ((position (heap-position heap)))\n (let ((costs (heap-costs heap))\n (vertices (heap-vertices heap)))\n (labels ((heapify (pos)\n (declare (optimize (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 (< (aref costs child-pos1) (aref costs child-pos2))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))\n (heapify child-pos1))\n (unless (< (aref costs pos) (aref costs child-pos2))\n (rotatef (aref costs pos) (aref costs child-pos2))\n (rotatef (aref vertices pos) (aref vertices child-pos2))\n (heapify child-pos2)))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))))))))\n (multiple-value-prog1 (values (aref costs 1) (aref vertices 1))\n (decf position)\n (setf (aref costs 1) (aref costs position)\n (aref vertices 1) (aref vertices position))\n (heapify 1))))))\n\n(declaim (inline heap-empty-p))\n(defun heap-empty-p (heap)\n (= (heap-position heap) 1))\n\n(declaim (inline heap-reinitialize))\n(defun heap-reinitialize (heap)\n (setf (heap-position heap) 1)\n heap)\n\n(defun min-cost-flow! (graph src-idx dest-idx flow &key edge-count (if-overflow :error))\n \"Returns the minimum cost to send FLOW units from SRC-IDX to DEST-IDX in\nGRAPH. Destructively modifies GRAPH.\n\nEDGE-COUNT := initial reserved size for heap (it should be the number of edges)\nIF-OVERFLOW := :error | nil\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) flow)\n ((simple-array list (*)) graph))\n (macrolet ((the-cost-type (form)\n (reduce (lambda (x y) `(,(car form) (the cost-type ,x) (the cost-type ,y)))\n\t\t (cdr form))))\n (let* ((size (length graph))\n (edge-count (or edge-count (* size 2)))\n (prev-vertices (make-array size :element-type 'fixnum :initial-element 0))\n (prev-edges (locally\n (declare (sb-ext:muffle-conditions style-warning))\n (make-array size :element-type 'cedge)))\n (potential (make-array size :element-type 'cost-type :initial-element 0))\n (dists (make-array size :element-type 'cost-type))\n (pqueue (make-heap edge-count))\n (res 0))\n (declare (fixnum edge-count)\n (cost-type res))\n ;; FIXME: Actually we must do Bellman-Ford here to handle negative edges\n ;; properly. Currently this function returns a correct result also for a\n ;; graph that contains negative edges, if no negative **cycles** are\n ;; contained. In this case, however, the worst-case time complexity is\n ;; exponential. As a special case, if an input network is for a weighted\n ;; bipartite matching that contains negative weights, this function\n ;; completely works without any problems.\n (loop (when (<= flow 0)\n (return))\n (fill dists +inf-cost+)\n (setf (aref dists src-idx) 0)\n (heap-reinitialize pqueue)\n (heap-push 0 src-idx pqueue)\n (loop until (heap-empty-p pqueue)\n do (multiple-value-bind (cost v) (heap-pop pqueue)\n (declare (cost-type cost)\n (fixnum v))\n (when (<= cost (aref dists v))\n (dolist (edge (aref graph v))\n (let* ((next-v (cedge-to edge))\n (next-cost (the-cost-type\n (+ (aref dists v)\n (cedge-cost edge)\n (aref potential v)\n (- (aref potential next-v))))))\n (when (and (> (cedge-capacity edge) 0)\n (> (aref dists next-v) next-cost))\n (setf (aref dists next-v) next-cost\n (aref prev-vertices next-v) v\n (aref prev-edges next-v) edge)\n (heap-push next-cost next-v pqueue)))))))\n (when (= (aref dists dest-idx) +inf-cost+)\n (if if-overflow\n (error 'not-enough-capacity-error :flow flow :graph graph :score res)\n (return)))\n (let ((max-flow flow))\n (declare (fixnum max-flow))\n (dotimes (v size)\n (setf (aref potential v)\n (min +inf-cost+\n (+ (aref potential v) (aref dists v)))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (setq max-flow (min max-flow (cedge-capacity (aref prev-edges v)))))\n (decf flow max-flow)\n (incf res (the cost-type (* max-flow (aref potential dest-idx))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (decf (cedge-capacity (aref prev-edges v)) max-flow)\n (incf (cedge-capacity (cedge-reversed (aref prev-edges v))) max-flow))))\n res)))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/ssp :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/min-cost-flow :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 (+ 2 (* n m)) :element-type 'list :initial-element nil))\n (plan (make-array (list n m) :element-type 'base-char :initial-element #\\.))\n (src (* n m))\n (dest (+ 1 (* n m)))\n (amount 0))\n (dotimes(i n)\n (let ((line (read-line)))\n (dotimes (j m)\n (ecase (aref line j)\n (#\\.)\n (#\\# (setf (aref plan i j) #\\#))\n (#\\o (setf (aref plan i j) #\\o))))))\n (labels ((encode (i j) (+ j (* i m)))\n (add (i1 j1 i2 j2)\n (when (and (<= 0 i1 (- n 1))\n (<= 0 j1 (- m 1))\n (<= 0 i2 (- n 1))\n (<= 0 j2 (- m 1))\n (char/= #\\# (aref plan i1 j1))\n (char/= #\\# (aref plan i2 j2)))\n (let ((p1 (encode i1 j1))\n (p2 (encode i2 j2)))\n (dbg i1 j1 i2 j2)\n (add-cedge graph p1 p2 -1 100)\n ;; (add-cedge graph p2 p1 -1 100)\n ;; (add-cedge graph src p2 0 100)\n ;; (add-cedge graph p1 dest 0 100)\n (incf amount 100))))\n (add-s (i j)\n (when (and (<= 0 i (- n 1))\n (<= 0 j (- m 1))\n (char= #\\o (aref plan i j)))\n (add-cedge graph src (encode i j) 0 1)))\n (add-t (i j)\n (when (and (<= 0 i (- n 1))\n (<= 0 j (- m 1))\n (char/= #\\# (aref plan i j)))\n (add-cedge graph (encode i j) dest 0 1))))\n (dotimes (i n)\n (dotimes (j m)\n (add-s i j)\n (add-t i j)\n (add i j (+ i 1) j)\n (add i j i (+ j 1))))\n (let ((res (min-cost-flow! graph src dest (count #\\o (array-storage-vector plan)))))\n (println (abs 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 \"4\n\"\n (run \"3 3\no..\n...\no.#\n\" nil)))\n (5am:is\n (equal \"24\n\"\n (run \"9 10\n.#....o#..\n.#..#..##o\n.....#o.##\n.###.#o..o\n#.#...##.#\n..#..#.###\n#o.....#..\n....###..o\no.......o#\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600630246, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02542.html", "problem_id": "p02542", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02542/input.txt", "sample_output_relpath": "derived/input_output/data/p02542/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02542/Lisp/s660132710.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s660132710", "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 (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/max-flow\n (:use :cl)\n (:export #:edge #:add-edge #:reinitialize-flow-network #:max-flow-overflow\n #:edge-to #:edge-capacity #:edge-default-capacity #:edge-reversed))\n(in-package :cp/max-flow)\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(defstruct (edge (:constructor %make-edge\n (to capacity reversed\n &aux (default-capacity capacity))))\n (to nil :type (integer 0 #.most-positive-fixnum))\n (capacity 0 :type (integer 0 #.most-positive-fixnum))\n (default-capacity 0 :type (integer 0 #.most-positive-fixnum))\n (reversed nil :type (or null edge)))\n\n(defmethod print-object ((edge edge) stream)\n (let ((*print-circle* t))\n (call-next-method)))\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, ADD-EDGE adds the reversed edge of the same\ncapacity in addition.\"\n (declare (optimize (speed 3))\n ((simple-array list (*)) graph))\n (let* ((dep (%make-edge to-idx capacity nil))\n (ret (%make-edge from-idx\n (if bidirectional capacity 0)\n dep)))\n (setf (edge-reversed dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n(declaim (inline reinitialize-flow-network))\n(defun reinitialize-flow-network (graph)\n \"Sets the current CAPACITY of every edge in GRAPH to the default\ncapacity. That is, this function reinitialize the graph network to the state\nprior to sending flow.\"\n (loop for edges across graph\n do (dolist (edge edges)\n (setf (edge-capacity edge) (edge-default-capacity edge)))))\n\n;;;\n;;; Minimum cost flow (SSP)\n;;;\n\n(defpackage :cp/min-cost-flow\n (:use :cl :cp/max-flow)\n (:export #:cedge #:cedge-p #:copy-cedge #:add-cedge #:+inf-cost+ #:cost-type\n #:cedge-reversed #:cedge-cost #:cedge-capacity #:cedge-to #:cedge-default-capacity\n #:not-enough-capacity-error #:not-enough-capacity-error-graph\n #:not-enough-capacity-error-flow #:not-enough-capacity-error-score))\n(in-package :cp/min-cost-flow)\n\n;; COST-TYPE and +INF-COST+ may be changed. (A supposed use case is to adopt\n;; bignum).\n\n(deftype cost-type () 'fixnum)\n(defconstant +inf-cost+ most-positive-fixnum)\n(assert (and (typep +inf-cost+ 'cost-type)\n (subtypep 'cost-type 'integer)))\n\n(defstruct (cedge (:constructor %make-cedge)\n (:include edge))\n (cost 0 :type cost-type))\n\n(define-condition not-enough-capacity-error (error)\n ((graph :initarg :graph :reader not-enough-capacity-error-graph)\n (flow :initarg :flow :reader not-enough-capacity-error-flow)\n (score :initarg :score :reader not-enough-capacity-error-score))\n (:report\n (lambda (c s)\n (format s \"Cannot send ~A units of flow on graph ~A due to not enough capacity.\"\n (not-enough-capacity-error-flow c)\n (not-enough-capacity-error-graph c)))))\n\n(defmethod print-object ((cedge cedge) stream)\n (let ((*print-circle* t))\n (call-next-method)))\n\n(defun add-cedge (graph from-idx to-idx cost capacity)\n \"FROM-IDX, TO-IDX := index of vertex\nGRAPH := vector of list of all the edges that goes from the vertex\"\n (declare ((simple-array list (*)) graph)\n (cost-type cost))\n (let* ((dep (%make-cedge :to to-idx :capacity capacity :cost cost))\n (ret (%make-cedge :to from-idx :capacity 0 :cost (- cost) :reversed dep)))\n (setf (cedge-reversed dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n(defpackage :cp/ssp\n (:use :cl :cp/min-cost-flow)\n (:export #:min-cost-flow!))\n(in-package :cp/ssp)\n\n;; binary heap for Dijkstra's algorithm\n(defstruct (heap (:constructor make-heap\n (size\n &aux (costs (make-array (1+ size) :element-type 'cost-type))\n (vertices (make-array (1+ size) :element-type 'fixnum))))\n (:copier nil)\n (:predicate nil))\n (costs nil :type (simple-array cost-type (*)))\n (vertices nil :type (simple-array fixnum (*)))\n (position 1 :type (integer 1 #.most-positive-fixnum)))\n\n(defun heap-push (cost vertex heap)\n (declare (optimize (speed 3)))\n (symbol-macrolet ((position (heap-position heap)))\n (when (>= position (length (heap-costs heap)))\n (setf (heap-costs heap)\n (adjust-array (heap-costs heap) (* position 2))\n (heap-vertices heap)\n (adjust-array (heap-vertices heap) (* position 2))))\n (let ((costs (heap-costs heap))\n (vertices (heap-vertices heap)))\n (labels ((heapify (pos)\n (declare (optimize (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (< (aref costs pos) (aref costs parent-pos))\n (rotatef (aref costs pos) (aref costs parent-pos))\n (rotatef (aref vertices pos) (aref vertices parent-pos))\n (heapify parent-pos))))))\n (setf (aref costs position) cost\n (aref vertices position) vertex)\n (heapify position)\n (incf position)\n heap))))\n\n(defun heap-pop (heap)\n (declare (optimize (speed 3)))\n (symbol-macrolet ((position (heap-position heap)))\n (let ((costs (heap-costs heap))\n (vertices (heap-vertices heap)))\n (labels ((heapify (pos)\n (declare (optimize (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 (< (aref costs child-pos1) (aref costs child-pos2))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))\n (heapify child-pos1))\n (unless (< (aref costs pos) (aref costs child-pos2))\n (rotatef (aref costs pos) (aref costs child-pos2))\n (rotatef (aref vertices pos) (aref vertices child-pos2))\n (heapify child-pos2)))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))))))))\n (multiple-value-prog1 (values (aref costs 1) (aref vertices 1))\n (decf position)\n (setf (aref costs 1) (aref costs position)\n (aref vertices 1) (aref vertices position))\n (heapify 1))))))\n\n(declaim (inline heap-empty-p))\n(defun heap-empty-p (heap)\n (= (heap-position heap) 1))\n\n(declaim (inline heap-reinitialize))\n(defun heap-reinitialize (heap)\n (setf (heap-position heap) 1)\n heap)\n\n(defun min-cost-flow! (graph src-idx dest-idx flow &key edge-count (if-overflow :error))\n \"Returns the minimum cost to send FLOW units from SRC-IDX to DEST-IDX in\nGRAPH. Destructively modifies GRAPH.\n\nEDGE-COUNT := initial reserved size for heap (it should be the number of edges)\nIF-OVERFLOW := :error | nil\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) flow)\n ((simple-array list (*)) graph))\n (macrolet ((the-cost-type (form)\n (reduce (lambda (x y) `(,(car form) (the cost-type ,x) (the cost-type ,y)))\n\t\t (cdr form))))\n (let* ((size (length graph))\n (edge-count (or edge-count (* size 2)))\n (prev-vertices (make-array size :element-type 'fixnum :initial-element 0))\n (prev-edges (locally\n (declare (sb-ext:muffle-conditions style-warning))\n (make-array size :element-type 'cedge)))\n (potential (make-array size :element-type 'cost-type :initial-element 0))\n (dists (make-array size :element-type 'cost-type))\n (pqueue (make-heap edge-count))\n (res 0))\n (declare (fixnum edge-count)\n (cost-type res))\n ;; FIXME: Actually we must do Bellman-Ford here to handle negative edges\n ;; properly. Currently this function returns a correct result also for a\n ;; graph that contains negative edges, if no negative **cycles** are\n ;; contained. In this case, however, the worst-case time complexity is\n ;; exponential. As a special case, if an input network is for a weighted\n ;; bipartite matching that contains negative weights, this function\n ;; completely works without any problems.\n (loop (when (<= flow 0)\n (return))\n (fill dists +inf-cost+)\n (setf (aref dists src-idx) 0)\n (heap-reinitialize pqueue)\n (heap-push 0 src-idx pqueue)\n (loop until (heap-empty-p pqueue)\n do (multiple-value-bind (cost v) (heap-pop pqueue)\n (declare (cost-type cost)\n (fixnum v))\n (when (<= cost (aref dists v))\n (dolist (edge (aref graph v))\n (let* ((next-v (cedge-to edge))\n (next-cost (the-cost-type\n (+ (aref dists v)\n (cedge-cost edge)\n (aref potential v)\n (- (aref potential next-v))))))\n (when (and (> (cedge-capacity edge) 0)\n (> (aref dists next-v) next-cost))\n (setf (aref dists next-v) next-cost\n (aref prev-vertices next-v) v\n (aref prev-edges next-v) edge)\n (heap-push next-cost next-v pqueue)))))))\n (when (= (aref dists dest-idx) +inf-cost+)\n (if if-overflow\n (error 'not-enough-capacity-error :flow flow :graph graph :score res)\n (return)))\n (let ((max-flow flow))\n (declare (fixnum max-flow))\n (dotimes (v size)\n (setf (aref potential v)\n (min +inf-cost+\n (+ (aref potential v) (aref dists v)))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (setq max-flow (min max-flow (cedge-capacity (aref prev-edges v)))))\n (decf flow max-flow)\n (incf res (the cost-type (* max-flow (aref potential dest-idx))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (decf (cedge-capacity (aref prev-edges v)) max-flow)\n (incf (cedge-capacity (cedge-reversed (aref prev-edges v))) max-flow))))\n res)))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/ssp :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/min-cost-flow :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 (+ 2 (* n m)) :element-type 'list :initial-element nil))\n (plan (make-array (list n m) :element-type 'base-char :initial-element #\\.))\n (src (* n m))\n (dest (+ 1 (* n m)))\n (amount 0))\n (dotimes(i n)\n (let ((line (read-line)))\n (dotimes (j m)\n (ecase (aref line j)\n (#\\.)\n (#\\# (setf (aref plan i j) #\\#))\n (#\\o (setf (aref plan i j) #\\o))))))\n (labels ((encode (i j) (+ j (* i m)))\n (add (i1 j1 i2 j2)\n (when (and (<= 0 i1 (- n 1))\n (<= 0 j1 (- m 1))\n (<= 0 i2 (- n 1))\n (<= 0 j2 (- m 1))\n (char/= #\\# (aref plan i1 j1))\n (char/= #\\# (aref plan i2 j2)))\n (let ((p1 (encode i1 j1))\n (p2 (encode i2 j2)))\n (dbg i1 j1 i2 j2)\n (add-cedge graph p1 p2 -1 100)\n ;; (add-cedge graph p2 p1 -1 100)\n ;; (add-cedge graph src p2 0 100)\n ;; (add-cedge graph p1 dest 0 100)\n (incf amount 100))))\n (add-s (i j)\n (when (and (<= 0 i (- n 1))\n (<= 0 j (- m 1))\n (char= #\\o (aref plan i j)))\n (add-cedge graph src (encode i j) 0 1)))\n (add-t (i j)\n (when (and (<= 0 i (- n 1))\n (<= 0 j (- m 1))\n (char/= #\\# (aref plan i j)))\n (add-cedge graph (encode i j) dest 0 1))))\n (dotimes (i n)\n (dotimes (j m)\n (add-s i j)\n (add-t i j)\n (add i j (+ i 1) j)\n (add i j i (+ j 1))))\n (let ((res (min-cost-flow! graph src dest (count #\\o (array-storage-vector plan)))))\n (println (abs 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 \"4\n\"\n (run \"3 3\no..\n...\no.#\n\" nil)))\n (5am:is\n (equal \"24\n\"\n (run \"9 10\n.#....o#..\n.#..#..##o\n.....#o.##\n.###.#o..o\n#.#...##.#\n..#..#.###\n#o.....#..\n....###..o\no.......o#\n\" nil))))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere is a board with N rows and M columns.\nThe information of this board is represented by N strings S_1,S_2,\\ldots,S_N.\nSpecifically, the state of the square at the i-th row from the top and the j-th column from the left is represented as follows:\n\nS_{i,j}=. : the square is empty.\n\nS_{i,j}=# : an obstacle is placed on the square.\n\nS_{i,j}=o : a piece is placed on the square.\n\nYosupo repeats the following operation:\n\nChoose a piece and move it to its right adjecent square or its down adjacent square.\nMoving a piece to squares with another piece or an obstacle is prohibited.\nMoving a piece out of the board is also prohibited.\n\nYosupo wants to perform the operation as many times as possible.\nFind the maximum possible number of operations.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n1 \\leq M \\leq 50\n\nS_i is a string of length M consisting of ., # and o.\n\n1 \\leq ( the number of pieces )\\leq 100.\nIn other words, the number of pairs (i, j) that satisfy S_{i,j}=o is between 1 and 100, both inclusive.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nS_1\nS_2\n\\vdots\nS_N\n\nOutput\n\nPrint the maximum possible number of operations in a line.\n\nSample Input 1\n\n3 3\no..\n...\no.#\n\nSample Output 1\n\n4\n\nYosupo can perform operations 4 times as follows:\n\no.. .o. ..o ... ...\n... -> ... -> ... -> ..o -> ..o\no.# o.# o.# o.# .o#\n\nSample Input 2\n\n9 10\n.#....o#..\n.#..#..##o\n.....#o.##\n.###.#o..o\n#.#...##.#\n..#..#.###\n#o.....#..\n....###..o\no.......o#\n\nSample Output 2\n\n24", "sample_input": "3 3\no..\n...\no.#\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02542", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere is a board with N rows and M columns.\nThe information of this board is represented by N strings S_1,S_2,\\ldots,S_N.\nSpecifically, the state of the square at the i-th row from the top and the j-th column from the left is represented as follows:\n\nS_{i,j}=. : the square is empty.\n\nS_{i,j}=# : an obstacle is placed on the square.\n\nS_{i,j}=o : a piece is placed on the square.\n\nYosupo repeats the following operation:\n\nChoose a piece and move it to its right adjecent square or its down adjacent square.\nMoving a piece to squares with another piece or an obstacle is prohibited.\nMoving a piece out of the board is also prohibited.\n\nYosupo wants to perform the operation as many times as possible.\nFind the maximum possible number of operations.\n\nConstraints\n\n1 \\leq N \\leq 50\n\n1 \\leq M \\leq 50\n\nS_i is a string of length M consisting of ., # and o.\n\n1 \\leq ( the number of pieces )\\leq 100.\nIn other words, the number of pairs (i, j) that satisfy S_{i,j}=o is between 1 and 100, both inclusive.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nS_1\nS_2\n\\vdots\nS_N\n\nOutput\n\nPrint the maximum possible number of operations in a line.\n\nSample Input 1\n\n3 3\no..\n...\no.#\n\nSample Output 1\n\n4\n\nYosupo can perform operations 4 times as follows:\n\no.. .o. ..o ... ...\n... -> ... -> ... -> ..o -> ..o\no.# o.# o.# o.# .o#\n\nSample Input 2\n\n9 10\n.#....o#..\n.#..#..##o\n.....#o.##\n.###.#o..o\n#.#...##.#\n..#..#.###\n#o.....#..\n....###..o\no.......o#\n\nSample Output 2\n\n24", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 17057, "cpu_time_ms": 56, "memory_kb": 27936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s322766225", "group_id": "codeNet:p02546", "input_text": "(let ((str (read-line)))\n (format t \"~A~:[s~;es~]\" str (eq #\\s (car (last (coerce str 'list))))))", "language": "Lisp", "metadata": {"date": 1600703866, "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/s322766225.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s322766225", "user_id": "u334552723"}, "prompt_components": {"gold_output": "apples\n", "input_to_evaluate": "(let ((str (read-line)))\n (format t \"~A~:[s~;es~]\" str (eq #\\s (car (last (coerce str 'list))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 24340}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s781341179", "group_id": "codeNet:p02546", "input_text": "(let* ((s (read-line)))\n (format t \"~A~A~%\" s (if (char= (aref s (1- (length s))) #\\s)\n \"es\"\n \"s\")))\n", "language": "Lisp", "metadata": {"date": 1600542113, "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/s781341179.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s781341179", "user_id": "u608227593"}, "prompt_components": {"gold_output": "apples\n", "input_to_evaluate": "(let* ((s (read-line)))\n (format t \"~A~A~%\" s (if (char= (aref s (1- (length s))) #\\s)\n \"es\"\n \"s\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 20, "memory_kb": 24292}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s833687050", "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": 1600544139, "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/s833687050.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s833687050", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 22, "memory_kb": 23740}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s080970175", "group_id": "codeNet:p02548", "input_text": "(let ((n (read))\n (ans 0))\n (loop :for a :from 1 :to (1- n)\n :do (loop :for b :from 1\n :while (< (* a b) n)\n :do (incf ans)))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1600543440, "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/s080970175.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s080970175", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((n (read))\n (ans 0))\n (loop :for a :from 1 :to (1- n)\n :do (loop :for b :from 1\n :while (< (* a b) n)\n :do (incf ans)))\n (format t \"~A~%\" 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 198, "cpu_time_ms": 98, "memory_kb": 24364}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s735555593", "group_id": "codeNet:p02549", "input_text": "(loop with N = (read) for i from 2 to N \n with lst = (loop repeat (read) collect (cons (read) (read)))\n and ht = (make-hash-table)\n and divisor = 998244353 and diff\n initially (setf (gethash 1 ht) 1)\n do (setf diff (loop for x in lst\n sum (- (or (gethash (- i (car x)) ht) 0)\n (or (gethash (- i (cdr x) 1) ht) 0)))\n (gethash i ht) (mod (+ (gethash (1- i) ht) diff) divisor))\n finally (princ diff))", "language": "Lisp", "metadata": {"date": 1600709240, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02549.html", "problem_id": "p02549", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02549/input.txt", "sample_output_relpath": "derived/input_output/data/p02549/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02549/Lisp/s735555593.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s735555593", "user_id": "u334552723"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(loop with N = (read) for i from 2 to N \n with lst = (loop repeat (read) collect (cons (read) (read)))\n and ht = (make-hash-table)\n and divisor = 998244353 and diff\n initially (setf (gethash 1 ht) 1)\n do (setf diff (loop for x in lst\n sum (- (or (gethash (- i (car x)) ht) 0)\n (or (gethash (- i (cdr x) 1) ht) 0)))\n (gethash i ht) (mod (+ (gethash (1- i) ht) diff) divisor))\n finally (princ diff))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N cells arranged in a row, numbered 1, 2, \\ldots, N from left to right.\n\nTak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below.\n\nYou are given an integer K that is less than or equal to 10, and K non-intersecting segments [L_1, R_1], [L_2, R_2], \\ldots, [L_K, R_K].\nLet S be the union of these K segments.\nHere, the segment [l, r] denotes the set consisting of all integers i that satisfy l \\leq i \\leq r.\n\n\bWhen you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells.\n\nTo help Tak, find the number of ways to go to Cell N, modulo 998244353.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq \\min(N, 10)\n\n1 \\leq L_i \\leq R_i \\leq N\n\n[L_i, R_i] and [L_j, R_j] do not intersect (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 K\nL_1 R_1\nL_2 R_2\n:\nL_K R_K\n\nOutput\n\nPrint the number of ways for Tak to go from Cell 1 to Cell N, modulo 998244353.\n\nSample Input 1\n\n5 2\n1 1\n3 4\n\nSample Output 1\n\n4\n\nThe set S is the union of the segment [1, 1] and the segment [3, 4], therefore S = \\{ 1, 3, 4 \\} holds.\n\nThere are 4 possible ways to get to Cell 5:\n\n1 \\to 2 \\to 3 \\to 4 \\to 5,\n\n1 \\to 2 \\to 5,\n\n1 \\to 4 \\to 5 and\n\n1 \\to 5.\n\nSample Input 2\n\n5 2\n3 3\n5 5\n\nSample Output 2\n\n0\n\nBecause S = \\{ 3, 5 \\} holds, you cannot reach to Cell 5.\nPrint 0.\n\nSample Input 3\n\n5 1\n1 2\n\nSample Output 3\n\n5\n\nSample Input 4\n\n60 3\n5 8\n1 3\n10 15\n\nSample Output 4\n\n221823067\n\nNote that you have to print the answer modulo 998244353.", "sample_input": "5 2\n1 1\n3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02549", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N cells arranged in a row, numbered 1, 2, \\ldots, N from left to right.\n\nTak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below.\n\nYou are given an integer K that is less than or equal to 10, and K non-intersecting segments [L_1, R_1], [L_2, R_2], \\ldots, [L_K, R_K].\nLet S be the union of these K segments.\nHere, the segment [l, r] denotes the set consisting of all integers i that satisfy l \\leq i \\leq r.\n\n\bWhen you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells.\n\nTo help Tak, find the number of ways to go to Cell N, modulo 998244353.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq \\min(N, 10)\n\n1 \\leq L_i \\leq R_i \\leq N\n\n[L_i, R_i] and [L_j, R_j] do not intersect (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 K\nL_1 R_1\nL_2 R_2\n:\nL_K R_K\n\nOutput\n\nPrint the number of ways for Tak to go from Cell 1 to Cell N, modulo 998244353.\n\nSample Input 1\n\n5 2\n1 1\n3 4\n\nSample Output 1\n\n4\n\nThe set S is the union of the segment [1, 1] and the segment [3, 4], therefore S = \\{ 1, 3, 4 \\} holds.\n\nThere are 4 possible ways to get to Cell 5:\n\n1 \\to 2 \\to 3 \\to 4 \\to 5,\n\n1 \\to 2 \\to 5,\n\n1 \\to 4 \\to 5 and\n\n1 \\to 5.\n\nSample Input 2\n\n5 2\n3 3\n5 5\n\nSample Output 2\n\n0\n\nBecause S = \\{ 3, 5 \\} holds, you cannot reach to Cell 5.\nPrint 0.\n\nSample Input 3\n\n5 1\n1 2\n\nSample Output 3\n\n5\n\nSample Input 4\n\n60 3\n5 8\n1 3\n10 15\n\nSample Output 4\n\n221823067\n\nNote that you have to print the answer modulo 998244353.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 498, "cpu_time_ms": 127, "memory_kb": 45920}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s685970752", "group_id": "codeNet:p02549", "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+ 998244353)\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;;; Arithmetic operations with static modulus\n;;;\n\n(defpackage :cp/mod-operations\n (:use :cl)\n (:export #:define-mod-operations))\n(in-package :cp/mod-operations)\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\n(defmacro define-mod-operations (divisor &optional (package (sb-int:sane-package)))\n (let ((mod* (intern \"MOD*\" package))\n (mod+ (intern \"MOD+\" package))\n (incfmod (intern \"INCFMOD\" package))\n (decfmod (intern \"DECFMOD\" package))\n (mulfmod (intern \"MULFMOD\" package)))\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 (sb-ext: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(define-mod-operations cl-user::+mod+ :cl-user)\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-operations :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (ls (make-array k :element-type 'uint31 :initial-element 0))\n (rs (make-array k :element-type 'uint31 :initial-element 0))\n (dp (make-array n :element-type 'uint31 :initial-element 0))\n (cumul (make-array n :element-type 'uint31 :initial-element 0)))\n (setf (aref dp 0) 1)\n (dotimes (i k)\n (let ((l (read))\n (r (+ (read) 1)))\n (setf (aref ls i) l\n (aref rs i) r)))\n (setf (aref cumul 0) 1)\n #>ls\n #>rs\n (dotimes (x n)\n (when (> x 0)\n (incfmod (aref cumul x) (aref cumul (- x 1))))\n (loop for l across ls\n for r across rs\n when (< (+ x l) n)\n do (incfmod (aref cumul (+ x l)) (aref cumul x))\n when (< (+ x r) n)\n do (decfmod (aref cumul (+ x r)) (aref cumul x))))\n (println (mod (- (aref cumul (- n 1)) (aref cumul (- n 2))) +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 (5am:is\n (equal \"4\n\"\n (run \"5 2\n1 1\n3 4\n\" nil)))\n (5am:is\n (equal \"0\n\"\n (run \"5 2\n3 3\n5 5\n\" nil)))\n (5am:is\n (equal \"5\n\"\n (run \"5 1\n1 2\n\" nil)))\n (5am:is\n (equal \"221823067\n\"\n (run \"60 3\n5 8\n1 3\n10 15\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600543248, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02549.html", "problem_id": "p02549", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02549/input.txt", "sample_output_relpath": "derived/input_output/data/p02549/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02549/Lisp/s685970752.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s685970752", "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 (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+ 998244353)\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;;; Arithmetic operations with static modulus\n;;;\n\n(defpackage :cp/mod-operations\n (:use :cl)\n (:export #:define-mod-operations))\n(in-package :cp/mod-operations)\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\n(defmacro define-mod-operations (divisor &optional (package (sb-int:sane-package)))\n (let ((mod* (intern \"MOD*\" package))\n (mod+ (intern \"MOD+\" package))\n (incfmod (intern \"INCFMOD\" package))\n (decfmod (intern \"DECFMOD\" package))\n (mulfmod (intern \"MULFMOD\" package)))\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 (sb-ext: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(define-mod-operations cl-user::+mod+ :cl-user)\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/mod-operations :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (ls (make-array k :element-type 'uint31 :initial-element 0))\n (rs (make-array k :element-type 'uint31 :initial-element 0))\n (dp (make-array n :element-type 'uint31 :initial-element 0))\n (cumul (make-array n :element-type 'uint31 :initial-element 0)))\n (setf (aref dp 0) 1)\n (dotimes (i k)\n (let ((l (read))\n (r (+ (read) 1)))\n (setf (aref ls i) l\n (aref rs i) r)))\n (setf (aref cumul 0) 1)\n #>ls\n #>rs\n (dotimes (x n)\n (when (> x 0)\n (incfmod (aref cumul x) (aref cumul (- x 1))))\n (loop for l across ls\n for r across rs\n when (< (+ x l) n)\n do (incfmod (aref cumul (+ x l)) (aref cumul x))\n when (< (+ x r) n)\n do (decfmod (aref cumul (+ x r)) (aref cumul x))))\n (println (mod (- (aref cumul (- n 1)) (aref cumul (- n 2))) +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 (5am:is\n (equal \"4\n\"\n (run \"5 2\n1 1\n3 4\n\" nil)))\n (5am:is\n (equal \"0\n\"\n (run \"5 2\n3 3\n5 5\n\" nil)))\n (5am:is\n (equal \"5\n\"\n (run \"5 1\n1 2\n\" nil)))\n (5am:is\n (equal \"221823067\n\"\n (run \"60 3\n5 8\n1 3\n10 15\n\" nil))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N cells arranged in a row, numbered 1, 2, \\ldots, N from left to right.\n\nTak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below.\n\nYou are given an integer K that is less than or equal to 10, and K non-intersecting segments [L_1, R_1], [L_2, R_2], \\ldots, [L_K, R_K].\nLet S be the union of these K segments.\nHere, the segment [l, r] denotes the set consisting of all integers i that satisfy l \\leq i \\leq r.\n\n\bWhen you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells.\n\nTo help Tak, find the number of ways to go to Cell N, modulo 998244353.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq \\min(N, 10)\n\n1 \\leq L_i \\leq R_i \\leq N\n\n[L_i, R_i] and [L_j, R_j] do not intersect (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 K\nL_1 R_1\nL_2 R_2\n:\nL_K R_K\n\nOutput\n\nPrint the number of ways for Tak to go from Cell 1 to Cell N, modulo 998244353.\n\nSample Input 1\n\n5 2\n1 1\n3 4\n\nSample Output 1\n\n4\n\nThe set S is the union of the segment [1, 1] and the segment [3, 4], therefore S = \\{ 1, 3, 4 \\} holds.\n\nThere are 4 possible ways to get to Cell 5:\n\n1 \\to 2 \\to 3 \\to 4 \\to 5,\n\n1 \\to 2 \\to 5,\n\n1 \\to 4 \\to 5 and\n\n1 \\to 5.\n\nSample Input 2\n\n5 2\n3 3\n5 5\n\nSample Output 2\n\n0\n\nBecause S = \\{ 3, 5 \\} holds, you cannot reach to Cell 5.\nPrint 0.\n\nSample Input 3\n\n5 1\n1 2\n\nSample Output 3\n\n5\n\nSample Input 4\n\n60 3\n5 8\n1 3\n10 15\n\nSample Output 4\n\n221823067\n\nNote that you have to print the answer modulo 998244353.", "sample_input": "5 2\n1 1\n3 4\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02549", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N cells arranged in a row, numbered 1, 2, \\ldots, N from left to right.\n\nTak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below.\n\nYou are given an integer K that is less than or equal to 10, and K non-intersecting segments [L_1, R_1], [L_2, R_2], \\ldots, [L_K, R_K].\nLet S be the union of these K segments.\nHere, the segment [l, r] denotes the set consisting of all integers i that satisfy l \\leq i \\leq r.\n\n\bWhen you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells.\n\nTo help Tak, find the number of ways to go to Cell N, modulo 998244353.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq K \\leq \\min(N, 10)\n\n1 \\leq L_i \\leq R_i \\leq N\n\n[L_i, R_i] and [L_j, R_j] do not intersect (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 K\nL_1 R_1\nL_2 R_2\n:\nL_K R_K\n\nOutput\n\nPrint the number of ways for Tak to go from Cell 1 to Cell N, modulo 998244353.\n\nSample Input 1\n\n5 2\n1 1\n3 4\n\nSample Output 1\n\n4\n\nThe set S is the union of the segment [1, 1] and the segment [3, 4], therefore S = \\{ 1, 3, 4 \\} holds.\n\nThere are 4 possible ways to get to Cell 5:\n\n1 \\to 2 \\to 3 \\to 4 \\to 5,\n\n1 \\to 2 \\to 5,\n\n1 \\to 4 \\to 5 and\n\n1 \\to 5.\n\nSample Input 2\n\n5 2\n3 3\n5 5\n\nSample Output 2\n\n0\n\nBecause S = \\{ 3, 5 \\} holds, you cannot reach to Cell 5.\nPrint 0.\n\nSample Input 3\n\n5 1\n1 2\n\nSample Output 3\n\n5\n\nSample Input 4\n\n60 3\n5 8\n1 3\n10 15\n\nSample Output 4\n\n221823067\n\nNote that you have to print the answer modulo 998244353.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6139, "cpu_time_ms": 60, "memory_kb": 25672}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s511064033", "group_id": "codeNet:p02552", "input_text": "(if (zerop (read))\n (format t \"0\")\n (format t \"1\"))", "language": "Lisp", "metadata": {"date": 1600024055, "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/s511064033.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s511064033", "user_id": "u611236551"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(if (zerop (read))\n (format t \"0\")\n (format t \"1\"))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 23256}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s283827530", "group_id": "codeNet:p02553", "input_text": "(let ((a (read))\n (b (read))\n (c (read))\n (d (read)))\n (max (* a b) (* a c) (* b c) (* b d)))", "language": "Lisp", "metadata": {"date": 1600030339, "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/s283827530.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s283827530", "user_id": "u611236551"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read))\n (d (read)))\n (max (* a b) (* a c) (* b c) (* b d)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 23268}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s402779489", "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\n(let ((a (read))\n (b (read))\n (c (read))\n (d (read)))\n (format t \"~a\" (hoge a b c d)))\n", "language": "Lisp", "metadata": {"date": 1600025300, "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/s402779489.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s402779489", "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\n(let ((a (read))\n (b (read))\n (c (read))\n (d (read)))\n (format t \"~a\" (hoge a b c d)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 530, "cpu_time_ms": 27, "memory_kb": 24396}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s728524557", "group_id": "codeNet:p02554", "input_text": ";;;; mod\n(let ((p 1000000007))\n (defun mod+ (a b)\n (mod (+ a b) p))\n\n (defun mod- (a b)\n (mod (- a b) p))\n\n (defun mod* (a b)\n (mod (* a b) p))\n\n (defun mod_expt (a z)\n (loop :with ans := 1\n :with pow := a\n :while (> z 0)\n :do (multiple-value-bind (x y) (floor z 2)\n (setf z x)\n (if (= y 1) (setf ans (mod* ans pow)))\n (setf pow (mod* pow pow)))\n :finally (return ans)))\n\n (defun mod_inv (a)\n ; TODO use Euclidean\n (mod_expt a (- p 2))))\n\n;;;; main\n(let* ((n (read))\n (x (mod_expt 10 n)) ; 0-9\n (y (mod_expt 9 n)) ; 0-8, 1-9\n (z (mod_expt 8 n))) ; 1-8\n (format t \"~A~%\" (mod- (mod+ x z) (mod* 2 y))))\n", "language": "Lisp", "metadata": {"date": 1600024253, "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/s728524557.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s728524557", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";;;; mod\n(let ((p 1000000007))\n (defun mod+ (a b)\n (mod (+ a b) p))\n\n (defun mod- (a b)\n (mod (- a b) p))\n\n (defun mod* (a b)\n (mod (* a b) p))\n\n (defun mod_expt (a z)\n (loop :with ans := 1\n :with pow := a\n :while (> z 0)\n :do (multiple-value-bind (x y) (floor z 2)\n (setf z x)\n (if (= y 1) (setf ans (mod* ans pow)))\n (setf pow (mod* pow pow)))\n :finally (return ans)))\n\n (defun mod_inv (a)\n ; TODO use Euclidean\n (mod_expt a (- p 2))))\n\n;;;; main\n(let* ((n (read))\n (x (mod_expt 10 n)) ; 0-9\n (y (mod_expt 9 n)) ; 0-8, 1-9\n (z (mod_expt 8 n))) ; 1-8\n (format t \"~A~%\" (mod- (mod+ x z) (mod* 2 y))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 724, "cpu_time_ms": 18, "memory_kb": 24444}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s475042550", "group_id": "codeNet:p02557", "input_text": ";;;; 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 := nil\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 (push x sub)))\n :if (null stack)\n :do (progn\n (cond ((and (= i (1- n)) (/= (aref a 0) (car sub)) (/= (aref a i) (aref c 0)))\n (setf (aref c i) (aref c 0))\n (setf (aref c 0) (pop sub))\n (return-from inner nil))\n (t\n (format t \"No~%\")\n (return-from main)))))\n :do (loop :while sub\n :for x := (pop sub)\n :do (push x stack))\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": 1600028908, "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/s475042550.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s475042550", "user_id": "u608227593"}, "prompt_components": {"gold_output": "Yes\n2 2 3 1 1 1\n", "input_to_evaluate": ";;;; 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 := nil\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 (push x sub)))\n :if (null stack)\n :do (progn\n (cond ((and (= i (1- n)) (/= (aref a 0) (car sub)) (/= (aref a i) (aref c 0)))\n (setf (aref c i) (aref c 0))\n (setf (aref c 0) (pop sub))\n (return-from inner nil))\n (t\n (format t \"No~%\")\n (return-from main)))))\n :do (loop :while sub\n :for x := (pop sub)\n :do (push x stack))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2209, "memory_kb": 100708}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s162542704", "group_id": "codeNet:p02568", "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+ 998244353)\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;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defpackage :cp/mod-operations\n (:use :cl)\n (:export #:define-mod-operations))\n(in-package :cp/mod-operations)\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\n(defmacro define-mod-operations (divisor)\n (let ((mod* (intern \"MOD*\"))\n (mod+ (intern \"MOD+\"))\n (incfmod (intern \"INCFMOD\"))\n (decfmod (intern \"DECFMOD\"))\n (mulfmod (intern \"MULFMOD\")))\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 (sb-ext: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;;; Implicit treap\n;;; (treap with implicit key)\n;;;\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-left #:itreap-update #:itreap-reverse\n #:itreap-bisect-left #:itreap-bisect-right #:itreap-insort)\n (:import-from :cl-user\n #:+mod+))\n(in-package :cp/implicit-treap)\n\n;; Note:\n;; - An empty treap is NIL.\n\n(deftype uint31 () '(unsigned-byte 31))\n(deftype node () '(cons uint31 uint31))\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (mod (+ a b) +mod+))\n\n(defconstant +op-identity+ 0\n \"identity element w.r.t. OP\")\n\n(declaim (inline updater-op))\n(defun updater-op (node1 node2)\n \"Is the operator to compute and update LAZY value. A is the current LAZY value\nand B is operand.\"\n (declare (node node1 node2))\n (cons (mod (* (car node1) (car node2)) +mod+)\n (mod (+ (mod (* (car node2) (cdr node1)) +mod+)\n (cdr node2))\n +mod+)))\n\n(sb-int:defconstant-eqx +updater-identity+ (cons 1 0) #'equal)\n\n(declaim (inline modifier-op))\n(defun modifier-op (acc x size)\n \"Is the operator to update ACCUMULATOR (and VALUE) based on LAZY value. ACC is\nthe current ACCUMULATOR value and X is the LAZY value. SIZE is the length of the\nspecified interval.\"\n (declare (ignorable size)\n ((unsigned-byte 31) acc size)\n (node x))\n (mod (+ (mod (* acc (car x)) +mod+)\n (mod (* (cdr x) size) +mod+))\n +mod+))\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 (unsigned-byte 31))\n (accumulator +op-identity+ :type (unsigned-byte 31))\n (lazy +updater-identity+ :type node)\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(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 (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(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 the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of the elements in 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(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP 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 \"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 (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-left))\n(defun itreap-fold-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 deals with 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 (force-down itreap)\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 (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 (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;;; Utilities for sorted treap\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\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/mod-operations :cl-user))\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-fixnum))\n (q (read-fixnum))\n (as (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((dp (make-itreap n :initial-contents as)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ q)\n (let ((type (read-fixnum)))\n (ecase type\n (0 (let ((l (read-fixnum))\n (r (read-fixnum))\n (b (read-fixnum))\n (c (read-fixnum)))\n (setq dp (itreap-update dp (cons b c) l r))))\n (1 (let ((l (read-fixnum))\n (r (read-fixnum)))\n (println (itreap-fold dp l r))))))))))))\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 \"15\n404\n41511\n4317767\n\"\n (run \"5 7\n1 2 3 4 5\n1 0 5\n0 2 4 100 101\n1 0 3\n0 1 3 102 103\n1 2 5\n0 2 5 104 105\n1 0 5\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1599604733, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02568.html", "problem_id": "p02568", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02568/input.txt", "sample_output_relpath": "derived/input_output/data/p02568/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02568/Lisp/s162542704.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s162542704", "user_id": "u352600849"}, "prompt_components": {"gold_output": "15\n404\n41511\n4317767\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+ 998244353)\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;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n(defpackage :cp/mod-operations\n (:use :cl)\n (:export #:define-mod-operations))\n(in-package :cp/mod-operations)\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\n(defmacro define-mod-operations (divisor)\n (let ((mod* (intern \"MOD*\"))\n (mod+ (intern \"MOD+\"))\n (incfmod (intern \"INCFMOD\"))\n (decfmod (intern \"DECFMOD\"))\n (mulfmod (intern \"MULFMOD\")))\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 (sb-ext: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;;; Implicit treap\n;;; (treap with implicit key)\n;;;\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-left #:itreap-update #:itreap-reverse\n #:itreap-bisect-left #:itreap-bisect-right #:itreap-insort)\n (:import-from :cl-user\n #:+mod+))\n(in-package :cp/implicit-treap)\n\n;; Note:\n;; - An empty treap is NIL.\n\n(deftype uint31 () '(unsigned-byte 31))\n(deftype node () '(cons uint31 uint31))\n\n(declaim (inline op))\n(defun op (a b)\n \"Is a binary operator comprising a monoid.\"\n (mod (+ a b) +mod+))\n\n(defconstant +op-identity+ 0\n \"identity element w.r.t. OP\")\n\n(declaim (inline updater-op))\n(defun updater-op (node1 node2)\n \"Is the operator to compute and update LAZY value. A is the current LAZY value\nand B is operand.\"\n (declare (node node1 node2))\n (cons (mod (* (car node1) (car node2)) +mod+)\n (mod (+ (mod (* (car node2) (cdr node1)) +mod+)\n (cdr node2))\n +mod+)))\n\n(sb-int:defconstant-eqx +updater-identity+ (cons 1 0) #'equal)\n\n(declaim (inline modifier-op))\n(defun modifier-op (acc x size)\n \"Is the operator to update ACCUMULATOR (and VALUE) based on LAZY value. ACC is\nthe current ACCUMULATOR value and X is the LAZY value. SIZE is the length of the\nspecified interval.\"\n (declare (ignorable size)\n ((unsigned-byte 31) acc size)\n (node x))\n (mod (+ (mod (* acc (car x)) +mod+)\n (mod (* (cdr x) size) +mod+))\n +mod+))\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 (unsigned-byte 31))\n (accumulator +op-identity+ :type (unsigned-byte 31))\n (lazy +updater-identity+ :type node)\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(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 (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(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 the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of the elements in 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(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP 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 \"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 (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-left))\n(defun itreap-fold-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 deals with 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 (force-down itreap)\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 (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 (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;;; Utilities for sorted treap\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\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/mod-operations :cl-user))\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-fixnum))\n (q (read-fixnum))\n (as (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((dp (make-itreap n :initial-contents as)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (_ q)\n (let ((type (read-fixnum)))\n (ecase type\n (0 (let ((l (read-fixnum))\n (r (read-fixnum))\n (b (read-fixnum))\n (c (read-fixnum)))\n (setq dp (itreap-update dp (cons b c) l r))))\n (1 (let ((l (read-fixnum))\n (r (read-fixnum)))\n (println (itreap-fold dp l r))))))))))))\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 \"15\n404\n41511\n4317767\n\"\n (run \"5 7\n1 2 3 4 5\n1 0 5\n0 2 4 100 101\n1 0 3\n0 1 3 102 103\n1 2 5\n0 2 5 104 105\n1 0 5\n\" nil))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.\n\n0 l r b c: For each i = l, l+1, \\dots, {r - 1}, set a_i \\gets b \\times a_i + c.\n\n1 l r: Print \\sum_{i = l}^{r - 1} a_i \\bmod 998244353.\n\nConstraints\n\n1 \\leq N, Q \\leq 500000\n\n0 \\leq a_i, c < 998244353\n\n1 \\leq b < 998244353\n\n0 \\leq l < r \\leq N\n\nAll values in Input are integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\na_0 a_1 ... a_{N - 1}\n\\textrm{Query}_0\n\\textrm{Query}_1\n:\n\\textrm{Query}_{Q - 1}\n\nOutput\n\nFor each query of the latter type, print the answer.\n\nSample Input 1\n\n5 7\n1 2 3 4 5\n1 0 5\n0 2 4 100 101\n1 0 3\n0 1 3 102 103\n1 2 5\n0 2 5 104 105\n1 0 5\n\nSample Output 1\n\n15\n404\n41511\n4317767", "sample_input": "5 7\n1 2 3 4 5\n1 0 5\n0 2 4 100 101\n1 0 3\n0 1 3 102 103\n1 2 5\n0 2 5 104 105\n1 0 5\n"}, "reference_outputs": ["15\n404\n41511\n4317767\n"], "source_document_id": "p02568", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.\n\n0 l r b c: For each i = l, l+1, \\dots, {r - 1}, set a_i \\gets b \\times a_i + c.\n\n1 l r: Print \\sum_{i = l}^{r - 1} a_i \\bmod 998244353.\n\nConstraints\n\n1 \\leq N, Q \\leq 500000\n\n0 \\leq a_i, c < 998244353\n\n1 \\leq b < 998244353\n\n0 \\leq l < r \\leq N\n\nAll values in Input are integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\na_0 a_1 ... a_{N - 1}\n\\textrm{Query}_0\n\\textrm{Query}_1\n:\n\\textrm{Query}_{Q - 1}\n\nOutput\n\nFor each query of the latter type, print the answer.\n\nSample Input 1\n\n5 7\n1 2 3 4 5\n1 0 5\n0 2 4 100 101\n1 0 3\n0 1 3 102 103\n1 2 5\n0 2 5 104 105\n1 0 5\n\nSample Output 1\n\n15\n404\n41511\n4317767", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 30259, "cpu_time_ms": 5516, "memory_kb": 131512}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s179915224", "group_id": "codeNet:p02569", "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/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;; DEFINE-INTEGER-PACK and DEFINE-CONS-PACK are so to say poor man's variants of\n;; DEFSTRUCT. Both \"structures\" can only have slots of fixed unsigned\n;; bytes. DEFINE-INTEGER-PACK handles the concatenated slots as UNSIGNED-BYTE\n;; and DEFINE-CONS-PACK handles them as (CONS (UNSIGNED-BYTE 62) (UNSIGNED-BYTE\n;; 62)).\n\n;; Example:\n;; The following form defines the type NODE as (UNSIGNED-BYTE 9):\n;; (define-integer-pack node (slot1 3) (slot2 5) (slot3 1))\n;; This macro in addition defines relevant utilities: NODE-SLOT1, NODE-SLOT2,\n;; NODE-SLOT3, setters and getters, PACK-NODE, the constructor, and\n;; WITH-UNPACKING-NODE, the destructuring-bind-style macro.\n;; \n;; DEFINE-CONS-PACK is almost the same as DEFINE-INTEGER-PACK though it will be\n;; suitable for the total bits in the range [63, 124].\n\n(defpackage :cp/integer-pack\n (:use :cl)\n (:export #:define-integer-pack #:define-cons-pack))\n(in-package :cp/integer-pack)\n\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-integer-pack (name &rest slot-descriptions)\n (assert slot-descriptions () \"~A has no slots.\" name)\n (let* ((packer-name (intern (%concat-name \"PACK\" name)))\n (unpacker-macro-name (intern (%concat-name \"WITH-UNPACKING\" name)))\n (total-size 0)\n (slots (loop with position = 0\n for (slot-name slot-size) in slot-descriptions\n collect (progn (check-type slot-name symbol)\n (check-type slot-size (integer 1))\n (list slot-name slot-size position))\n do (incf position slot-size)\n finally (setq total-size position)))\n (revslots (reverse slots))\n (new-value (gensym \"NEW-VALUE\"))\n (tmp (gensym)))\n `(progn\n (deftype ,name () '(unsigned-byte ,total-size))\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-name slot-size slot-position) in slots\n for accessor-name = (intern (%concat-name name slot-name))\n append `((declaim (inline ,accessor-name\n (setf ,accessor-name)))\n (defun ,accessor-name (,name)\n (declare (type ,name ,name))\n (ldb (byte ,slot-size ,slot-position) ,name))\n (defun (setf ,accessor-name) (,new-value ,name)\n (declare (type ,name ,name))\n (setf (ldb (byte ,slot-size ,slot-position) ,name) ,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 _) in slots\n collect `(type (unsigned-byte ,slot-size) ,slot-name )))\n (let ((,tmp ,(caar revslots)))\n (declare (type (unsigned-byte ,total-size) ,tmp))\n ,@(loop for (slot-name slot-size _) in (cdr revslots)\n collect `(setq ,tmp (logxor ,slot-name\n (the (unsigned-byte ,total-size)\n (ash ,tmp ,slot-size)))))\n ,tmp))\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 (declare (type (unsigned-byte ,,total-size) ,',tmp))\n (let* ,(loop for var in vars\n for rest on ',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) ,',tmp))\n ,@(when (cdr rest)\n `((setq ,',tmp (ash ,',tmp ,(- slot-size))))))))\n ,@body))))))\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 violated: 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;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n(defpackage :cp/implicit-treap\n (:use :cl :cp/integer-pack)\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-left #:itreap-update #:itreap-reverse\n #:itreap-bisect-left #:itreap-bisect-right #:itreap-insort\n #:pack-node #:node-x))\n(in-package :cp/implicit-treap)\n\n;; Note:\n;; - An empty treap is NIL.\n\n(define-cons-pack node (x 62) (y 20) (z 20))\n\n(declaim (inline op))\n(defun op (node1 node2)\n \"Is a binary operator comprising a monoid.\"\n (with-unpacking-node (x1 y1 z1) node1\n (with-unpacking-node (x2 y2 z2) node2\n (pack-node (+ (the (unsigned-byte 60) (+ x1 x2))\n (* z1 y2))\n (+ y1 y2)\n (+ z1 z2)))))\n\n(sb-int:defconstant-eqx +op-identity+ (cons 0 0) #'equal\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. A is the current LAZY value\nand B is operand.\"\n (declare (bit a b))\n (logxor 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 (acc delta size)\n \"Is the operator to update ACCUMULATOR (and VALUE) based on LAZY value. ACC is\nthe current ACCUMULATOR value and X is the LAZY value. SIZE is the length of the\nspecified interval.\"\n (declare (ignorable size)\n (bit delta))\n (with-unpacking-node (x y z) acc\n (if (zerop delta)\n (pack-node x y z)\n (let ((l (+ y z)))\n (pack-node (- (ash (* l (- l 1)) -1) x) z y)))))\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 bit)\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 (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 (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 (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(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 the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of the elements in 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(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP 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 \"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;; (declaim (inline itreap-fold))\n;; (defun itreap-fold (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;; (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-left))\n(defun itreap-fold-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 deals with 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 (force-down itreap)\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 (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 (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;;; Utilities for sorted treap\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/implicit-treap :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/integer-pack :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-small ()\n (let* ((n (read))\n (q (read))\n (as (make-array n :element-type 'bit)))\n (declare (uint31 n q))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (_ q)\n (let ((type (read-fixnum))\n (l (- (read-fixnum) 1))\n (r (read-fixnum)))\n (ecase type\n (1 (loop for i from l below r\n do (setf (aref as i) (logxor 1 (aref as i)))))\n (2 (println (loop for i1 from l below r\n sum (loop for i2 from (+ i1 1) below r\n count (> (aref as i1) (aref as i2)))))))))))\n(defun main ()\n (let* ((n (read))\n (q (read))\n (inits (make-array n :element-type 'list)))\n (declare (uint31 n q))\n (dotimes (i n)\n (setf (aref inits i)\n (if (zerop (read-fixnum))\n (pack-node 0 1 0)\n (pack-node 0 0 1))))\n (let ((dp (make-itreap n :initial-contents inits)))\n (dotimes (_ q)\n (let ((type (read-fixnum))\n (l (- (read-fixnum) 1))\n (r (read-fixnum)))\n (ecase type\n (1 (setq dp (itreap-update dp 1 l r)))\n (2 (println (node-x (itreap-fold dp l r))))))))))\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*) function)\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'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 (funcall (or function #'main))))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (funcall (or function #'main))))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (funcall (or function #'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(defun gen-str ()\n (with-output-to-string (out)\n (format out \"5 10~%\")\n (dotimes (_ 5)\n (println (random 2) out))\n (dotimes (_ 10)\n (let ((l (+ 1 (random 5)))\n (r (+ 1 (random 5))))\n (when (> l r)\n (rotatef l r))\n (format out \"~D ~D ~D~%\"\n (+ 1 (random 2))\n l r)))))\n\n(defun compare ()\n (loop for input = (gen-str)\n for out1 = (with-output-to-string (*standard-output*)\n (with-input-from-string (*standard-input* input)\n (main)))\n for out2 = (with-output-to-string (*standard-output*)\n (with-input-from-string (*standard-input* input)\n (main-small)))\n unless (equal out1 out2)\n do (return input)))\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\n0\n1\n\"\n (run \"5 5\n0 1 0 0 1\n2 1 5\n1 3 4\n2 2 5\n1 1 3\n2 1 2\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1599773851, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02569.html", "problem_id": "p02569", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02569/input.txt", "sample_output_relpath": "derived/input_output/data/p02569/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02569/Lisp/s179915224.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s179915224", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n0\n1\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/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;; DEFINE-INTEGER-PACK and DEFINE-CONS-PACK are so to say poor man's variants of\n;; DEFSTRUCT. Both \"structures\" can only have slots of fixed unsigned\n;; bytes. DEFINE-INTEGER-PACK handles the concatenated slots as UNSIGNED-BYTE\n;; and DEFINE-CONS-PACK handles them as (CONS (UNSIGNED-BYTE 62) (UNSIGNED-BYTE\n;; 62)).\n\n;; Example:\n;; The following form defines the type NODE as (UNSIGNED-BYTE 9):\n;; (define-integer-pack node (slot1 3) (slot2 5) (slot3 1))\n;; This macro in addition defines relevant utilities: NODE-SLOT1, NODE-SLOT2,\n;; NODE-SLOT3, setters and getters, PACK-NODE, the constructor, and\n;; WITH-UNPACKING-NODE, the destructuring-bind-style macro.\n;; \n;; DEFINE-CONS-PACK is almost the same as DEFINE-INTEGER-PACK though it will be\n;; suitable for the total bits in the range [63, 124].\n\n(defpackage :cp/integer-pack\n (:use :cl)\n (:export #:define-integer-pack #:define-cons-pack))\n(in-package :cp/integer-pack)\n\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-integer-pack (name &rest slot-descriptions)\n (assert slot-descriptions () \"~A has no slots.\" name)\n (let* ((packer-name (intern (%concat-name \"PACK\" name)))\n (unpacker-macro-name (intern (%concat-name \"WITH-UNPACKING\" name)))\n (total-size 0)\n (slots (loop with position = 0\n for (slot-name slot-size) in slot-descriptions\n collect (progn (check-type slot-name symbol)\n (check-type slot-size (integer 1))\n (list slot-name slot-size position))\n do (incf position slot-size)\n finally (setq total-size position)))\n (revslots (reverse slots))\n (new-value (gensym \"NEW-VALUE\"))\n (tmp (gensym)))\n `(progn\n (deftype ,name () '(unsigned-byte ,total-size))\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-name slot-size slot-position) in slots\n for accessor-name = (intern (%concat-name name slot-name))\n append `((declaim (inline ,accessor-name\n (setf ,accessor-name)))\n (defun ,accessor-name (,name)\n (declare (type ,name ,name))\n (ldb (byte ,slot-size ,slot-position) ,name))\n (defun (setf ,accessor-name) (,new-value ,name)\n (declare (type ,name ,name))\n (setf (ldb (byte ,slot-size ,slot-position) ,name) ,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 _) in slots\n collect `(type (unsigned-byte ,slot-size) ,slot-name )))\n (let ((,tmp ,(caar revslots)))\n (declare (type (unsigned-byte ,total-size) ,tmp))\n ,@(loop for (slot-name slot-size _) in (cdr revslots)\n collect `(setq ,tmp (logxor ,slot-name\n (the (unsigned-byte ,total-size)\n (ash ,tmp ,slot-size)))))\n ,tmp))\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 (declare (type (unsigned-byte ,,total-size) ,',tmp))\n (let* ,(loop for var in vars\n for rest on ',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) ,',tmp))\n ,@(when (cdr rest)\n `((setq ,',tmp (ash ,',tmp ,(- slot-size))))))))\n ,@body))))))\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 violated: 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;;;\n;;; Implicit treap\n;;; (treap with implicit key)\n;;;\n\n(defpackage :cp/implicit-treap\n (:use :cl :cp/integer-pack)\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-left #:itreap-update #:itreap-reverse\n #:itreap-bisect-left #:itreap-bisect-right #:itreap-insort\n #:pack-node #:node-x))\n(in-package :cp/implicit-treap)\n\n;; Note:\n;; - An empty treap is NIL.\n\n(define-cons-pack node (x 62) (y 20) (z 20))\n\n(declaim (inline op))\n(defun op (node1 node2)\n \"Is a binary operator comprising a monoid.\"\n (with-unpacking-node (x1 y1 z1) node1\n (with-unpacking-node (x2 y2 z2) node2\n (pack-node (+ (the (unsigned-byte 60) (+ x1 x2))\n (* z1 y2))\n (+ y1 y2)\n (+ z1 z2)))))\n\n(sb-int:defconstant-eqx +op-identity+ (cons 0 0) #'equal\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. A is the current LAZY value\nand B is operand.\"\n (declare (bit a b))\n (logxor 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 (acc delta size)\n \"Is the operator to update ACCUMULATOR (and VALUE) based on LAZY value. ACC is\nthe current ACCUMULATOR value and X is the LAZY value. SIZE is the length of the\nspecified interval.\"\n (declare (ignorable size)\n (bit delta))\n (with-unpacking-node (x y z) acc\n (if (zerop delta)\n (pack-node x y z)\n (let ((l (+ y z)))\n (pack-node (- (ash (* l (- l 1)) -1) x) z y)))))\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 bit)\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 (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 (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 (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(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 the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of the elements in 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(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP 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 \"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;; (declaim (inline itreap-fold))\n;; (defun itreap-fold (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;; (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-left))\n(defun itreap-fold-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 deals with 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 (force-down itreap)\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 (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 (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;;; Utilities for sorted treap\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\n\n;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/implicit-treap :cl-user))\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/integer-pack :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-small ()\n (let* ((n (read))\n (q (read))\n (as (make-array n :element-type 'bit)))\n (declare (uint31 n q))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (_ q)\n (let ((type (read-fixnum))\n (l (- (read-fixnum) 1))\n (r (read-fixnum)))\n (ecase type\n (1 (loop for i from l below r\n do (setf (aref as i) (logxor 1 (aref as i)))))\n (2 (println (loop for i1 from l below r\n sum (loop for i2 from (+ i1 1) below r\n count (> (aref as i1) (aref as i2)))))))))))\n(defun main ()\n (let* ((n (read))\n (q (read))\n (inits (make-array n :element-type 'list)))\n (declare (uint31 n q))\n (dotimes (i n)\n (setf (aref inits i)\n (if (zerop (read-fixnum))\n (pack-node 0 1 0)\n (pack-node 0 0 1))))\n (let ((dp (make-itreap n :initial-contents inits)))\n (dotimes (_ q)\n (let ((type (read-fixnum))\n (l (- (read-fixnum) 1))\n (r (read-fixnum)))\n (ecase type\n (1 (setq dp (itreap-update dp 1 l r)))\n (2 (println (node-x (itreap-fold dp l r))))))))))\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*) function)\n \"THING := null | string | symbol | pathname\n\nnull: run #'MAIN using the text on clipboard as input.\nstring: run #'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 (funcall (or function #'main))))\n (string\n (with-input-from-string (*standard-input* (delete #\\Return thing))\n (funcall (or function #'main))))\n (symbol (5am:run! thing))\n (pathname\n (with-open-file (*standard-input* thing)\n (funcall (or function #'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(defun gen-str ()\n (with-output-to-string (out)\n (format out \"5 10~%\")\n (dotimes (_ 5)\n (println (random 2) out))\n (dotimes (_ 10)\n (let ((l (+ 1 (random 5)))\n (r (+ 1 (random 5))))\n (when (> l r)\n (rotatef l r))\n (format out \"~D ~D ~D~%\"\n (+ 1 (random 2))\n l r)))))\n\n(defun compare ()\n (loop for input = (gen-str)\n for out1 = (with-output-to-string (*standard-output*)\n (with-input-from-string (*standard-input* input)\n (main)))\n for out2 = (with-output-to-string (*standard-output*)\n (with-input-from-string (*standard-input* input)\n (main-small)))\n unless (equal out1 out2)\n do (return input)))\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\n0\n1\n\"\n (run \"5 5\n0 1 0 0 1\n2 1 5\n1 3 4\n2 2 5\n1 1 3\n2 1 2\n\" nil))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a binary array A=(A_1,A_2,\\cdots,A_N) of length N.\n\nProcess Q queries of the following types. The i-th query is represented by three integers T_i,L_i,R_i.\n\nT_i=1: Replace the value of A_j with 1-A_j for each L_i \\leq j \\leq R_i.\n\nT_i=2: Calculate the inversion(*) of the array A_{L_i},A_{L_i+1},\\cdots,A_{R_i}.\n\nNote:The inversion of the array x_1,x_2,\\cdots,x_k is the number of the pair of integers i,j with 1 \\leq i < j \\leq k, x_i > x_j.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq A_i \\leq 1\n\n1 \\leq Q \\leq 2 \\times 10^5\n\n1 \\leq T_i \\leq 2\n\n1 \\leq L_i \\leq R_i \\leq N\n\nAll values in Input are integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nA_1 A_2 \\cdots A_N\nT_1 L_1 R_1\nT_2 L_2 R_2\n\\vdots\nT_Q L_Q R_Q\n\nOutput\n\nFor each query with T_i=2, print the answer.\n\nSample Input 1\n\n5 5\n0 1 0 0 1\n2 1 5\n1 3 4\n2 2 5\n1 1 3\n2 1 2\n\nSample Output 1\n\n2\n0\n1\n\nFirst query: Print 2, which is the inversion of (A_1,A_2,A_3,A_4,A_5)=(0,1,0,0,1).\n\nSecond query: Replace the value of A_3 and A_4 with 1 and 1, respectively.\n\nThird query: Print 0, which is the inversion of (A_2,A_3,A_4,A_5)=(1,1,1,1).\n\nFourth query: Replace the value of A_1, A_2 and A_4 with 1, 0 and 0, respectively.\n\nFifth query: Print 1, which is the inversion of (A_1,A_2)=(1,0).", "sample_input": "5 5\n0 1 0 0 1\n2 1 5\n1 3 4\n2 2 5\n1 1 3\n2 1 2\n"}, "reference_outputs": ["2\n0\n1\n"], "source_document_id": "p02569", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a binary array A=(A_1,A_2,\\cdots,A_N) of length N.\n\nProcess Q queries of the following types. The i-th query is represented by three integers T_i,L_i,R_i.\n\nT_i=1: Replace the value of A_j with 1-A_j for each L_i \\leq j \\leq R_i.\n\nT_i=2: Calculate the inversion(*) of the array A_{L_i},A_{L_i+1},\\cdots,A_{R_i}.\n\nNote:The inversion of the array x_1,x_2,\\cdots,x_k is the number of the pair of integers i,j with 1 \\leq i < j \\leq k, x_i > x_j.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n0 \\leq A_i \\leq 1\n\n1 \\leq Q \\leq 2 \\times 10^5\n\n1 \\leq T_i \\leq 2\n\n1 \\leq L_i \\leq R_i \\leq N\n\nAll values in Input are integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nA_1 A_2 \\cdots A_N\nT_1 L_1 R_1\nT_2 L_2 R_2\n\\vdots\nT_Q L_Q R_Q\n\nOutput\n\nFor each query with T_i=2, print the answer.\n\nSample Input 1\n\n5 5\n0 1 0 0 1\n2 1 5\n1 3 4\n2 2 5\n1 1 3\n2 1 2\n\nSample Output 1\n\n2\n0\n1\n\nFirst query: Print 2, which is the inversion of (A_1,A_2,A_3,A_4,A_5)=(0,1,0,0,1).\n\nSecond query: Replace the value of A_3 and A_4 with 1 and 1, respectively.\n\nThird query: Print 0, which is the inversion of (A_2,A_3,A_4,A_5)=(1,1,1,1).\n\nFourth query: Replace the value of A_1, A_2 and A_4 with 1, 0 and 0, respectively.\n\nFifth query: Print 1, which is the inversion of (A_1,A_2)=(1,0).", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 41909, "cpu_time_ms": 1197, "memory_kb": 106052}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s370914934", "group_id": "codeNet:p02570", "input_text": "(let ((d (read))\n (t/ (read))\n (s (read)))\n (format t \"~A~%\" (if (>= (* t/ s) d)\n \"Yes\"\n \"No\")))\n", "language": "Lisp", "metadata": {"date": 1598727807, "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/s370914934.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s370914934", "user_id": "u607637432"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((d (read))\n (t/ (read))\n (s (read)))\n (format t \"~A~%\" (if (>= (* t/ s) d)\n \"Yes\"\n \"No\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 19, "memory_kb": 24176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s236615877", "group_id": "codeNet:p02573", "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;;; 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(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/disjoint-set :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (dset (make-disjoint-set n)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (ds-unite! dset a b)))\n (println\n (loop for i below n\n maximize (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;; 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 3\n1 2\n3 4\n5 1\n\" nil)))\n (it.bese.fiveam:is\n (equal \"4\n\"\n (run \"4 10\n1 2\n2 1\n1 2\n2 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\" nil)))\n (it.bese.fiveam:is\n (equal \"3\n\"\n (run \"10 4\n3 1\n4 1\n5 9\n2 6\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1598774226, "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/s236615877.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s236615877", "user_id": "u352600849"}, "prompt_components": {"gold_output": "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 (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;;; 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(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/disjoint-set :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (dset (make-disjoint-set n)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (ds-unite! dset a b)))\n (println\n (loop for i below n\n maximize (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;; 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 3\n1 2\n3 4\n5 1\n\" nil)))\n (it.bese.fiveam:is\n (equal \"4\n\"\n (run \"4 10\n1 2\n2 1\n1 2\n2 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\" nil)))\n (it.bese.fiveam:is\n (equal \"3\n\"\n (run \"10 4\n3 1\n4 1\n5 9\n2 6\n\" nil))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6926, "cpu_time_ms": 65, "memory_kb": 27036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s894984296", "group_id": "codeNet:p02573", "input_text": "(let* ((n (read))\n (m (read))\n (g (make-array (list (1+ n)) :initial-element nil))\n (num (make-array (list (1+ n)) :initial-element 1)))\n (loop :for _ :from 1 :to m\n :for a := (read)\n :for b := (read)\n :do (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 ;; do nothing\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 (format t \"~A~%\" (loop :for i :from 1 :to n\n :maximize (aref num i))))\n", "language": "Lisp", "metadata": {"date": 1598729293, "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/s894984296.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s894984296", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (g (make-array (list (1+ n)) :initial-element nil))\n (num (make-array (list (1+ n)) :initial-element 1)))\n (loop :for _ :from 1 :to m\n :for a := (read)\n :for b := (read)\n :do (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 ;; do nothing\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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 867, "cpu_time_ms": 406, "memory_kb": 80472}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s649841349", "group_id": "codeNet:p02575", "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\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;;;\n;;; Treap with explicit key\n;;; Virtually it works like std::map, std::multiset, or java.util.TreeMap.\n;;;\n\n(defpackage :cp/explicit-treap\n (:use :cl)\n (:export #:treap #:treap-p #:treap-key #:treap-accumulator\n #:treap-split #:treap-insert #:treap-merge #:treap-delete\n #:treap-ensure-key #:treap-unite #:treap-map #:do-treap\n #:make-treap #:treap-fold #:treap-update #:treap-ref\n #:treap-first #:treap-last #:treap-find\n #:treap-bisect-left #:treap-bisect-right #:treap-bisect-left-1 #:treap-bisect-right-1\n #:treap-fold-bisect #:treap-fold-bisect-from-end))\n(in-package :cp/explicit-treap)\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\n;;\n;; (treap-ensure-key 1 :if-exists #'1+)\n;;\n;; instead of TREAP-INSERT.\n\n;; TODO & NOTE: insufficient tests\n;; TODO: introduce abstraction by macro\n\n(declaim (inline op))\n(defun op (x y)\n \"Is the operator comprising a monoid\"\n (declare ((integer 0 #.most-positive-fixnum) x y))\n (min x y))\n\n(defconstant +op-identity+ most-positive-fixnum\n \"identity element w.r.t. OP\")\n\n(defstruct (treap (:constructor %make-treap (key priority value &key left right (accumulator value)))\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 (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 \"Returns the key of the (nullable) TREAP.\"\n (and treap (%treap-key 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 (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 (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (treap key &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 #.cl-user::opt\n (function order)\n ((or null treap) treap))\n (if (null treap)\n (values nil nil)\n (progn\n (if (funcall order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split (%treap-right treap) key :order order)\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 :order order)\n (setf (%treap-left treap) right)\n (force-up treap)\n (values left treap))))))\n\n(declaim (inline treap-insert))\n(defun treap-insert (treap key value &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 (node treap)\n (declare (treap node))\n (unless treap (return-from recur node))\n (if (> (%treap-priority node) (%treap-priority treap))\n (progn\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split treap (%treap-key node) :order order))\n (force-up node)\n node)\n (progn\n (if (funcall 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-up treap)\n treap))))\n (recur (%make-treap key (random most-positive-fixnum) value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (treap key value &key (order #'<) 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 already contains KEY, TREAP-ENSURE-KEY\nupdates the value by the function instead of overwriting it with VALUE.\"\n (declare (function order)\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 (cond ((funcall order key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n (force-up treap)\n t))\n ((funcall order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n (force-up treap)\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n (force-up treap)\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert treap key value :order order))))\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.\"\n (declare #.cl-user::opt\n ((or null treap) left right))\n (cond ((null left) (when right (force-up right)) right)\n ((null right) (when left (force-up left)) left)\n (t\n (if (> (%treap-priority left) (%treap-priority right))\n (progn\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (force-up right)\n right)))))\n\n(defun treap-delete (treap key &key (order #'<))\n \"Destructively deletes the KEY in TREAP and returns the resultant\ntreap. Returns the unmodified TREAP If KEY doesn't exist. You cannot rely on the\nside effect. Use the returned value.\n\n (Note that this function deletes at most one node even if duplicated keys\nexist.)\"\n (declare ((or null treap) treap)\n (function order))\n (when treap\n (cond ((funcall order key (%treap-key treap))\n (setf (%treap-left treap)\n (treap-delete (%treap-left treap) key :order order))\n (force-up treap)\n treap)\n ((funcall order (%treap-key treap) key)\n (setf (%treap-right treap)\n (treap-delete (%treap-right treap) key :order order))\n (force-up treap)\n treap)\n (t\n (treap-merge (%treap-left treap) (%treap-right 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) (when r (force-up r)) r)\n ((null r) (when l (force-up l)) l)\n (t (when (< (%treap-priority l) (%treap-priority r))\n (rotatef l r))\n (multiple-value-bind (lchild rchild)\n (treap-split r (%treap-key l) :order order)\n (setf (%treap-left l) (recur (%treap-left l) lchild)\n (%treap-right l) (recur (%treap-right l) rchild))\n (force-up l)\n l)))))\n (recur treap1 treap2)))\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 two arguments: KEY and VALUE.\"\n (labels ((recur (treap)\n (when treap\n (recur (%treap-left treap))\n (funcall function (%treap-key treap) (%treap-value treap))\n (recur (%treap-right treap))\n (force-up 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 value)\n (if init\n (setf init nil)\n (write-char #\\ stream))\n (format stream \"<~A . ~A>\" key value))\n object))))\n\n(defmacro do-treap ((key-var value-var treap &optional result) &body body)\n \"Successively binds the key and value of INODE[0], ..., INODE[SIZE-1] to\nKEY-VAR and VALUE-VAR and executes BODY.\"\n `(block nil\n (treap-map (lambda (,key-var ,value-var) ,@body) ,treap)\n ,result))\n\n;; This function takes O(nlog(n)) time. It is just for debugging.\n(defun treap (order &rest key-and-values)\n \"Takes cons cells in the form of ( . ).\"\n (loop with res = nil\n for (key . value) in key-and-values\n do (setf res (treap-insert res key value :order order))\n finally (return res)))\n\n;; Reference: https://cp-algorithms.com/data_structures/treap.html\n;; TODO: take a sorted list as the argument\n(declaim (inline make-treap))\n(defun make-treap (sorted-vector)\n \"Makes a treap using each key of the given SORTED-VECTOR in O(n) time. Note\nthat this function doesn't check if the SORTED-VECTOR is actually sorted\nw.r.t. your intended order. The values are filled with the identity element.\"\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 +op-identity+)))\n (setf (%treap-left node) (build l mid))\n (setf (%treap-right node) (build (+ mid 1) r))\n (heapify node)\n node))))\n (build 0 (length sorted-vector))))\n\n(declaim (inline treap-ref))\n(defun treap-ref (treap key &key (order #'<))\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (when treap\n (prog1 (cond ((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 (%treap-value treap)))\n (force-up treap)))))\n (recur treap)))\n\n(declaim (inline (setf treap-ref)))\n(defun (setf treap-ref) (new-value treap key &key (order #'<))\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (when treap\n (prog1 (cond ((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 (setf (%treap-value treap) new-value)))\n (force-up treap)))))\n (recur treap)))\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;;;\n;;; Bisection search w.r.t. key\n;;;\n\n;; NOTE: These functions intentionally don't return the assigned value. That is\n;; for efficiency, because thereby they don't need to execute lazy propagation.\n\n(defun treap-find (treap key &key (order #'<))\n \"Finds the key that satisfies (AND (NOT (FUNCALL ORDER KEY (%TREAP-KEY\n))) (NOT (FUNCALL ORDER (%TREAP-KEY ) KEY))) and returns\nKEY if it exists, otherwise returns NIL.\"\n (declare (optimize (speed 3))\n (function order)\n ((or null treap) treap))\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (treap-find (%treap-left treap) key :order order))\n ((funcall order (%treap-key treap) key)\n (treap-find (%treap-right treap) key :order order))\n (t key)))\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-left))\n(defun treap-bisect-right (treap key &key (order #'<))\n \"Returns the smallest key larger than KEY. Returns NIL if KEY is equal to or\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 key (%treap-key treap))\n (or (recur (%treap-left treap))\n treap)\n (recur (%treap-right treap)))))\n (treap-key (recur treap))))\n\n(declaim (inline treap-bisect-left-1))\n(defun treap-bisect-left-1 (treap key &key (order #'<))\n \"Returns the largest key smaller than KEY. Returns NIL if KEY is equal to or\nsmaller 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 (or (recur (%treap-right treap))\n treap)\n (recur (%treap-left 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 (unless treap (return-from recur nil))\n (if (funcall order key (%treap-key treap))\n (recur (%treap-left treap))\n (or (recur (%treap-right treap))\n treap))))\n (treap-key (recur treap))))\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/explicit-treap :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* ((h (read))\n (w (read))\n treap)\n (declare (uint31 h w))\n (dotimes (i w)\n (setq treap (treap-insert treap i 0)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (i h)\n (let ((a (- (read-fixnum) 1))\n (b (read-fixnum))\n (hi-dist most-positive-fixnum))\n (declare (uint62 hi-dist))\n (multiple-value-bind (treap-left treap-rest) (treap-split treap a)\n (multiple-value-bind (treap-mid treap-right) (treap-split treap-rest b)\n (treap-map (lambda (col cumul)\n (let ((hi-delta (- b col)))\n (minf hi-dist (+ cumul hi-delta))))\n treap-mid)\n (setq treap (treap-merge treap-left treap-right))\n (when (and (< b w) (< hi-dist most-positive-fixnum))\n (setq treap (treap-ensure-key\n treap b hi-dist\n :if-exists (lambda (value) (min value hi-dist)))))))\n (let ((res (treap-accumulator treap)))\n (println (if (>= res most-positive-fixnum)\n -1\n (+ i 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;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"1\n3\n6\n-1\n\"\n (run \"4 4\n2 4\n1 1\n2 3\n2 4\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1598780477, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02575.html", "problem_id": "p02575", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02575/input.txt", "sample_output_relpath": "derived/input_output/data/p02575/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02575/Lisp/s649841349.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s649841349", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n3\n6\n-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\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;;;\n;;; Treap with explicit key\n;;; Virtually it works like std::map, std::multiset, or java.util.TreeMap.\n;;;\n\n(defpackage :cp/explicit-treap\n (:use :cl)\n (:export #:treap #:treap-p #:treap-key #:treap-accumulator\n #:treap-split #:treap-insert #:treap-merge #:treap-delete\n #:treap-ensure-key #:treap-unite #:treap-map #:do-treap\n #:make-treap #:treap-fold #:treap-update #:treap-ref\n #:treap-first #:treap-last #:treap-find\n #:treap-bisect-left #:treap-bisect-right #:treap-bisect-left-1 #:treap-bisect-right-1\n #:treap-fold-bisect #:treap-fold-bisect-from-end))\n(in-package :cp/explicit-treap)\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\n;;\n;; (treap-ensure-key 1 :if-exists #'1+)\n;;\n;; instead of TREAP-INSERT.\n\n;; TODO & NOTE: insufficient tests\n;; TODO: introduce abstraction by macro\n\n(declaim (inline op))\n(defun op (x y)\n \"Is the operator comprising a monoid\"\n (declare ((integer 0 #.most-positive-fixnum) x y))\n (min x y))\n\n(defconstant +op-identity+ most-positive-fixnum\n \"identity element w.r.t. OP\")\n\n(defstruct (treap (:constructor %make-treap (key priority value &key left right (accumulator value)))\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 (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 \"Returns the key of the (nullable) TREAP.\"\n (and treap (%treap-key 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 (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 (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (treap key &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 #.cl-user::opt\n (function order)\n ((or null treap) treap))\n (if (null treap)\n (values nil nil)\n (progn\n (if (funcall order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split (%treap-right treap) key :order order)\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 :order order)\n (setf (%treap-left treap) right)\n (force-up treap)\n (values left treap))))))\n\n(declaim (inline treap-insert))\n(defun treap-insert (treap key value &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 (node treap)\n (declare (treap node))\n (unless treap (return-from recur node))\n (if (> (%treap-priority node) (%treap-priority treap))\n (progn\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split treap (%treap-key node) :order order))\n (force-up node)\n node)\n (progn\n (if (funcall 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-up treap)\n treap))))\n (recur (%make-treap key (random most-positive-fixnum) value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (treap key value &key (order #'<) 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 already contains KEY, TREAP-ENSURE-KEY\nupdates the value by the function instead of overwriting it with VALUE.\"\n (declare (function order)\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 (cond ((funcall order key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n (force-up treap)\n t))\n ((funcall order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n (force-up treap)\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n (force-up treap)\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert treap key value :order order))))\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.\"\n (declare #.cl-user::opt\n ((or null treap) left right))\n (cond ((null left) (when right (force-up right)) right)\n ((null right) (when left (force-up left)) left)\n (t\n (if (> (%treap-priority left) (%treap-priority right))\n (progn\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (force-up right)\n right)))))\n\n(defun treap-delete (treap key &key (order #'<))\n \"Destructively deletes the KEY in TREAP and returns the resultant\ntreap. Returns the unmodified TREAP If KEY doesn't exist. You cannot rely on the\nside effect. Use the returned value.\n\n (Note that this function deletes at most one node even if duplicated keys\nexist.)\"\n (declare ((or null treap) treap)\n (function order))\n (when treap\n (cond ((funcall order key (%treap-key treap))\n (setf (%treap-left treap)\n (treap-delete (%treap-left treap) key :order order))\n (force-up treap)\n treap)\n ((funcall order (%treap-key treap) key)\n (setf (%treap-right treap)\n (treap-delete (%treap-right treap) key :order order))\n (force-up treap)\n treap)\n (t\n (treap-merge (%treap-left treap) (%treap-right 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) (when r (force-up r)) r)\n ((null r) (when l (force-up l)) l)\n (t (when (< (%treap-priority l) (%treap-priority r))\n (rotatef l r))\n (multiple-value-bind (lchild rchild)\n (treap-split r (%treap-key l) :order order)\n (setf (%treap-left l) (recur (%treap-left l) lchild)\n (%treap-right l) (recur (%treap-right l) rchild))\n (force-up l)\n l)))))\n (recur treap1 treap2)))\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 two arguments: KEY and VALUE.\"\n (labels ((recur (treap)\n (when treap\n (recur (%treap-left treap))\n (funcall function (%treap-key treap) (%treap-value treap))\n (recur (%treap-right treap))\n (force-up 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 value)\n (if init\n (setf init nil)\n (write-char #\\ stream))\n (format stream \"<~A . ~A>\" key value))\n object))))\n\n(defmacro do-treap ((key-var value-var treap &optional result) &body body)\n \"Successively binds the key and value of INODE[0], ..., INODE[SIZE-1] to\nKEY-VAR and VALUE-VAR and executes BODY.\"\n `(block nil\n (treap-map (lambda (,key-var ,value-var) ,@body) ,treap)\n ,result))\n\n;; This function takes O(nlog(n)) time. It is just for debugging.\n(defun treap (order &rest key-and-values)\n \"Takes cons cells in the form of ( . ).\"\n (loop with res = nil\n for (key . value) in key-and-values\n do (setf res (treap-insert res key value :order order))\n finally (return res)))\n\n;; Reference: https://cp-algorithms.com/data_structures/treap.html\n;; TODO: take a sorted list as the argument\n(declaim (inline make-treap))\n(defun make-treap (sorted-vector)\n \"Makes a treap using each key of the given SORTED-VECTOR in O(n) time. Note\nthat this function doesn't check if the SORTED-VECTOR is actually sorted\nw.r.t. your intended order. The values are filled with the identity element.\"\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 +op-identity+)))\n (setf (%treap-left node) (build l mid))\n (setf (%treap-right node) (build (+ mid 1) r))\n (heapify node)\n node))))\n (build 0 (length sorted-vector))))\n\n(declaim (inline treap-ref))\n(defun treap-ref (treap key &key (order #'<))\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (when treap\n (prog1 (cond ((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 (%treap-value treap)))\n (force-up treap)))))\n (recur treap)))\n\n(declaim (inline (setf treap-ref)))\n(defun (setf treap-ref) (new-value treap key &key (order #'<))\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (when treap\n (prog1 (cond ((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 (setf (%treap-value treap) new-value)))\n (force-up treap)))))\n (recur treap)))\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;;;\n;;; Bisection search w.r.t. key\n;;;\n\n;; NOTE: These functions intentionally don't return the assigned value. That is\n;; for efficiency, because thereby they don't need to execute lazy propagation.\n\n(defun treap-find (treap key &key (order #'<))\n \"Finds the key that satisfies (AND (NOT (FUNCALL ORDER KEY (%TREAP-KEY\n))) (NOT (FUNCALL ORDER (%TREAP-KEY ) KEY))) and returns\nKEY if it exists, otherwise returns NIL.\"\n (declare (optimize (speed 3))\n (function order)\n ((or null treap) treap))\n (cond ((null treap) nil)\n ((funcall order key (%treap-key treap))\n (treap-find (%treap-left treap) key :order order))\n ((funcall order (%treap-key treap) key)\n (treap-find (%treap-right treap) key :order order))\n (t key)))\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-left))\n(defun treap-bisect-right (treap key &key (order #'<))\n \"Returns the smallest key larger than KEY. Returns NIL if KEY is equal to or\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 key (%treap-key treap))\n (or (recur (%treap-left treap))\n treap)\n (recur (%treap-right treap)))))\n (treap-key (recur treap))))\n\n(declaim (inline treap-bisect-left-1))\n(defun treap-bisect-left-1 (treap key &key (order #'<))\n \"Returns the largest key smaller than KEY. Returns NIL if KEY is equal to or\nsmaller 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 (or (recur (%treap-right treap))\n treap)\n (recur (%treap-left 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 (unless treap (return-from recur nil))\n (if (funcall order key (%treap-key treap))\n (recur (%treap-left treap))\n (or (recur (%treap-right treap))\n treap))))\n (treap-key (recur treap))))\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/explicit-treap :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* ((h (read))\n (w (read))\n treap)\n (declare (uint31 h w))\n (dotimes (i w)\n (setq treap (treap-insert treap i 0)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (i h)\n (let ((a (- (read-fixnum) 1))\n (b (read-fixnum))\n (hi-dist most-positive-fixnum))\n (declare (uint62 hi-dist))\n (multiple-value-bind (treap-left treap-rest) (treap-split treap a)\n (multiple-value-bind (treap-mid treap-right) (treap-split treap-rest b)\n (treap-map (lambda (col cumul)\n (let ((hi-delta (- b col)))\n (minf hi-dist (+ cumul hi-delta))))\n treap-mid)\n (setq treap (treap-merge treap-left treap-right))\n (when (and (< b w) (< hi-dist most-positive-fixnum))\n (setq treap (treap-ensure-key\n treap b hi-dist\n :if-exists (lambda (value) (min value hi-dist)))))))\n (let ((res (treap-accumulator treap)))\n (println (if (>= res most-positive-fixnum)\n -1\n (+ i 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;; To run: (5am:run! :sample)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (equal \"1\n3\n6\n-1\n\"\n (run \"4 4\n2 4\n1 1\n2 3\n2 4\n\" nil))))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere is a grid of squares with H+1 horizontal rows and W vertical columns.\n\nYou will start at one of the squares in the top row and repeat moving one square right or down. However, for each integer i from 1 through H, you cannot move down from the A_i-th, (A_i + 1)-th, \\ldots, B_i-th squares from the left in the i-th row from the top.\n\nFor each integer k from 1 through H, find the minimum number of moves needed to reach one of the squares in the (k+1)-th row from the top. (The starting square can be chosen individually for each case.) If, starting from any square in the top row, none of the squares in the (k+1)-th row can be reached, print -1 instead.\n\nConstraints\n\n1 \\leq H,W \\leq 2\\times 10^5\n\n1 \\leq A_i \\leq B_i \\leq W\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nA_1 B_1\nA_2 B_2\n:\nA_H B_H\n\nOutput\n\nPrint H lines. The i-th line should contain the answer for the case k=i.\n\nSample Input 1\n\n4 4\n2 4\n1 1\n2 3\n2 4\n\nSample Output 1\n\n1\n3\n6\n-1\n\nLet (i,j) denote the square at the i-th row from the top and j-th column from the left.\n\nFor k=1, we need one move such as (1,1) → (2,1).\n\nFor k=2, we need three moves such as (1,1) → (2,1) → (2,2) → (3,2).\n\nFor k=3, we need six moves such as (1,1) → (2,1) → (2,2) → (3,2) → (3,3) → (3,4) → (4,4).\n\nFor k=4, it is impossible to reach any square in the fifth row from the top.", "sample_input": "4 4\n2 4\n1 1\n2 3\n2 4\n"}, "reference_outputs": ["1\n3\n6\n-1\n"], "source_document_id": "p02575", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere is a grid of squares with H+1 horizontal rows and W vertical columns.\n\nYou will start at one of the squares in the top row and repeat moving one square right or down. However, for each integer i from 1 through H, you cannot move down from the A_i-th, (A_i + 1)-th, \\ldots, B_i-th squares from the left in the i-th row from the top.\n\nFor each integer k from 1 through H, find the minimum number of moves needed to reach one of the squares in the (k+1)-th row from the top. (The starting square can be chosen individually for each case.) If, starting from any square in the top row, none of the squares in the (k+1)-th row can be reached, print -1 instead.\n\nConstraints\n\n1 \\leq H,W \\leq 2\\times 10^5\n\n1 \\leq A_i \\leq B_i \\leq W\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nA_1 B_1\nA_2 B_2\n:\nA_H B_H\n\nOutput\n\nPrint H lines. The i-th line should contain the answer for the case k=i.\n\nSample Input 1\n\n4 4\n2 4\n1 1\n2 3\n2 4\n\nSample Output 1\n\n1\n3\n6\n-1\n\nLet (i,j) denote the square at the i-th row from the top and j-th column from the left.\n\nFor k=1, we need one move such as (1,1) → (2,1).\n\nFor k=2, we need three moves such as (1,1) → (2,1) → (2,2) → (3,2).\n\nFor k=3, we need six moves such as (1,1) → (2,1) → (2,2) → (3,2) → (3,3) → (3,4) → (4,4).\n\nFor k=4, it is impossible to reach any square in the fifth row from the top.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 22830, "cpu_time_ms": 256, "memory_kb": 44868}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s740463924", "group_id": "codeNet:p02576", "input_text": "(LET ((N (READ))\n (X (READ))\n (TIME (READ)))\n (PRINC\n (LOOP FOR R FROM N ABOVE 0 BY X\n\tSUM TIME)))", "language": "Lisp", "metadata": {"date": 1598436178, "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/s740463924.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s740463924", "user_id": "u756033787"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(LET ((N (READ))\n (X (READ))\n (TIME (READ)))\n (PRINC\n (LOOP FOR R FROM N ABOVE 0 BY X\n\tSUM TIME)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 24480}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s500847572", "group_id": "codeNet:p02577", "input_text": "(defun parse-int-ex (n)\n (cond ((upper-case-p n) (- (char-code n) 55))\n ((lower-case-p n) (- (char-code n) 87))\n (t (- (char-code n) 48))))\n(let* ((n (read-line)))\n (if (= 0 (mod (reduce #'+ (map 'list #'parse-int-ex n)) 9)) (princ \"Yes\") (princ \"No\")))\n", "language": "Lisp", "metadata": {"date": 1598937083, "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/s500847572.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s500847572", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun parse-int-ex (n)\n (cond ((upper-case-p n) (- (char-code n) 55))\n ((lower-case-p n) (- (char-code n) 87))\n (t (- (char-code n) 48))))\n(let* ((n (read-line)))\n (if (= 0 (mod (reduce #'+ (map 'list #'parse-int-ex n)) 9)) (princ \"Yes\") (princ \"No\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 270, "cpu_time_ms": 34, "memory_kb": 30108}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s260433498", "group_id": "codeNet:p02577", "input_text": "(if (mod (read) 9) (princ \"Yes\") (princ \"No\"))", "language": "Lisp", "metadata": {"date": 1598936624, "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/s260433498.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s260433498", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(if (mod (read) 9) (princ \"Yes\") (princ \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 406, "memory_kb": 113076}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s794959347", "group_id": "codeNet:p02577", "input_text": "(if (zerop (mod (parse-integer (read)) 9))\n (princ \"Yes\")\n (princ \"No\"))\n(fresh-line)", "language": "Lisp", "metadata": {"date": 1598198782, "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/s794959347.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s794959347", "user_id": "u735896835"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(if (zerop (mod (parse-integer (read)) 9))\n (princ \"Yes\")\n (princ \"No\"))\n(fresh-line)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 1186, "memory_kb": 115396}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s188880599", "group_id": "codeNet:p02578", "input_text": "(let* ((n (read))\n (lst (loop :repeat n :collect (read))))\n (princ (loop :for k :in lst\n :with mx := 0\n :if (< k mx)\n :sum (- mx k)\n :else :do (setf mx k))))", "language": "Lisp", "metadata": {"date": 1598944180, "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/s188880599.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s188880599", "user_id": "u610490393"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let* ((n (read))\n (lst (loop :repeat n :collect (read))))\n (princ (loop :for k :in lst\n :with mx := 0\n :if (< k mx)\n :sum (- mx k)\n :else :do (setf mx k))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 222, "cpu_time_ms": 255, "memory_kb": 80036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s031085262", "group_id": "codeNet:p02578", "input_text": "(defun read-n-num (n)\n (let ((result)) (dotimes (x n (nreverse result)) (push (read) result))))\n\n(format t \"~d~%\" (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 ))\n", "language": "Lisp", "metadata": {"date": 1598127184, "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/s031085262.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s031085262", "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\n(format t \"~d~%\" (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 ))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 472, "cpu_time_ms": 276, "memory_kb": 79860}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s942478264", "group_id": "codeNet:p02579", "input_text": "(defun make-queue () (cons nil nil))\n(defun enqueue (item queue)\n (let ((cell (list item)))\n (if (cdr queue)\n (setf (cdr (cdr queue)) cell)\n (setf (car queue) cell))\n (setf (cdr queue) cell)))\n(defun dequeue (queue)\n (when (car queue)\n (prog1 (pop (car queue))\n (unless (car queue)\n (setf (cdr queue) nil)))))\n\n\n(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 :do (loop :for j :from 1 :to w\n :if (char= (read-char) #\\#)\n :do (setf (aref f i j) nil))\n :do (read-char))\n ;\n (defun check (q)\n (let ((c (make-queue)))\n (loop :while (car q)\n :for pos := (dequeue 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 (- 2 i)) :to (min h (+ 2 i))\n :do (loop :for x :from (max 1 (- 2 j)) :to (min w (+ 2 j))\n :do (when (aref f y x)\n (let ((d (+ (abs (- i y)) (abs (- j x)))))\n (if (= 1 d)\n (enqueue (cons y x) q)\n (enqueue (cons y x) c))))))))\n c))\n ;\n (let ((q (make-queue))\n (cost 0))\n (enqueue (cons ci cj) q)\n (loop :named main\n :while (car q)\n :do (progn\n (setf q (check q))\n (when (null (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": 1598826916, "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/s942478264.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s942478264", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun make-queue () (cons nil nil))\n(defun enqueue (item queue)\n (let ((cell (list item)))\n (if (cdr queue)\n (setf (cdr (cdr queue)) cell)\n (setf (car queue) cell))\n (setf (cdr queue) cell)))\n(defun dequeue (queue)\n (when (car queue)\n (prog1 (pop (car queue))\n (unless (car queue)\n (setf (cdr queue) nil)))))\n\n\n(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 :do (loop :for j :from 1 :to w\n :if (char= (read-char) #\\#)\n :do (setf (aref f i j) nil))\n :do (read-char))\n ;\n (defun check (q)\n (let ((c (make-queue)))\n (loop :while (car q)\n :for pos := (dequeue 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 (- 2 i)) :to (min h (+ 2 i))\n :do (loop :for x :from (max 1 (- 2 j)) :to (min w (+ 2 j))\n :do (when (aref f y x)\n (let ((d (+ (abs (- i y)) (abs (- j x)))))\n (if (= 1 d)\n (enqueue (cons y x) q)\n (enqueue (cons y x) c))))))))\n c))\n ;\n (let ((q (make-queue))\n (cost 0))\n (enqueue (cons ci cj) q)\n (loop :named main\n :while (car q)\n :do (progn\n (setf q (check q))\n (when (null (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2012, "cpu_time_ms": 2217, "memory_kb": 486788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s278989708", "group_id": "codeNet:p02579", "input_text": "(defstruct queue (entrance nil) (exit nil))\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(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(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 nil))\n (s (make-array (list (1+ h)) :initial-element \"\")))\n ;\n (loop :for i :from 1 :to h\n :do (setf (aref s i) (read-line)))\n (defun not-yet (i j)\n (and (<= 1 i h) (<= 1 j w) (char= (char (aref s i) (1- j)) #\\.) (null (aref f i j))))\n ;\n (defun check (q cost)\n (let ((c (make-queue))\n (d nil))\n (loop :for pos := (dequeue q)\n :while pos\n :for i := (car pos)\n :for j := (cdr pos)\n :if (not-yet i j)\n :do (progn\n (setf (aref f i j) cost)\n (when (and (= i di) (= j dj))\n (format t \"~A~%\" cost)\n (return-from check nil))\n (push (cons i j) d)\n (if (not-yet (+ i 1) j) (enqueue (cons (+ i 1) j) q))\n (if (not-yet i (+ j 1)) (enqueue (cons i (+ j 1)) q))\n (if (not-yet (+ i 1) j) (enqueue (cons (- i 1) j) q))\n (if (not-yet i (- j 1)) (enqueue (cons i (- j 1)) q))))\n (loop :for pos :in d\n :for i := (car pos)\n :for j := (cdr pos)\n :do (loop :for y :from (- 2 i) :to (+ 2 i)\n :do (loop :for x :from (- 2 j) :to (+ 2 j)\n :if (and (not-yet y x) (< 1 (+ (abs (- i y)) (abs (- j x)))))\n :do (enqueue (cons y x) c))))\n c))\n ;\n (let ((q (make-queue))\n (cost 0))\n (enqueue (cons ci cj) q)\n (loop :named main\n :while (queue-exit q)\n :do (progn\n (setf q (check q cost))\n (when (aref f di dj)\n (return-from main))\n (incf cost))\n :finally (format t \"-1~%\"))))\n", "language": "Lisp", "metadata": {"date": 1598726062, "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/s278989708.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s278989708", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defstruct queue (entrance nil) (exit nil))\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(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(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 nil))\n (s (make-array (list (1+ h)) :initial-element \"\")))\n ;\n (loop :for i :from 1 :to h\n :do (setf (aref s i) (read-line)))\n (defun not-yet (i j)\n (and (<= 1 i h) (<= 1 j w) (char= (char (aref s i) (1- j)) #\\.) (null (aref f i j))))\n ;\n (defun check (q cost)\n (let ((c (make-queue))\n (d nil))\n (loop :for pos := (dequeue q)\n :while pos\n :for i := (car pos)\n :for j := (cdr pos)\n :if (not-yet i j)\n :do (progn\n (setf (aref f i j) cost)\n (when (and (= i di) (= j dj))\n (format t \"~A~%\" cost)\n (return-from check nil))\n (push (cons i j) d)\n (if (not-yet (+ i 1) j) (enqueue (cons (+ i 1) j) q))\n (if (not-yet i (+ j 1)) (enqueue (cons i (+ j 1)) q))\n (if (not-yet (+ i 1) j) (enqueue (cons (- i 1) j) q))\n (if (not-yet i (- j 1)) (enqueue (cons i (- j 1)) q))))\n (loop :for pos :in d\n :for i := (car pos)\n :for j := (cdr pos)\n :do (loop :for y :from (- 2 i) :to (+ 2 i)\n :do (loop :for x :from (- 2 j) :to (+ 2 j)\n :if (and (not-yet y x) (< 1 (+ (abs (- i y)) (abs (- j x)))))\n :do (enqueue (cons y x) c))))\n c))\n ;\n (let ((q (make-queue))\n (cost 0))\n (enqueue (cons ci cj) q)\n (loop :named main\n :while (queue-exit q)\n :do (progn\n (setf q (check q cost))\n (when (aref f di dj)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2323, "cpu_time_ms": 2216, "memory_kb": 280500}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s488003117", "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 (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 (loop for i2 from (max 0 (- i1 2)) to (min (- h 1) (+ i1 2))\n do (loop for j2 from (max 0 (- j1 2)) to (min (- w 1) (+ j1 2))\n for new-dist = (+ dist (calc-cost i2 j2))\n when (< new-dist (aref dists i2 j2))\n do (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 (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": 1598176482, "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/s488003117.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s488003117", "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 (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 (loop for i2 from (max 0 (- i1 2)) to (min (- h 1) (+ i1 2))\n do (loop for j2 from (max 0 (- j1 2)) to (min (- w 1) (+ j1 2))\n for new-dist = (+ dist (calc-cost i2 j2))\n when (< new-dist (aref dists i2 j2))\n do (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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7044, "cpu_time_ms": 223, "memory_kb": 67828}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s062342114", "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;;;\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 #:disjoint-set-p\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 (: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(defpackage :cp/adjacent-duplicates\n (:use :cl)\n (:export #:delete-adjacent-duplicates))\n(in-package :cp/adjacent-duplicates)\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;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/adjacent-duplicates :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-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 (graph (make-array (* h w) :element-type 'list :initial-element nil))\n (dset (make-disjoint-set (* h w))))\n (declare (uint16 h w ch cw dh dw))\n (labels ((encode (y x) (+ (* y w) x))\n (unite (y1 x1 y2 x2)\n (when (and (<= 0 y2 (- h 1))\n (<= 0 x2 (- w 1))\n (zerop (aref plan y2 x2)))\n (ds-unite! dset (encode y1 x1) (encode y2 x2)))))\n (dotimes (i h)\n (dotimes (j w (read-schar))\n (ecase (read-schar)\n (#\\.)\n (#\\# (setf (aref plan i j) 1)))))\n (dotimes (i h)\n (dotimes (j w)\n (when (zerop (aref plan i j))\n (unite i j i (+ j 1))\n (unite i j i (- j 1))\n (unite i j (+ i 1) j)\n (unite i j (- i 1) j))))\n (dotimes (i1 h)\n (dotimes (j1 w)\n (when (zerop (aref plan i1 j1))\n (let ((code1 (ds-root dset (encode i1 j1))))\n (loop for i2 from (max 0 (- i1 2)) to (min (- h 1) (+ i1 2))\n do (loop for j2 from (max 0 (- j1 2)) to (min (- w 1) (+ j1 2))\n for code2 = (ds-root dset (encode i2 j2))\n when (and (zerop (aref plan i2 j2))\n (/= code1 code2))\n do (push code2 (aref graph code1))))))))\n (dotimes (v (* h w))\n (setf (aref graph v) (delete-adjacent-duplicates\n (sort (the list (aref graph v))\n (lambda (x y)\n (declare (fixnum x y))\n (< x y)))\n :test #'eq)))\n (let ((que (make-queue))\n (dists (make-array (* h w) :element-type 'uint31 :initial-element +inf+))\n (s (ds-root dset (encode ch cw)))\n (g (ds-root dset (encode dh dw))))\n (enqueue s que)\n (setf (aref dists s) 0)\n (dbg s g)\n (loop until (queue-empty-p que)\n for v = (dequeue que)\n do (dolist (next (aref graph v))\n (when (= +inf+ (aref dists next))\n (setf (aref dists next) (+ (aref dists v) 1))\n (enqueue next que))))\n (println (if (= (aref dists g) +inf+)\n -1\n (aref dists g)))))))\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": 1598164279, "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/s062342114.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s062342114", "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;;;\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 #:disjoint-set-p\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 (: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(defpackage :cp/adjacent-duplicates\n (:use :cl)\n (:export #:delete-adjacent-duplicates))\n(in-package :cp/adjacent-duplicates)\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;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/adjacent-duplicates :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-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 (graph (make-array (* h w) :element-type 'list :initial-element nil))\n (dset (make-disjoint-set (* h w))))\n (declare (uint16 h w ch cw dh dw))\n (labels ((encode (y x) (+ (* y w) x))\n (unite (y1 x1 y2 x2)\n (when (and (<= 0 y2 (- h 1))\n (<= 0 x2 (- w 1))\n (zerop (aref plan y2 x2)))\n (ds-unite! dset (encode y1 x1) (encode y2 x2)))))\n (dotimes (i h)\n (dotimes (j w (read-schar))\n (ecase (read-schar)\n (#\\.)\n (#\\# (setf (aref plan i j) 1)))))\n (dotimes (i h)\n (dotimes (j w)\n (when (zerop (aref plan i j))\n (unite i j i (+ j 1))\n (unite i j i (- j 1))\n (unite i j (+ i 1) j)\n (unite i j (- i 1) j))))\n (dotimes (i1 h)\n (dotimes (j1 w)\n (when (zerop (aref plan i1 j1))\n (let ((code1 (ds-root dset (encode i1 j1))))\n (loop for i2 from (max 0 (- i1 2)) to (min (- h 1) (+ i1 2))\n do (loop for j2 from (max 0 (- j1 2)) to (min (- w 1) (+ j1 2))\n for code2 = (ds-root dset (encode i2 j2))\n when (and (zerop (aref plan i2 j2))\n (/= code1 code2))\n do (push code2 (aref graph code1))))))))\n (dotimes (v (* h w))\n (setf (aref graph v) (delete-adjacent-duplicates\n (sort (the list (aref graph v))\n (lambda (x y)\n (declare (fixnum x y))\n (< x y)))\n :test #'eq)))\n (let ((que (make-queue))\n (dists (make-array (* h w) :element-type 'uint31 :initial-element +inf+))\n (s (ds-root dset (encode ch cw)))\n (g (ds-root dset (encode dh dw))))\n (enqueue s que)\n (setf (aref dists s) 0)\n (dbg s g)\n (loop until (queue-empty-p que)\n for v = (dequeue que)\n do (dolist (next (aref graph v))\n (when (= +inf+ (aref dists next))\n (setf (aref dists next) (+ (aref dists v) 1))\n (enqueue next que))))\n (println (if (= (aref dists g) +inf+)\n -1\n (aref dists g)))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11362, "cpu_time_ms": 468, "memory_kb": 99328}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s644659597", "group_id": "codeNet:p02579", "input_text": "(defun paint (x y s h w)\n (let ((current (aref s x y)))\n (when\n (and (< x h)\n (eql (aref s (1+ x) y) nil))\n (setf (aref s (1+ x) y) current)\n (paint (1+ x) y s h w))\n (when\n (and (< y w)\n (eql (aref s x (1+ y)) nil))\n (setf (aref s x (1+ y)) current)\n (paint x (1+ y) s h w))\n (when (and (> x 0)\n (eql (aref s (1- x) y) nil))\n (setf (aref s (1- x) y) current)\n (paint (1- x) y s h w))\n (when (and (> y 0)\n (eql (aref s x (1- y)) nil))\n (setf (aref s x (1- y)) current)\n (paint x (1- y) s h w))))\n\n(defun solved (x y s h w)\n (first (sort (remove-if-not 'numberp\n (list\n (when (< x h)\n (aref s (1+ x) y))\n (when (< y w)\n (aref s x (1+ y)))\n (when (> x 0)\n (aref s (1- x) y))\n (when (> y 0)\n (aref s x (1- y)))))\n #'<)))\n\n(defun find-warp (s h w)\n (loop for w_ from 0 to w\n do (loop for h_ from 0 to h\n do (unless (aref s h_ w_)\n (loop for h__ from (max (- h_ 2) 0) to (min (+ h_ 2) h)\n do (loop with c = nil\n for w__ from (max (- w_ 2) 0) to (min (+ w_ 2) w)\n do (setf c (or (and (numberp (aref s h__ w__))\n (if c\n (min c (aref s h__ w__))\n (aref s h__ w__)))\n c))\n finally (when c\n (setf (aref s h_ w_) (1+ c))\n (return-from find-warp (list h_ w_)))))))))\n\n\n(let* ((h (1- (read)))\n (w (1- (read)))\n (ch (1- (read)))\n (cw (1- (read)))\n (dh (1- (read)))\n (dw (1- (read)))\n (s (make-array (list (1+ w) (1+ h)))))\n (loop for h_ from 0 to h\n do (loop for w_ from 0 to w\n do (setf (aref s h_ w_) (eql #\\# (read-char)))\n finally (read-char)))\n (setf (aref s ch cw) 0)\n (setf (aref s dh dw) :goal)\n (loop with x = ch\n with y = cw\n with new\n do\n (paint x y s h w)\n (setf new (find-warp s h w)\n x (first new)\n y (second new))\n while new\n finally (format t\"~A~%\" (or (solved dh dw s h w) -1)))\n (print (list (list ch cw)\n (list dh dw)\n s)))", "language": "Lisp", "metadata": {"date": 1598128772, "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/s644659597.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s644659597", "user_id": "u607637432"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun paint (x y s h w)\n (let ((current (aref s x y)))\n (when\n (and (< x h)\n (eql (aref s (1+ x) y) nil))\n (setf (aref s (1+ x) y) current)\n (paint (1+ x) y s h w))\n (when\n (and (< y w)\n (eql (aref s x (1+ y)) nil))\n (setf (aref s x (1+ y)) current)\n (paint x (1+ y) s h w))\n (when (and (> x 0)\n (eql (aref s (1- x) y) nil))\n (setf (aref s (1- x) y) current)\n (paint (1- x) y s h w))\n (when (and (> y 0)\n (eql (aref s x (1- y)) nil))\n (setf (aref s x (1- y)) current)\n (paint x (1- y) s h w))))\n\n(defun solved (x y s h w)\n (first (sort (remove-if-not 'numberp\n (list\n (when (< x h)\n (aref s (1+ x) y))\n (when (< y w)\n (aref s x (1+ y)))\n (when (> x 0)\n (aref s (1- x) y))\n (when (> y 0)\n (aref s x (1- y)))))\n #'<)))\n\n(defun find-warp (s h w)\n (loop for w_ from 0 to w\n do (loop for h_ from 0 to h\n do (unless (aref s h_ w_)\n (loop for h__ from (max (- h_ 2) 0) to (min (+ h_ 2) h)\n do (loop with c = nil\n for w__ from (max (- w_ 2) 0) to (min (+ w_ 2) w)\n do (setf c (or (and (numberp (aref s h__ w__))\n (if c\n (min c (aref s h__ w__))\n (aref s h__ w__)))\n c))\n finally (when c\n (setf (aref s h_ w_) (1+ c))\n (return-from find-warp (list h_ w_)))))))))\n\n\n(let* ((h (1- (read)))\n (w (1- (read)))\n (ch (1- (read)))\n (cw (1- (read)))\n (dh (1- (read)))\n (dw (1- (read)))\n (s (make-array (list (1+ w) (1+ h)))))\n (loop for h_ from 0 to h\n do (loop for w_ from 0 to w\n do (setf (aref s h_ w_) (eql #\\# (read-char)))\n finally (read-char)))\n (setf (aref s ch cw) 0)\n (setf (aref s dh dw) :goal)\n (loop with x = ch\n with y = cw\n with new\n do\n (paint x y s h w)\n (setf new (find-warp s h w)\n x (first new)\n y (second new))\n while new\n finally (format t\"~A~%\" (or (solved dh dw s h w) -1)))\n (print (list (list ch cw)\n (list dh dw)\n s)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2833, "cpu_time_ms": 2206, "memory_kb": 76996}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s654639039", "group_id": "codeNet:p02582", "input_text": "(princ ((lambda (x)\n (let ((count 0)\n (previous nil)\n (species-count 0))\n (dotimes (n 3)\n (cond ((and (null previous) (eql (aref x n) #\\R))\n (incf count))\n ((and (eql previous #\\R) (eql (aref x n) #\\R))\n (incf count)))\n (setq previous (aref x n)))\n count))\n (read-line)))\n", "language": "Lisp", "metadata": {"date": 1597527244, "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/s654639039.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s654639039", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ ((lambda (x)\n (let ((count 0)\n (previous nil)\n (species-count 0))\n (dotimes (n 3)\n (cond ((and (null previous) (eql (aref x n) #\\R))\n (incf count))\n ((and (eql previous #\\R) (eql (aref x n) #\\R))\n (incf count)))\n (setq previous (aref x n)))\n count))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 19, "memory_kb": 24480}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s721211614", "group_id": "codeNet:p02584", "input_text": "(defun solve (X K D)\n (when (oddp K)\n (decf K)\n (decf X D)\n (if (minusp X) (setf X (- X))))\n (multiple-value-bind (q r)\n (floor X (* 2 D))\n (if (>= q K) r\n (min r (abs (- r (* 2 D)))))))\n\n(princ (solve (abs (read)) (read) (read)))", "language": "Lisp", "metadata": {"date": 1597592623, "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/s721211614.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s721211614", "user_id": "u289580381"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve (X K D)\n (when (oddp K)\n (decf K)\n (decf X D)\n (if (minusp X) (setf X (- X))))\n (multiple-value-bind (q r)\n (floor X (* 2 D))\n (if (>= q K) r\n (min r (abs (- r (* 2 D)))))))\n\n(princ (solve (abs (read)) (read) (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 20, "memory_kb": 24512}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s674253395", "group_id": "codeNet:p02584", "input_text": "(let ((x (read))\n (k (read))\n (l 0)\n (ki 0)\n (gu 0)\n (nokori 0)\n (dr (read)))\n (loop for i below k do\n (progn\n (if (<= x 0)\n (incf x dr)\n (decf x dr)\n )\n (if (<= i 2)\n (if (zerop (rem i 2))\n (if (= x gu)\n (progn\n (setq nokori (- k i 1))\n (return)\n )\n (setq gu x)\n )\n (if (= x ki)\n (progn\n (setq nokori (- k i 1))\n (return)\n )\n (setq ki x)\n )\n )\n )\n )\n )\n (if (zerop (rem nokori 2))\n (princ (abs x))\n (if (<= x 0)\n (princ (abs (+ x dr)))\n (princ (abs (- x dr)))\n )\n )\n)", "language": "Lisp", "metadata": {"date": 1597522158, "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/s674253395.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s674253395", "user_id": "u136500538"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((x (read))\n (k (read))\n (l 0)\n (ki 0)\n (gu 0)\n (nokori 0)\n (dr (read)))\n (loop for i below k do\n (progn\n (if (<= x 0)\n (incf x dr)\n (decf x dr)\n )\n (if (<= i 2)\n (if (zerop (rem i 2))\n (if (= x gu)\n (progn\n (setq nokori (- k i 1))\n (return)\n )\n (setq gu x)\n )\n (if (= x ki)\n (progn\n (setq nokori (- k i 1))\n (return)\n )\n (setq ki x)\n )\n )\n )\n )\n )\n (if (zerop (rem nokori 2))\n (princ (abs x))\n (if (<= x 0)\n (princ (abs (+ x dr)))\n (princ (abs (- x dr)))\n )\n )\n)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 893, "cpu_time_ms": 2206, "memory_kb": 24448}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s818041459", "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 (let ((value 0))\n (declare (uint62 value))\n (when (> num 0)\n (maxf value (aref dp j (- num 1))))\n (cond ((= num 0)\n (maxf value (aref dp j 3)))\n ((= num 1)\n (maxf value (+ v (aref dp j 3)))))\n (when (> j 0)\n (when (> num 0)\n (maxf value (+ v (aref dp (- j 1) (- num 1)))))\n (maxf value (aref dp (- j 1) num)))\n (setf (aref dp j num) value))))))\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": 1597569563, "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/s818041459.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s818041459", "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 (let ((value 0))\n (declare (uint62 value))\n (when (> num 0)\n (maxf value (aref dp j (- num 1))))\n (cond ((= num 0)\n (maxf value (aref dp j 3)))\n ((= num 1)\n (maxf value (+ v (aref dp j 3)))))\n (when (> j 0)\n (when (> num 0)\n (maxf value (+ v (aref dp (- j 1) (- num 1)))))\n (maxf value (aref dp (- j 1) num)))\n (setf (aref dp j num) value))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6302, "cpu_time_ms": 280, "memory_kb": 60040}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s318799343", "group_id": "codeNet:p02595", "input_text": "(let* ((n (read))\n (d (read))\n (r (loop with d2 = (* d d)\n for i from 1 to n\n for x = (read)\n for y = (read)\n when (<= (+ (* x x) (* y y)) d2)\n count t)))\n (format t \"~A~%\" r))", "language": "Lisp", "metadata": {"date": 1596416926, "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/s318799343.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s318799343", "user_id": "u607637432"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((n (read))\n (d (read))\n (r (loop with d2 = (* d d)\n for i from 1 to n\n for x = (read)\n for y = (read)\n when (<= (+ (* x x) (* y y)) d2)\n count t)))\n (format t \"~A~%\" r))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 264, "cpu_time_ms": 376, "memory_kb": 77100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s067970264", "group_id": "codeNet:p02596", "input_text": "(defun solve (K)\n (defvar r (mod 7 K))\n (defvar ht (make-hash-table))\n\n (loop for i from 1\n \n if (zerop r) return i\n if #1=(gethash r ht) return -1\n do (setf #1# t\n r (mod (+ (* 10 r) 7) K))))\n\n(princ (solve (read)))", "language": "Lisp", "metadata": {"date": 1597095580, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02596.html", "problem_id": "p02596", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02596/input.txt", "sample_output_relpath": "derived/input_output/data/p02596/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02596/Lisp/s067970264.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s067970264", "user_id": "u289580381"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solve (K)\n (defvar r (mod 7 K))\n (defvar ht (make-hash-table))\n\n (loop for i from 1\n \n if (zerop r) return i\n if #1=(gethash r ht) return -1\n do (setf #1# t\n r (mod (+ (* 10 r) 7) K))))\n\n(princ (solve (read)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi loves the number 7 and multiples of K.\n\nWhere is the first occurrence of a multiple of K in the sequence 7,77,777,\\ldots? (Also see Output and Sample Input/Output below.)\n\nIf the sequence contains no multiples of K, print -1 instead.\n\nConstraints\n\n1 \\leq K \\leq 10^6\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)\n\nSample Input 1\n\n101\n\nSample Output 1\n\n4\n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n-1\n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\nSample Input 3\n\n999983\n\nSample Output 3\n\n999982", "sample_input": "101\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02596", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi loves the number 7 and multiples of K.\n\nWhere is the first occurrence of a multiple of K in the sequence 7,77,777,\\ldots? (Also see Output and Sample Input/Output below.)\n\nIf the sequence contains no multiples of K, print -1 instead.\n\nConstraints\n\n1 \\leq K \\leq 10^6\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)\n\nSample Input 1\n\n101\n\nSample Output 1\n\n4\n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n-1\n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\nSample Input 3\n\n999983\n\nSample Output 3\n\n999982", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 308, "memory_kb": 122556}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s704353378", "group_id": "codeNet:p02596", "input_text": "(defun main (k s index)\n (cond ((< (expt 10 6) index) (princ -1))\n ((= (mod s k) 0) (princ index))\n (t (main k (mod (+ (* s 10) 7) k) (incf index)))))\n\n(main (read) 7 1)\n", "language": "Lisp", "metadata": {"date": 1596849387, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02596.html", "problem_id": "p02596", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02596/input.txt", "sample_output_relpath": "derived/input_output/data/p02596/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02596/Lisp/s704353378.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s704353378", "user_id": "u761519515"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun main (k s index)\n (cond ((< (expt 10 6) index) (princ -1))\n ((= (mod s k) 0) (princ index))\n (t (main k (mod (+ (* s 10) 7) k) (incf index)))))\n\n(main (read) 7 1)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi loves the number 7 and multiples of K.\n\nWhere is the first occurrence of a multiple of K in the sequence 7,77,777,\\ldots? (Also see Output and Sample Input/Output below.)\n\nIf the sequence contains no multiples of K, print -1 instead.\n\nConstraints\n\n1 \\leq K \\leq 10^6\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)\n\nSample Input 1\n\n101\n\nSample Output 1\n\n4\n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n-1\n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\nSample Input 3\n\n999983\n\nSample Output 3\n\n999982", "sample_input": "101\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02596", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi loves the number 7 and multiples of K.\n\nWhere is the first occurrence of a multiple of K in the sequence 7,77,777,\\ldots? (Also see Output and Sample Input/Output below.)\n\nIf the sequence contains no multiples of K, print -1 instead.\n\nConstraints\n\n1 \\leq K \\leq 10^6\n\nK is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nK\n\nOutput\n\nPrint an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)\n\nSample Input 1\n\n101\n\nSample Output 1\n\n4\n\nNone of 7, 77, and 777 is a multiple of 101, but 7777 is.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n-1\n\nAll elements in the sequence are odd numbers; there are no multiples of 2.\n\nSample Input 3\n\n999983\n\nSample Output 3\n\n999982", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 65, "memory_kb": 24296}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s818135456", "group_id": "codeNet:p02598", "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(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\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(declaim (ftype (function (fixnum list) fixnum) solve))\n(defun solve (k xs)\n (declare (fixnum k)\n (list xs))\n (labels ((calc-proc (len x)\n (max (1- (ceiling len x))\n 0))\n (judge (x)\n (<= (reduce #'+\n (mapcar (lambda (s)\n (calc-proc s x))\n xs))\n k))\n (bs (ng ok)\n (if (<= (abs (- ng ok)) 1)\n ok\n (let ((mid (floor (+ ng ok) 2)))\n (if (judge mid)\n (bs ng mid)\n (bs mid ok))))))\n (declare (inline calc-proc judge))\n (declare (ftype (function (fixnum fixnum)) calc-proc)\n (ftype (function (fixnum)) judge)\n (ftype (function (fixnum fixnum) fixnum) bs))\n (bs 0 (expt 10 9))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (k (read)))\n (declare (fixnum n k))\n (let ((xs (read-numbers-to-list n)))\n (declare (list xs))\n (princ (solve k xs))\n (fresh-line))))\n\n\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600353670, "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/s818135456.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s818135456", "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(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\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(declaim (ftype (function (fixnum list) fixnum) solve))\n(defun solve (k xs)\n (declare (fixnum k)\n (list xs))\n (labels ((calc-proc (len x)\n (max (1- (ceiling len x))\n 0))\n (judge (x)\n (<= (reduce #'+\n (mapcar (lambda (s)\n (calc-proc s x))\n xs))\n k))\n (bs (ng ok)\n (if (<= (abs (- ng ok)) 1)\n ok\n (let ((mid (floor (+ ng ok) 2)))\n (if (judge mid)\n (bs ng mid)\n (bs mid ok))))))\n (declare (inline calc-proc judge))\n (declare (ftype (function (fixnum fixnum)) calc-proc)\n (ftype (function (fixnum)) judge)\n (ftype (function (fixnum fixnum) fixnum) bs))\n (bs 0 (expt 10 9))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (k (read)))\n (declare (fixnum n k))\n (let ((xs (read-numbers-to-list n)))\n (declare (list xs))\n (princ (solve k xs))\n (fresh-line))))\n\n\n\n#-swank (main)\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)))\n (loop while (> k 0)\n do (loop for i from 1\n while (and (> k i)\n (> (/ (first a) (+ 1 i))\n (/ (second a) 2)))\n finally (if (> k i)\n (progn\n (decf k i)\n (loop with v = (pop a)\n repeat (1+ i)\n do (push (/ v (1+ i)) a)))\n (progn\n (decf k)\n (let ((v (pop a)))\n (push (/ v 2) a)\n (push (/ v 2) a)))))\n do (setf a (sort a #'>))\n (print (list k a))\n )\n (format t \"~A~%\" (ceiling (first a)))\n )\n", "language": "Lisp", "metadata": {"date": 1596422323, "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/s408295179.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s408295179", "user_id": "u607637432"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (a (sort (loop repeat n collect (read)) #'>)))\n (loop while (> k 0)\n do (loop for i from 1\n while (and (> k i)\n (> (/ (first a) (+ 1 i))\n (/ (second a) 2)))\n finally (if (> k i)\n (progn\n (decf k i)\n (loop with v = (pop a)\n repeat (1+ i)\n do (push (/ v (1+ i)) a)))\n (progn\n (decf k)\n (let ((v (pop a)))\n (push (/ v 2) a)\n (push (/ v 2) a)))))\n do (setf a (sort a #'>))\n (print (list k a))\n )\n (format t \"~A~%\" (ceiling (first a)))\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;;; Quicksort (deterministic median-of-three partitioning)\n;;;\n\n;; NOTE: This quicksort is NOT randomized. You should shuffle an input when you\n;; need to avoid getting hacked.\n\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)\n \"Destructively sorts VECTOR w.r.t. ORDER.\"\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))\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 0 (- (length vector) 1))\n vector))\n\n;;;\n;;; Mo's algorithm\n;;;\n\n(deftype mo-integer () 'uint31)\n\n(defstruct (mo (:constructor %make-mo\n (lefts rights order))\n (:conc-name %mo-)\n (:copier nil)\n (:predicate nil))\n (lefts nil :type (simple-array mo-integer (*)))\n (rights nil :type (simple-array mo-integer (*)))\n (order nil :type (simple-array mo-integer (*)))\n (index 0 :type (integer 0 #.most-positive-fixnum)))\n\n(defun make-mo (bucket-width lefts rights)\n \"LEFTS := vector of indices of left-end of queries (inclusive)\nRIGHTS := vector of indices of right-end of queries (exclusive)\n\nBUCKET-WIDTH would be better set to N/sqrt(Q) where N is the width of the\nuniverse and Q is the number of queries.\"\n (declare #.opt\n ((simple-array mo-integer (*)) lefts rights)\n ((integer 0 #.most-positive-fixnum) bucket-width)\n (inline sort))\n (let* ((q (length lefts))\n (order (make-array q :element-type 'mo-integer)))\n (assert (= q (length rights)))\n (dotimes (i q) (setf (aref order i) i))\n (quicksort! order\n (lambda (x y)\n (if (= (floor (aref lefts x) bucket-width)\n (floor (aref lefts y) bucket-width))\n ;; Even-number [Odd-number] block is in ascending\n ;; [descending] order w.r.t. the right end.\n (if (evenp (floor (aref lefts x) bucket-width))\n (< (aref rights x) (aref rights y))\n (> (aref rights x) (aref rights y)))\n (< (aref lefts x) (aref lefts y)))))\n (%make-mo lefts rights order)))\n\n(declaim (inline mo-get-current))\n(defun mo-get-current (mo)\n \"Returns the original index of the current (not yet proessed) query.\"\n (aref (%mo-order mo) (%mo-index mo)))\n\n(declaim (ftype (function * (values uint31 &optional)) read-fixnum+))\n(defun read-fixnum+ (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.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 (uint31 result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte)\n (setq result (+ (- byte 48)\n (* 10 (the uint31 result))))\n (return 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 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 (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 (let ((mo (make-mo 740 ls rs))\n (dp (make-array (+ n 1) :element-type 'uint31))\n (res (make-array q :element-type 'uint31 :initial-element 0))\n (value 0)\n (posl 0)\n (posr 0))\n (declare (uint31 value))\n (dotimes (_ q)\n (let* ((ord (mo-get-current mo))\n (left (aref ls ord))\n (right (aref rs ord)))\n (declare ((integer 0 #.most-positive-fixnum) posl posr))\n (loop while (< left posl)\n do (decf posl)\n (let* ((c (aref cs posl))\n (num (aref dp c)))\n (when (zerop num)\n (incf value))\n (setf (aref dp c) (+ num 1))))\n (loop while (< posr right)\n do (let* ((c (aref cs posr))\n (num (aref dp c)))\n (when (zerop num)\n (incf value))\n (setf (aref dp c) (+ num 1)))\n (incf posr))\n (loop while (< posl left)\n do (let* ((c (aref cs posl))\n (num (aref dp c)))\n (when (= 1 num)\n (decf value))\n (setf (aref dp c) (- num 1)))\n (incf posl))\n (loop while (< right posr)\n do (decf posr)\n (let* ((c (aref cs posr))\n (num (aref dp c)))\n (when (= 1 num)\n (decf value))\n (setf (aref dp c) (- num 1))))\n (incf (%mo-index mo))\n (setf (aref res ord) value)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\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 #+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": 1596596831, "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/s367159541.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s367159541", "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;;; Quicksort (deterministic median-of-three partitioning)\n;;;\n\n;; NOTE: This quicksort is NOT randomized. You should shuffle an input when you\n;; need to avoid getting hacked.\n\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)\n \"Destructively sorts VECTOR w.r.t. ORDER.\"\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))\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 0 (- (length vector) 1))\n vector))\n\n;;;\n;;; Mo's algorithm\n;;;\n\n(deftype mo-integer () 'uint31)\n\n(defstruct (mo (:constructor %make-mo\n (lefts rights order))\n (:conc-name %mo-)\n (:copier nil)\n (:predicate nil))\n (lefts nil :type (simple-array mo-integer (*)))\n (rights nil :type (simple-array mo-integer (*)))\n (order nil :type (simple-array mo-integer (*)))\n (index 0 :type (integer 0 #.most-positive-fixnum)))\n\n(defun make-mo (bucket-width lefts rights)\n \"LEFTS := vector of indices of left-end of queries (inclusive)\nRIGHTS := vector of indices of right-end of queries (exclusive)\n\nBUCKET-WIDTH would be better set to N/sqrt(Q) where N is the width of the\nuniverse and Q is the number of queries.\"\n (declare #.opt\n ((simple-array mo-integer (*)) lefts rights)\n ((integer 0 #.most-positive-fixnum) bucket-width)\n (inline sort))\n (let* ((q (length lefts))\n (order (make-array q :element-type 'mo-integer)))\n (assert (= q (length rights)))\n (dotimes (i q) (setf (aref order i) i))\n (quicksort! order\n (lambda (x y)\n (if (= (floor (aref lefts x) bucket-width)\n (floor (aref lefts y) bucket-width))\n ;; Even-number [Odd-number] block is in ascending\n ;; [descending] order w.r.t. the right end.\n (if (evenp (floor (aref lefts x) bucket-width))\n (< (aref rights x) (aref rights y))\n (> (aref rights x) (aref rights y)))\n (< (aref lefts x) (aref lefts y)))))\n (%make-mo lefts rights order)))\n\n(declaim (inline mo-get-current))\n(defun mo-get-current (mo)\n \"Returns the original index of the current (not yet proessed) query.\"\n (aref (%mo-order mo) (%mo-index mo)))\n\n(declaim (ftype (function * (values uint31 &optional)) read-fixnum+))\n(defun read-fixnum+ (&optional (in *standard-input*))\n \"NOTE: cannot read -2^62\"\n (declare #.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 (uint31 result))\n (loop\n (let* ((byte (%read-byte)))\n (if (<= 48 byte)\n (setq result (+ (- byte 48)\n (* 10 (the uint31 result))))\n (return 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 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 (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 (let ((mo (make-mo 740 ls rs))\n (dp (make-array (+ n 1) :element-type 'uint31))\n (res (make-array q :element-type 'uint31 :initial-element 0))\n (value 0)\n (posl 0)\n (posr 0))\n (declare (uint31 value))\n (dotimes (_ q)\n (let* ((ord (mo-get-current mo))\n (left (aref ls ord))\n (right (aref rs ord)))\n (declare ((integer 0 #.most-positive-fixnum) posl posr))\n (loop while (< left posl)\n do (decf posl)\n (let* ((c (aref cs posl))\n (num (aref dp c)))\n (when (zerop num)\n (incf value))\n (setf (aref dp c) (+ num 1))))\n (loop while (< posr right)\n do (let* ((c (aref cs posr))\n (num (aref dp c)))\n (when (zerop num)\n (incf value))\n (setf (aref dp c) (+ num 1)))\n (incf posr))\n (loop while (< posl left)\n do (let* ((c (aref cs posl))\n (num (aref dp c)))\n (when (= 1 num)\n (decf value))\n (setf (aref dp c) (- num 1)))\n (incf posl))\n (loop while (< right posr)\n do (decf posr)\n (let* ((c (aref cs posr))\n (num (aref dp c)))\n (when (= 1 num)\n (decf value))\n (setf (aref dp c) (- num 1))))\n (incf (%mo-index mo))\n (setf (aref res ord) value)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\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 #+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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10186, "cpu_time_ms": 1981, "memory_kb": 43880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s178392148", "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(deftype node () '(simple-vector 3))\n(defstruct (node (:constructor make-node (&optional (value 0)))\n (:type vector))\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": 1596427144, "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/s178392148.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s178392148", "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(deftype node () '(simple-vector 3))\n(defstruct (node (:constructor make-node (&optional (value 0)))\n (:type vector))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10030, "cpu_time_ms": 2227, "memory_kb": 957096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s408511409", "group_id": "codeNet:p02600", "input_text": "(let ((x (read)))\n (format t \"~A~%\" (cond ((<= 400 x 599) 8)\n ((<= 600 x 799) 7)\n ((<= 800 x 999) 6)\n ((<= 1000 x 1199) 5)\n ((<= 1200 x 1399) 4)\n ((<= 1400 x 1599) 3)\n ((<= 1600 x 1799) 2)\n (t 1))))\n", "language": "Lisp", "metadata": {"date": 1595725354, "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/s408511409.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s408511409", "user_id": "u608227593"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(let ((x (read)))\n (format t \"~A~%\" (cond ((<= 400 x 599) 8)\n ((<= 600 x 799) 7)\n ((<= 800 x 999) 6)\n ((<= 1000 x 1199) 5)\n ((<= 1200 x 1399) 4)\n ((<= 1400 x 1599) 3)\n ((<= 1600 x 1799) 2)\n (t 1))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 368, "cpu_time_ms": 21, "memory_kb": 24388}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s351834358", "group_id": "codeNet:p02602", "input_text": "(let* ((n (read))\n (k (read))\n (a (make-array (list (1+ n)))))\n (loop :for i :from 1 :to k\n :do (setf (aref a i) (read)))\n (loop :for i :from (1+ k) :to n\n :do (setf (aref a i) (read))\n :if (> (aref a i) (aref a (- i k)))\n :do (format t \"Yes~%\")\n :else\n :do (format t \"No~%\")))\n", "language": "Lisp", "metadata": {"date": 1595726440, "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/s351834358.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s351834358", "user_id": "u608227593"}, "prompt_components": {"gold_output": "Yes\nNo\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (a (make-array (list (1+ n)))))\n (loop :for i :from 1 :to k\n :do (setf (aref a i) (read)))\n (loop :for i :from (1+ k) :to n\n :do (setf (aref a i) (read))\n :if (> (aref a i) (aref a (- i k)))\n :do (format t \"Yes~%\")\n :else\n :do (format t \"No~%\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 334, "cpu_time_ms": 531, "memory_kb": 77968}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s324715838", "group_id": "codeNet:p02603", "input_text": "(let* ((x 1000)\n (y 0)\n (n (read))\n (a (make-array (list n))))\n (loop :for i :from 0 :to (1- n)\n :do (setf (aref a i) (read)))\n ;;\n (loop :for i :from 0 :to (- n 2)\n :for today := (aref a i)\n :for tomorrow := (aref a (1+ i))\n :if (< today tomorrow)\n :do (let ((d (floor (/ x (aref a i)))))\n (incf y d)\n (decf x (* d today)))\n :if (> today tomorrow)\n :do (progn\n (incf x (* y today)))\n (setf y 0))\n (when (/= y 0)\n (incf x (* y (aref a (1- n))))\n (setf y 0))\n (format t \"~A~%\" x))\n", "language": "Lisp", "metadata": {"date": 1595727241, "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/s324715838.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s324715838", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1685\n", "input_to_evaluate": "(let* ((x 1000)\n (y 0)\n (n (read))\n (a (make-array (list n))))\n (loop :for i :from 0 :to (1- n)\n :do (setf (aref a i) (read)))\n ;;\n (loop :for i :from 0 :to (- n 2)\n :for today := (aref a i)\n :for tomorrow := (aref a (1+ i))\n :if (< today tomorrow)\n :do (let ((d (floor (/ x (aref a i)))))\n (incf y d)\n (decf x (* d today)))\n :if (> today tomorrow)\n :do (progn\n (incf x (* y today)))\n (setf y 0))\n (when (/= y 0)\n (incf x (* y (aref a (1- n))))\n (setf y 0))\n (format t \"~A~%\" x))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 24720}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s157750855", "group_id": "codeNet:p02604", "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(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;;; Sort multiple vectors\n;;;\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 (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(defun parallel-shuffle! (vector &rest vectors)\n \"Destructively shuffles VECTOR and applies the same permutation to all the\nvectors in VECTORS.\"\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 (dolist (v vectors)\n (rotatef (aref v i) (aref v j)))\n finally (return vector)))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:define-source-transform parallel-shuffle! (vector &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 (loop for i from (- (length ,vec) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref ,vec i) (aref ,vec j))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym i) (aref ,sym j)))\n finally (return ,vec))))))\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 xs ys ps k seconds)\n (declare #.OPT\n ((simple-array int32 (*)) xs ys ps)\n (uint8 n k))\n (let ((on-set (make-array k :element-type 'int32 :initial-element 0))\n (off-set (make-array n :element-type 'int32 :initial-element 0))\n ;; 0: horizontal, 1: vertical\n (dirs (make-array k :element-type 'bit :initial-element 0)))\n (parallel-shuffle! xs ys ps)\n (dotimes (i n)\n (if (< i k)\n (setf (aref on-set i) i\n (aref dirs i) (random 2))\n (setf (aref off-set (- i k)) i)))\n (labels ((calc-score ()\n (loop for x across xs\n for y across ys\n for p across ps\n sum (* p (min (loop for idx across on-set\n for dir across dirs\n minimize (if (zerop dir)\n (abs (- y (aref ys idx)))\n (abs (- x (aref xs idx)))))\n (abs y)\n (abs x)))\n of-type fixnum)))\n (let* ((min-score (calc-score))\n (current-score min-score)\n (count 0)\n (kick-count 0))\n (declare (fixnum min-score current-score count))\n (sb-int:with-progressive-timeout (get-remaining-time :seconds seconds)\n (loop (minf min-score current-score)\n (when (eq 0 (get-remaining-time))\n #>kick-count\n (return min-score))\n (let ((i (random k))\n (j (random (- n k)))\n (flip (random 2)))\n (rotatef (aref on-set i) (aref off-set j))\n (xorf (aref dirs i) flip)\n (let ((score (calc-score)))\n (cond ((< score current-score)\n (setq current-score score\n count 0))\n ((= score current-score)\n (incf count))\n (t\n (rotatef (aref on-set i) (aref off-set j))\n (xorf (aref dirs i) flip)\n (incf count))))\n ;; kick\n (when (>= count 1000)\n (incf kick-count)\n (parallel-shuffle! xs ys ps)\n (setq current-score (calc-score))))))))))\n\n(defun main ()\n (let* ((n (read))\n (xs (make-array n :element-type 'int32 :initial-element 0))\n (ys (make-array n :element-type 'int32 :initial-element 0))\n (ps (make-array n :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref xs i) (read)\n (aref ys i) (read)\n (aref ps i) (read)))\n (println (loop for x across xs\n for y across ys\n for p across ps\n sum (* p (min (abs x) (abs y)))))\n (loop for k from 1 below n\n do (println (if (member k (list 1 (- n 2)))\n (solve n xs ys ps k 0.02d0)\n (solve n xs ys ps k 0.24d0))))\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 #+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 \"15~%\")\n (dotimes (_ 15)\n (format out \"~D ~D ~D~%\"\n (- (random 20000) 10000)\n (- (random 20000) 10000)\n (+ 1 (random 1000000))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; 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 300\n3 3 600\n1 4 800\n\"\n \"2900\n900\n0\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n3 5 400\n5 3 700\n5 5 1000\n5 7 700\n7 5 400\n\"\n \"13800\n1600\n0\n0\n0\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2 5 1000\n5 2 1100\n5 5 1700\n-2 -5 900\n-5 -2 600\n-5 -5 2200\n\"\n \"26700\n13900\n3200\n1200\n0\n0\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n2 2 286017\n3 1 262355\n2 -2 213815\n1 -3 224435\n-2 -2 136860\n-3 -1 239338\n-2 2 217647\n-1 3 141903\n\"\n \"2576709\n1569381\n868031\n605676\n366338\n141903\n0\n0\n0\n\")))\n", "language": "Lisp", "metadata": {"date": 1595741149, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02604.html", "problem_id": "p02604", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02604/input.txt", "sample_output_relpath": "derived/input_output/data/p02604/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02604/Lisp/s157750855.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s157750855", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2900\n900\n0\n0\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(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;;; Sort multiple vectors\n;;;\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 (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(defun parallel-shuffle! (vector &rest vectors)\n \"Destructively shuffles VECTOR and applies the same permutation to all the\nvectors in VECTORS.\"\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 (dolist (v vectors)\n (rotatef (aref v i) (aref v j)))\n finally (return vector)))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:define-source-transform parallel-shuffle! (vector &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 (loop for i from (- (length ,vec) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref ,vec i) (aref ,vec j))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym i) (aref ,sym j)))\n finally (return ,vec))))))\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 xs ys ps k seconds)\n (declare #.OPT\n ((simple-array int32 (*)) xs ys ps)\n (uint8 n k))\n (let ((on-set (make-array k :element-type 'int32 :initial-element 0))\n (off-set (make-array n :element-type 'int32 :initial-element 0))\n ;; 0: horizontal, 1: vertical\n (dirs (make-array k :element-type 'bit :initial-element 0)))\n (parallel-shuffle! xs ys ps)\n (dotimes (i n)\n (if (< i k)\n (setf (aref on-set i) i\n (aref dirs i) (random 2))\n (setf (aref off-set (- i k)) i)))\n (labels ((calc-score ()\n (loop for x across xs\n for y across ys\n for p across ps\n sum (* p (min (loop for idx across on-set\n for dir across dirs\n minimize (if (zerop dir)\n (abs (- y (aref ys idx)))\n (abs (- x (aref xs idx)))))\n (abs y)\n (abs x)))\n of-type fixnum)))\n (let* ((min-score (calc-score))\n (current-score min-score)\n (count 0)\n (kick-count 0))\n (declare (fixnum min-score current-score count))\n (sb-int:with-progressive-timeout (get-remaining-time :seconds seconds)\n (loop (minf min-score current-score)\n (when (eq 0 (get-remaining-time))\n #>kick-count\n (return min-score))\n (let ((i (random k))\n (j (random (- n k)))\n (flip (random 2)))\n (rotatef (aref on-set i) (aref off-set j))\n (xorf (aref dirs i) flip)\n (let ((score (calc-score)))\n (cond ((< score current-score)\n (setq current-score score\n count 0))\n ((= score current-score)\n (incf count))\n (t\n (rotatef (aref on-set i) (aref off-set j))\n (xorf (aref dirs i) flip)\n (incf count))))\n ;; kick\n (when (>= count 1000)\n (incf kick-count)\n (parallel-shuffle! xs ys ps)\n (setq current-score (calc-score))))))))))\n\n(defun main ()\n (let* ((n (read))\n (xs (make-array n :element-type 'int32 :initial-element 0))\n (ys (make-array n :element-type 'int32 :initial-element 0))\n (ps (make-array n :element-type 'int32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref xs i) (read)\n (aref ys i) (read)\n (aref ps i) (read)))\n (println (loop for x across xs\n for y across ys\n for p across ps\n sum (* p (min (abs x) (abs y)))))\n (loop for k from 1 below n\n do (println (if (member k (list 1 (- n 2)))\n (solve n xs ys ps k 0.02d0)\n (solve n xs ys ps k 0.24d0))))\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 #+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 \"15~%\")\n (dotimes (_ 15)\n (format out \"~D ~D ~D~%\"\n (- (random 20000) 10000)\n (- (random 20000) 10000)\n (+ 1 (random 1000000))))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; 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 300\n3 3 600\n1 4 800\n\"\n \"2900\n900\n0\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n3 5 400\n5 3 700\n5 5 1000\n5 7 700\n7 5 400\n\"\n \"13800\n1600\n0\n0\n0\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n2 5 1000\n5 2 1100\n5 5 1700\n-2 -5 900\n-5 -2 600\n-5 -5 2200\n\"\n \"26700\n13900\n3200\n1200\n0\n0\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n2 2 286017\n3 1 262355\n2 -2 213815\n1 -3 224435\n-2 -2 136860\n-3 -1 239338\n-2 2 217647\n-1 3 141903\n\"\n \"2576709\n1569381\n868031\n605676\n366338\n141903\n0\n0\n0\n\")))\n", "problem_context": "Score: 500 points\n\nProblem Statement\n\nNew AtCoder City has an infinite grid of streets, as follows:\n\nAt the center of the city stands a clock tower. Let (0, 0) be the coordinates of this point.\n\nA straight street, which we will call East-West Main Street, runs east-west and passes the clock tower. It corresponds to the x-axis in the two-dimensional coordinate plane.\n\nThere are also other infinitely many streets parallel to East-West Main Street, with a distance of 1 between them. They correspond to the lines \\ldots, y = -2, y = -1, y = 1, y = 2, \\ldots in the two-dimensional coordinate plane.\n\nA straight street, which we will call North-South Main Street, runs north-south and passes the clock tower. It corresponds to the y-axis in the two-dimensional coordinate plane.\n\nThere are also other infinitely many streets parallel to North-South Main Street, with a distance of 1 between them. They correspond to the lines \\ldots, x = -2, x = -1, x = 1, x = 2, \\ldots in the two-dimensional coordinate plane.\n\nThere are N residential areas in New AtCoder City. The i-th area is located at the intersection with the coordinates (X_i, Y_i) and has a population of P_i. Each citizen in the city lives in one of these areas.\n\nThe city currently has only two railroads, stretching infinitely, one along East-West Main Street and the other along North-South Main Street.\n\nM-kun, the mayor, thinks that they are not enough for the commuters, so he decides to choose K streets and build a railroad stretching infinitely along each of those streets.\n\nLet the walking distance of each citizen be the distance from his/her residential area to the nearest railroad.\n\nM-kun wants to build railroads so that the sum of the walking distances of all citizens, S, is minimized.\n\nFor each K = 0, 1, 2, \\dots, N, what is the minimum possible value of S after building railroads?\n\nConstraints\n\n1 \\leq N \\leq 15\n\n-10 \\ 000 \\leq X_i \\leq 10 \\ 000\n\n-10 \\ 000 \\leq Y_i \\leq 10 \\ 000\n\n1 \\leq P_i \\leq 1 \\ 000 \\ 000\n\nThe locations of the N residential areas, (X_i, Y_i), are all distinct.\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 P_1\nX_2 Y_2 P_2\n: : :\nX_N Y_N P_N\n\nOutput\n\nPrint the answer in N+1 lines.\n\nThe i-th line (i = 1, \\ldots, N+1) should contain the minimum possible value of S after building railroads for the case K = i-1.\n\nSample Input 1\n\n3\n1 2 300\n3 3 600\n1 4 800\n\nSample Output 1\n\n2900\n900\n0\n0\n\nWhen K = 0, the residents of Area 1, 2, and 3 have to walk the distances of 1, 3, and 1, respectively, to reach a railroad.\n\nThus, the sum of the walking distances of all citizens, S, is 1 \\times 300 + 3 \\times 600 + 1 \\times 800 = 2900.\n\nWhen K = 1, if we build a railroad along the street corresponding to the line y = 4 in the coordinate plane, the walking distances of the citizens of Area 1, 2, and 3 become 1, 1, and 0, respectively.\n\nThen, S = 1 \\times 300 + 1 \\times 600 + 0 \\times 800 = 900.\n\nWe have many other options for where we build the railroad, but none of them makes S less than 900.\n\nWhen K = 2, if we build a railroad along the street corresponding to the lines x = 1 and x = 3 in the coordinate plane, all citizens can reach a railroad with the walking distance of 0, so S = 0. We can also have S = 0 when K = 3.\n\nThe figure below shows the optimal way to build railroads for the cases K = 0, 1, 2.\n\nThe street painted blue represents the roads along which we build railroads.\n\nSample Input 2\n\n5\n3 5 400\n5 3 700\n5 5 1000\n5 7 700\n7 5 400\n\nSample Output 2\n\n13800\n1600\n0\n0\n0\n0\n\nThe figure below shows the optimal way to build railroads for the cases K = 1, 2.\n\nSample Input 3\n\n6\n2 5 1000\n5 2 1100\n5 5 1700\n-2 -5 900\n-5 -2 600\n-5 -5 2200\n\nSample Output 3\n\n26700\n13900\n3200\n1200\n0\n0\n0\n\nThe figure below shows the optimal way to build railroads for the case K = 3.\n\nSample Input 4\n\n8\n2 2 286017\n3 1 262355\n2 -2 213815\n1 -3 224435\n-2 -2 136860\n-3 -1 239338\n-2 2 217647\n-1 3 141903\n\nSample Output 4\n\n2576709\n1569381\n868031\n605676\n366338\n141903\n0\n0\n0\n\nThe figure below shows the optimal way to build railroads for the case K = 4.", "sample_input": "3\n1 2 300\n3 3 600\n1 4 800\n"}, "reference_outputs": ["2900\n900\n0\n0\n"], "source_document_id": "p02604", "source_text": "Score: 500 points\n\nProblem Statement\n\nNew AtCoder City has an infinite grid of streets, as follows:\n\nAt the center of the city stands a clock tower. Let (0, 0) be the coordinates of this point.\n\nA straight street, which we will call East-West Main Street, runs east-west and passes the clock tower. It corresponds to the x-axis in the two-dimensional coordinate plane.\n\nThere are also other infinitely many streets parallel to East-West Main Street, with a distance of 1 between them. They correspond to the lines \\ldots, y = -2, y = -1, y = 1, y = 2, \\ldots in the two-dimensional coordinate plane.\n\nA straight street, which we will call North-South Main Street, runs north-south and passes the clock tower. It corresponds to the y-axis in the two-dimensional coordinate plane.\n\nThere are also other infinitely many streets parallel to North-South Main Street, with a distance of 1 between them. They correspond to the lines \\ldots, x = -2, x = -1, x = 1, x = 2, \\ldots in the two-dimensional coordinate plane.\n\nThere are N residential areas in New AtCoder City. The i-th area is located at the intersection with the coordinates (X_i, Y_i) and has a population of P_i. Each citizen in the city lives in one of these areas.\n\nThe city currently has only two railroads, stretching infinitely, one along East-West Main Street and the other along North-South Main Street.\n\nM-kun, the mayor, thinks that they are not enough for the commuters, so he decides to choose K streets and build a railroad stretching infinitely along each of those streets.\n\nLet the walking distance of each citizen be the distance from his/her residential area to the nearest railroad.\n\nM-kun wants to build railroads so that the sum of the walking distances of all citizens, S, is minimized.\n\nFor each K = 0, 1, 2, \\dots, N, what is the minimum possible value of S after building railroads?\n\nConstraints\n\n1 \\leq N \\leq 15\n\n-10 \\ 000 \\leq X_i \\leq 10 \\ 000\n\n-10 \\ 000 \\leq Y_i \\leq 10 \\ 000\n\n1 \\leq P_i \\leq 1 \\ 000 \\ 000\n\nThe locations of the N residential areas, (X_i, Y_i), are all distinct.\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 P_1\nX_2 Y_2 P_2\n: : :\nX_N Y_N P_N\n\nOutput\n\nPrint the answer in N+1 lines.\n\nThe i-th line (i = 1, \\ldots, N+1) should contain the minimum possible value of S after building railroads for the case K = i-1.\n\nSample Input 1\n\n3\n1 2 300\n3 3 600\n1 4 800\n\nSample Output 1\n\n2900\n900\n0\n0\n\nWhen K = 0, the residents of Area 1, 2, and 3 have to walk the distances of 1, 3, and 1, respectively, to reach a railroad.\n\nThus, the sum of the walking distances of all citizens, S, is 1 \\times 300 + 3 \\times 600 + 1 \\times 800 = 2900.\n\nWhen K = 1, if we build a railroad along the street corresponding to the line y = 4 in the coordinate plane, the walking distances of the citizens of Area 1, 2, and 3 become 1, 1, and 0, respectively.\n\nThen, S = 1 \\times 300 + 1 \\times 600 + 0 \\times 800 = 900.\n\nWe have many other options for where we build the railroad, but none of them makes S less than 900.\n\nWhen K = 2, if we build a railroad along the street corresponding to the lines x = 1 and x = 3 in the coordinate plane, all citizens can reach a railroad with the walking distance of 0, so S = 0. We can also have S = 0 when K = 3.\n\nThe figure below shows the optimal way to build railroads for the cases K = 0, 1, 2.\n\nThe street painted blue represents the roads along which we build railroads.\n\nSample Input 2\n\n5\n3 5 400\n5 3 700\n5 5 1000\n5 7 700\n7 5 400\n\nSample Output 2\n\n13800\n1600\n0\n0\n0\n0\n\nThe figure below shows the optimal way to build railroads for the cases K = 1, 2.\n\nSample Input 3\n\n6\n2 5 1000\n5 2 1100\n5 5 1700\n-2 -5 900\n-5 -2 600\n-5 -5 2200\n\nSample Output 3\n\n26700\n13900\n3200\n1200\n0\n0\n0\n\nThe figure below shows the optimal way to build railroads for the case K = 3.\n\nSample Input 4\n\n8\n2 2 286017\n3 1 262355\n2 -2 213815\n1 -3 224435\n-2 -2 136860\n-3 -1 239338\n-2 2 217647\n-1 3 141903\n\nSample Output 4\n\n2576709\n1569381\n868031\n605676\n366338\n141903\n0\n0\n0\n\nThe figure below shows the optimal way to build railroads for the case K = 4.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11939, "cpu_time_ms": 2940, "memory_kb": 24940}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s693870014", "group_id": "codeNet:p02606", "input_text": "(setq l (read))\n(setq r (read))\n(setq d (read))\n(prog (ans now)\n (setq ans 0)\n (setq now l)\n loop\n (cond ((> now r) (princ ans) (return ans)))\n (cond ((equal 0 (mod now d)) (setq ans (+ 1 ans))))\n (setq now (+ now 1))\n (go loop)\n)\n", "language": "Lisp", "metadata": {"date": 1595654007, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02606.html", "problem_id": "p02606", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02606/input.txt", "sample_output_relpath": "derived/input_output/data/p02606/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02606/Lisp/s693870014.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s693870014", "user_id": "u509739538"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(setq l (read))\n(setq r (read))\n(setq d (read))\n(prog (ans now)\n (setq ans 0)\n (setq now l)\n loop\n (cond ((> now r) (princ ans) (return ans)))\n (cond ((equal 0 (mod now d)) (setq ans (+ 1 ans))))\n (setq now (+ now 1))\n (go loop)\n)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nHow many multiples of d are there among the integers between L and R (inclusive)?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq L \\leq R \\leq 100\n\n1 \\leq d \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL R d\n\nOutput\n\nPrint the number of multiples of d among the integers between L and R (inclusive).\n\nSample Input 1\n\n5 10 2\n\nSample Output 1\n\n3\n\nAmong the integers between 5 and 10, there are three multiples of 2: 6, 8, and 10.\n\nSample Input 2\n\n6 20 7\n\nSample Output 2\n\n2\n\nAmong the integers between 6 and 20, there are two multiples of 7: 7 and 14.\n\nSample Input 3\n\n1 100 1\n\nSample Output 3\n\n100", "sample_input": "5 10 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02606", "source_text": "Score : 100 points\n\nProblem Statement\n\nHow many multiples of d are there among the integers between L and R (inclusive)?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq L \\leq R \\leq 100\n\n1 \\leq d \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL R d\n\nOutput\n\nPrint the number of multiples of d among the integers between L and R (inclusive).\n\nSample Input 1\n\n5 10 2\n\nSample Output 1\n\n3\n\nAmong the integers between 5 and 10, there are three multiples of 2: 6, 8, and 10.\n\nSample Input 2\n\n6 20 7\n\nSample Output 2\n\n2\n\nAmong the integers between 6 and 20, there are two multiples of 7: 7 and 14.\n\nSample Input 3\n\n1 100 1\n\nSample Output 3\n\n100", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 24348}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s591130790", "group_id": "codeNet:p02606", "input_text": "(let ((l (read))\n (r (read))\n (d (read)))\n (format t \"~A~%\"\n (loop for i from l to r\n when (zerop (mod i d))\n count t)))", "language": "Lisp", "metadata": {"date": 1594516024, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02606.html", "problem_id": "p02606", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02606/input.txt", "sample_output_relpath": "derived/input_output/data/p02606/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02606/Lisp/s591130790.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s591130790", "user_id": "u607637432"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((l (read))\n (r (read))\n (d (read)))\n (format t \"~A~%\"\n (loop for i from l to r\n when (zerop (mod i d))\n count t)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nHow many multiples of d are there among the integers between L and R (inclusive)?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq L \\leq R \\leq 100\n\n1 \\leq d \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL R d\n\nOutput\n\nPrint the number of multiples of d among the integers between L and R (inclusive).\n\nSample Input 1\n\n5 10 2\n\nSample Output 1\n\n3\n\nAmong the integers between 5 and 10, there are three multiples of 2: 6, 8, and 10.\n\nSample Input 2\n\n6 20 7\n\nSample Output 2\n\n2\n\nAmong the integers between 6 and 20, there are two multiples of 7: 7 and 14.\n\nSample Input 3\n\n1 100 1\n\nSample Output 3\n\n100", "sample_input": "5 10 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02606", "source_text": "Score : 100 points\n\nProblem Statement\n\nHow many multiples of d are there among the integers between L and R (inclusive)?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq L \\leq R \\leq 100\n\n1 \\leq d \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL R d\n\nOutput\n\nPrint the number of multiples of d among the integers between L and R (inclusive).\n\nSample Input 1\n\n5 10 2\n\nSample Output 1\n\n3\n\nAmong the integers between 5 and 10, there are three multiples of 2: 6, 8, and 10.\n\nSample Input 2\n\n6 20 7\n\nSample Output 2\n\n2\n\nAmong the integers between 6 and 20, there are two multiples of 7: 7 and 14.\n\nSample Input 3\n\n1 100 1\n\nSample Output 3\n\n100", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 24488}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s927504535", "group_id": "codeNet:p02607", "input_text": "(let ((n (read))\n (ans 0))\n (loop :for i :from 1 :to n\n :for a := (read)\n :if (and (oddp i) (oddp a))\n :do (incf ans))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1594515862, "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/s927504535.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s927504535", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((n (read))\n (ans 0))\n (loop :for i :from 1 :to n\n :for a := (read)\n :if (and (oddp i) (oddp a))\n :do (incf ans))\n (format t \"~A~%\" 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 171, "cpu_time_ms": 20, "memory_kb": 24476}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s258137406", "group_id": "codeNet:p02607", "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 (lst)\n (loop for i in lst\n for j from 1\n when (and (oddp j)\n (oddp i))\n sum 1))\n\n(princ\n (main (read-times (read))))\n", "language": "Lisp", "metadata": {"date": 1594515759, "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/s258137406.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s258137406", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\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 (lst)\n (loop for i in lst\n for j from 1\n when (and (oddp j)\n (oddp i))\n sum 1))\n\n(princ\n (main (read-times (read))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5939, "cpu_time_ms": 32, "memory_kb": 25696}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s707202897", "group_id": "codeNet:p02608", "input_text": "(let* ((n (read))\n (ans (make-array (+ n 1) :initial-element 0)))\n\n (loop for x from 1 to n do\n (loop for y from 1 to n do\n (loop for z from 1 to n do\n (if (<= (+ (expt x 2) (expt y 2) (expt z 2) (* x y) (* y z) (* z x)) n)\n (incf (aref ans (+ (expt x 2) (expt y 2) (expt z 2) (* x y) (* y z) (* z x))))\n )\n )\n )\n )\n (loop for i from 1 to n do\n (format t \"~D~%\" (aref ans i))\n )\n\n\n)", "language": "Lisp", "metadata": {"date": 1594526134, "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/s707202897.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s707202897", "user_id": "u136500538"}, "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": "(let* ((n (read))\n (ans (make-array (+ n 1) :initial-element 0)))\n\n (loop for x from 1 to n do\n (loop for y from 1 to n do\n (loop for z from 1 to n do\n (if (<= (+ (expt x 2) (expt y 2) (expt z 2) (* x y) (* y z) (* z x)) n)\n (incf (aref ans (+ (expt x 2) (expt y 2) (expt z 2) (* x y) (* y z) (* z x))))\n )\n )\n )\n )\n (loop for i from 1 to n do\n (format t \"~D~%\" (aref ans i))\n )\n\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 489, "cpu_time_ms": 2206, "memory_kb": 24436}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s514598411", "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 (floor (sqrt (- n (calc x y 0))))\n for r = (calc x y z)\n while (>= n r)\n when (= n r)\n do (incf result)))\n finally (return (* result 2))))\n\n(let ((n (read)))\n (loop for i from 1 to n\n do (format t \"~A~%\" (f i))))", "language": "Lisp", "metadata": {"date": 1594519475, "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/s514598411.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s514598411", "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 (floor (sqrt (- n (calc x y 0))))\n for r = (calc x y z)\n while (>= n r)\n when (= n r)\n do (incf result)))\n finally (return (* result 2))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1021, "cpu_time_ms": 1187, "memory_kb": 24328}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s745509859", "group_id": "codeNet:p02609", "input_text": "(defun f (x)\n (let ((acc 0))\n (loop :while (< 0 x)\n :do (setf x (mod x (logcount x)))\n :do (incf acc))\n acc))\n\n(let* ((n (read))\n (s (read-line))\n (x (parse-integer s :radix 2))\n (p (logcount x))\n (2+ (make-array (list n)))\n (2- (make-array (list n)))\n (y+ 0)\n (y- 0))\n (setf (aref 2+ 0) (mod 1 (1+ p)))\n (loop :for i :from 1 :to (1- n)\n :do (setf (aref 2+ i) (mod (* (aref 2+ (1- i)) 2) (1+ p))))\n (setf y+ (mod x (1+ p)))\n (when (/= p 1)\n (setf (aref 2- 0) (mod 1 (1- p)))\n (loop :for i :from 1 :to (1- n)\n :do (setf (aref 2- i) (mod (* (aref 2- (1- i)) 2) (1- p))))\n (setf y- (mod x (1- p))))\n (format t\n \"~{~A~%~}\" \n (loop :for i :from 0 :to (1- n)\n :for j :downfrom (1- n) :to 0\n :collect (cond ((and (char= (aref s i) #\\1) (= p 1))\n 0)\n ((char= (aref s i) #\\1)\n (1+ (f (mod (- y- (mod (aref 2- j) (1- p))) (1- p)))))\n (t\n (1+ (f (mod (+ y+ (mod (aref 2+ j) (1+ p))) (1+ p)))))))))\n", "language": "Lisp", "metadata": {"date": 1594532091, "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/s745509859.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s745509859", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n1\n1\n", "input_to_evaluate": "(defun f (x)\n (let ((acc 0))\n (loop :while (< 0 x)\n :do (setf x (mod x (logcount x)))\n :do (incf acc))\n acc))\n\n(let* ((n (read))\n (s (read-line))\n (x (parse-integer s :radix 2))\n (p (logcount x))\n (2+ (make-array (list n)))\n (2- (make-array (list n)))\n (y+ 0)\n (y- 0))\n (setf (aref 2+ 0) (mod 1 (1+ p)))\n (loop :for i :from 1 :to (1- n)\n :do (setf (aref 2+ i) (mod (* (aref 2+ (1- i)) 2) (1+ p))))\n (setf y+ (mod x (1+ p)))\n (when (/= p 1)\n (setf (aref 2- 0) (mod 1 (1- p)))\n (loop :for i :from 1 :to (1- n)\n :do (setf (aref 2- i) (mod (* (aref 2- (1- i)) 2) (1- p))))\n (setf y- (mod x (1- p))))\n (format t\n \"~{~A~%~}\" \n (loop :for i :from 0 :to (1- n)\n :for j :downfrom (1- n) :to 0\n :collect (cond ((and (char= (aref s i) #\\1) (= p 1))\n 0)\n ((char= (aref s i) #\\1)\n (1+ (f (mod (- y- (mod (aref 2- j) (1- p))) (1- p)))))\n (t\n (1+ (f (mod (+ y+ (mod (aref 2+ j) (1+ p))) (1+ p)))))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1185, "cpu_time_ms": 2210, "memory_kb": 128696}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s350503112", "group_id": "codeNet:p02609", "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 log2-int (str)\n (loop for i across str\n with res = 0\n do\n (progn\n (setf res (ash res 1))\n (incf res (- (char-code i) (char-code #\\0))))\n finally (return res)))\n\n(defun pop-count (x)\n (labels ((f (x)\n (if (zerop x)\n 0\n (+ (if (oddp x) 1 0)\n (f (ash x -1))))))\n (f x)))\n\n\n(defun func (x)\n (labels ((f (x)\n (if (zerop x) 0\n (1+ (f (mod x (pop-count x)))))))\n (f x)))\n\n(defun main (n str)\n (let* ((pop-num (count #\\1 str))\n (num (log2-int str))\n (divide-by-up (mod num (1+ pop-num)))\n (divide-by-down (if (>= pop-num 2)\n (mod num (1- pop-num))\n num)))\n (reverse\n (loop for char across (reverse str)\n for i below n\n with pows-up = 1\n with pows-down = (if (= pop-num 2) 0 1)\n when (char= char #\\0)\n collect\n (1+ (func (mod (+ divide-by-up pows-up)\n (1+ pop-num))))\n when (char= char #\\1)\n collect\n (if (= pop-num 1)\n 0\n (1+ (func (mod (- divide-by-down pows-down)\n (1- pop-num)))))\n do\n (progn\n (setf pows-up (mod (ash pows-up 1) (1+ pop-num)))\n (when (>= pop-num 2)\n (setf pows-down (mod (ash pows-down 1) (1- pop-num)))))))))\n\n\n(format\n t\n \"~{~a~%~}\"\n (main (read) (read-line)))\n\n", "language": "Lisp", "metadata": {"date": 1594518960, "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/s350503112.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s350503112", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\n1\n1\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 log2-int (str)\n (loop for i across str\n with res = 0\n do\n (progn\n (setf res (ash res 1))\n (incf res (- (char-code i) (char-code #\\0))))\n finally (return res)))\n\n(defun pop-count (x)\n (labels ((f (x)\n (if (zerop x)\n 0\n (+ (if (oddp x) 1 0)\n (f (ash x -1))))))\n (f x)))\n\n\n(defun func (x)\n (labels ((f (x)\n (if (zerop x) 0\n (1+ (f (mod x (pop-count x)))))))\n (f x)))\n\n(defun main (n str)\n (let* ((pop-num (count #\\1 str))\n (num (log2-int str))\n (divide-by-up (mod num (1+ pop-num)))\n (divide-by-down (if (>= pop-num 2)\n (mod num (1- pop-num))\n num)))\n (reverse\n (loop for char across (reverse str)\n for i below n\n with pows-up = 1\n with pows-down = (if (= pop-num 2) 0 1)\n when (char= char #\\0)\n collect\n (1+ (func (mod (+ divide-by-up pows-up)\n (1+ pop-num))))\n when (char= char #\\1)\n collect\n (if (= pop-num 1)\n 0\n (1+ (func (mod (- divide-by-down pows-down)\n (1- pop-num)))))\n do\n (progn\n (setf pows-up (mod (ash pows-up 1) (1+ pop-num)))\n (when (>= pop-num 2)\n (setf pows-down (mod (ash pows-down 1) (1- pop-num)))))))))\n\n\n(format\n t\n \"~{~a~%~}\"\n (main (read) (read-line)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7353, "cpu_time_ms": 2206, "memory_kb": 129740}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s617666814", "group_id": "codeNet:p02615", "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 (as (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (setq as (sort as #'>))\n (let ((pos 0)\n (rest (- n 1))\n (res 0))\n (loop while (> rest 0)\n do (cond ((= pos 0)\n (incf res (aref as 0))\n (decf rest))\n ((= rest 1)\n (incf res (aref as pos))\n (decf rest))\n (t (incf res (* 2 (aref as pos)))\n (decf rest 2)))\n (incf 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 #+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\n2 2 1 3\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n1 1 1 1 1 1 1\n\"\n \"6\n\")))\n", "language": "Lisp", "metadata": {"date": 1594023240, "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/s617666814.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s617666814", "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 #\\# #\\> (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 (as (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (setq as (sort as #'>))\n (let ((pos 0)\n (rest (- n 1))\n (res 0))\n (loop while (> rest 0)\n do (cond ((= pos 0)\n (incf res (aref as 0))\n (decf rest))\n ((= rest 1)\n (incf res (aref as pos))\n (decf rest))\n (t (incf res (* 2 (aref as pos)))\n (decf rest 2)))\n (incf 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 #+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\n2 2 1 3\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n1 1 1 1 1 1 1\n\"\n \"6\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5374, "cpu_time_ms": 164, "memory_kb": 25852}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s917318969", "group_id": "codeNet:p02615", "input_text": "(let* ((n (read))\n (a (make-array `(,n) :initial-element 0))\n (ans 0))\n (loop :for i :from 1 :to n\n :do (setf (aref a (1- i)) (read)))\n ;;\n (setf a (sort a #'>))\n ;;\n (incf ans (aref a 0))\n ;;\n (loop :for i :from 1 :to (floor (/ (- n 2) 2))\n :do (incf ans (* 2 (aref a i))))\n (when (oddp (- n 2))\n (incf ans (aref a (ceiling (/ (- n 2) 2)))))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1594001134, "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/s917318969.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s917318969", "user_id": "u608227593"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(let* ((n (read))\n (a (make-array `(,n) :initial-element 0))\n (ans 0))\n (loop :for i :from 1 :to n\n :do (setf (aref a (1- i)) (read)))\n ;;\n (setf a (sort a #'>))\n ;;\n (incf ans (aref a 0))\n ;;\n (loop :for i :from 1 :to (floor (/ (- n 2) 2))\n :do (incf ans (* 2 (aref a i))))\n (when (oddp (- n 2))\n (incf ans (aref a (ceiling (/ (- n 2) 2)))))\n (format t \"~A~%\" ans))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 405, "cpu_time_ms": 309, "memory_kb": 78872}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s392710323", "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 ((res 0)\n ;; (maxlog most-negative-double-float))\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 (> (- log 1d-10) maxlog)\n ;; (setq maxlog log\n ;; res (mod* (aref cumuls+ d+) (aref cumuls- d-)))))))\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\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": 1594005293, "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/s392710323.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s392710323", "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 ((res 0)\n ;; (maxlog most-negative-double-float))\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 (> (- log 1d-10) maxlog)\n ;; (setq maxlog log\n ;; res (mod* (aref cumuls+ d+) (aref cumuls- d-)))))))\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\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9221, "cpu_time_ms": 436, "memory_kb": 32084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s714708992", "group_id": "codeNet:p02616", "input_text": "(defun main ()\n (let* ((n (read))\n (k (read))\n (a (make-array (list n)))\n (mx 0)\n (my 0)\n (s 0)\n (z 0)\n (x 1)\n (pe nil)\n (y 1)\n (_ (+ (expt 10 9) 7)))\n ;\n (loop :for i :from 0 :to n\n :do (let ((w (read)))\n (setf (aref a i) w)\n (if (= w 0) (incf z))))\n ;\n (when (> k (- n z))\n (format t \"0~%\")\n (return-from main))\n \n (setf a (sort a (lambda (a b) (> (abs a) (abs b)))))\n (loop :with i := 0\n :with j := 0\n :while (< j k)\n :if (/= (aref a i) 0)\n :do (progn\n (when (< (aref a i) 0)\n (incf mx))\n (setf x (mod (* x (abs (aref a i))) _))\n (incf j))\n :do (incf i))\n (loop :with i := 0\n :with j := 0\n :while (< j k)\n :if (/= (aref a (- (1- n) i)) 0)\n :do (progn\n (when (< (aref a (- (1- n) i)) 0)\n (incf my))\n (setf y (mod (* y (abs (aref a (- (1- n) i)))) _))\n (setf s i)\n (incf j))\n :do (incf i))\n \n (loop :named foo\n :for i :from (1+ s) :to (1- n)\n :if (> (aref a i) 0)\n :do (progn\n (setf pe (aref a i))\n (return-from foo)))\n \n (cond ((evenp mx)\n (format t \"~A~%\" x))\n (pe\n (let ((mm))\n (loop :named foo\n :for i :from s :downto 0\n :if (< (aref a i) 0)\n :do (progn\n (setf mm (aref a i))\n (return-from foo))) \n (setf mm (mod (expt mm (- _ 2)) _))\n (format t \"~A~%\" (mod (* (mod (* x pe) _) mm) _))))\n (t\n (format t \"~A~%\" y)))))\n(main)\n", "language": "Lisp", "metadata": {"date": 1593981520, "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/s714708992.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s714708992", "user_id": "u608227593"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(defun main ()\n (let* ((n (read))\n (k (read))\n (a (make-array (list n)))\n (mx 0)\n (my 0)\n (s 0)\n (z 0)\n (x 1)\n (pe nil)\n (y 1)\n (_ (+ (expt 10 9) 7)))\n ;\n (loop :for i :from 0 :to n\n :do (let ((w (read)))\n (setf (aref a i) w)\n (if (= w 0) (incf z))))\n ;\n (when (> k (- n z))\n (format t \"0~%\")\n (return-from main))\n \n (setf a (sort a (lambda (a b) (> (abs a) (abs b)))))\n (loop :with i := 0\n :with j := 0\n :while (< j k)\n :if (/= (aref a i) 0)\n :do (progn\n (when (< (aref a i) 0)\n (incf mx))\n (setf x (mod (* x (abs (aref a i))) _))\n (incf j))\n :do (incf i))\n (loop :with i := 0\n :with j := 0\n :while (< j k)\n :if (/= (aref a (- (1- n) i)) 0)\n :do (progn\n (when (< (aref a (- (1- n) i)) 0)\n (incf my))\n (setf y (mod (* y (abs (aref a (- (1- n) i)))) _))\n (setf s i)\n (incf j))\n :do (incf i))\n \n (loop :named foo\n :for i :from (1+ s) :to (1- n)\n :if (> (aref a i) 0)\n :do (progn\n (setf pe (aref a i))\n (return-from foo)))\n \n (cond ((evenp mx)\n (format t \"~A~%\" x))\n (pe\n (let ((mm))\n (loop :named foo\n :for i :from s :downto 0\n :if (< (aref a i) 0)\n :do (progn\n (setf mm (aref a i))\n (return-from foo))) \n (setf mm (mod (expt mm (- _ 2)) _))\n (format t \"~A~%\" (mod (* (mod (* x pe) _) mm) _))))\n (t\n (format t \"~A~%\" y)))))\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1879, "cpu_time_ms": 274, "memory_kb": 77988}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s485757793", "group_id": "codeNet:p02617", "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 (res (floor (* n (+ n 1) (+ n 2)) 6)))\n #>res\n #>n\n (dotimes (i (- n 1))\n (let ((u (read-fixnum))\n (v (read-fixnum)))\n (when (> u v)\n (rotatef u v))\n (decf res (* u (+ 1 (- n v))))))\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 \"3\n1 3\n2 3\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n5 3\n5 7\n8 9\n1 9\n9 10\n8 4\n7 4\n6 10\n7 2\n\"\n \"113\n\")))\n", "language": "Lisp", "metadata": {"date": 1594013244, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02617.html", "problem_id": "p02617", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02617/input.txt", "sample_output_relpath": "derived/input_output/data/p02617/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02617/Lisp/s485757793.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s485757793", "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 #\\# #\\> (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 (res (floor (* n (+ n 1) (+ n 2)) 6)))\n #>res\n #>n\n (dotimes (i (- n 1))\n (let ((u (read-fixnum))\n (v (read-fixnum)))\n (when (> u v)\n (rotatef u v))\n (decf res (* u (+ 1 (- n v))))))\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 \"3\n1 3\n2 3\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n5 3\n5 7\n8 9\n1 9\n9 10\n8 4\n7 4\n6 10\n7 2\n\"\n \"113\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\\cdots, N and 1, 2, \\cdots, N-1. Edge i connects Vertex u_i and v_i.\n\nFor integers L, R (1 \\leq L \\leq R \\leq N), let us define a function f(L, R) as follows:\n\nLet S be the set of the vertices numbered L through R. f(L, R) represents the number of connected components in the subgraph formed only from the vertex set S and the edges whose endpoints both belong to S.\n\nCompute \\sum_{L=1}^{N} \\sum_{R=L}^{N} f(L, R).\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq u_i, v_i \\leq N\n\nThe given graph is a tree.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nu_1 v_1\nu_2 v_2\n:\nu_{N-1} v_{N-1}\n\nOutput\n\nPrint \\sum_{L=1}^{N} \\sum_{R=L}^{N} f(L, R).\n\nSample Input 1\n\n3\n1 3\n2 3\n\nSample Output 1\n\n7\n\nWe have six possible pairs (L, R) as follows:\n\nFor L = 1, R = 1, S = \\{1\\} and we have 1 connected component.\n\nFor L = 1, R = 2, S = \\{1, 2\\} and we have 2 connected components.\n\nFor L = 1, R = 3, S = \\{1, 2, 3\\} and we have 1 connected component, since S contains both endpoints of each of the edges 1, 2.\n\nFor L = 2, R = 2, S = \\{2\\} and we have 1 connected component.\n\nFor L = 2, R = 3, S = \\{2, 3\\} and we have 1 connected component, since S contains both endpoints of Edge 2.\n\nFor L = 3, R = 3, S = \\{3\\} and we have 1 connected component.\n\nThe sum of these is 7.\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n5 3\n5 7\n8 9\n1 9\n9 10\n8 4\n7 4\n6 10\n7 2\n\nSample Output 3\n\n113", "sample_input": "3\n1 3\n2 3\n"}, "reference_outputs": ["7\n"], "source_document_id": "p02617", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\\cdots, N and 1, 2, \\cdots, N-1. Edge i connects Vertex u_i and v_i.\n\nFor integers L, R (1 \\leq L \\leq R \\leq N), let us define a function f(L, R) as follows:\n\nLet S be the set of the vertices numbered L through R. f(L, R) represents the number of connected components in the subgraph formed only from the vertex set S and the edges whose endpoints both belong to S.\n\nCompute \\sum_{L=1}^{N} \\sum_{R=L}^{N} f(L, R).\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq u_i, v_i \\leq N\n\nThe given graph is a tree.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nu_1 v_1\nu_2 v_2\n:\nu_{N-1} v_{N-1}\n\nOutput\n\nPrint \\sum_{L=1}^{N} \\sum_{R=L}^{N} f(L, R).\n\nSample Input 1\n\n3\n1 3\n2 3\n\nSample Output 1\n\n7\n\nWe have six possible pairs (L, R) as follows:\n\nFor L = 1, R = 1, S = \\{1\\} and we have 1 connected component.\n\nFor L = 1, R = 2, S = \\{1, 2\\} and we have 2 connected components.\n\nFor L = 1, R = 3, S = \\{1, 2, 3\\} and we have 1 connected component, since S contains both endpoints of each of the edges 1, 2.\n\nFor L = 2, R = 2, S = \\{2\\} and we have 1 connected component.\n\nFor L = 2, R = 3, S = \\{2, 3\\} and we have 1 connected component, since S contains both endpoints of Edge 2.\n\nFor L = 3, R = 3, S = \\{3\\} and we have 1 connected component.\n\nThe sum of these is 7.\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n3\n\nSample Input 3\n\n10\n5 3\n5 7\n8 9\n1 9\n9 10\n8 4\n7 4\n6 10\n7 2\n\nSample Output 3\n\n113", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 55, "memory_kb": 25144}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s372201643", "group_id": "codeNet:p02619", "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* ((d (read))\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 (prevs (make-array 26 :element-type 'int32 :initial-element -1)))\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 (let ((res 0))\n (dotimes (i d)\n (let ((type (- (read-fixnum) 1)))\n (incf res (aref ss i type))\n (setf (aref prevs type) i)\n (dotimes (j 26)\n (decf res (* (aref cs j) (- i (aref prevs j)))))\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 \"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\"\n \"18398\n35037\n51140\n65837\n79325\n\")))\n", "language": "Lisp", "metadata": {"date": 1593411964, "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/s372201643.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s372201643", "user_id": "u352600849"}, "prompt_components": {"gold_output": "18398\n35037\n51140\n65837\n79325\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* ((d (read))\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 (prevs (make-array 26 :element-type 'int32 :initial-element -1)))\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 (let ((res 0))\n (dotimes (i d)\n (let ((type (- (read-fixnum) 1)))\n (incf res (aref ss i type))\n (setf (aref prevs type) i)\n (dotimes (j 26)\n (decf res (* (aref cs j) (- i (aref prevs j)))))\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 \"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\"\n \"18398\n35037\n51140\n65837\n79325\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6057, "cpu_time_ms": 19, "memory_kb": 25000}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s270115878", "group_id": "codeNet:p02621", "input_text": "\n(defun solve (x)\n (+ (+ (* x x) (* (* x x) x)) x)\n )\n\n(princ (solve (read)))", "language": "Lisp", "metadata": {"date": 1594766450, "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/s270115878.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s270115878", "user_id": "u765865533"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": "\n(defun solve (x)\n (+ (+ (* x x) (* (* x x) x)) x)\n )\n\n(princ (solve (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 79, "cpu_time_ms": 19, "memory_kb": 24196}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s237362953", "group_id": "codeNet:p02621", "input_text": "(defun main ()\n (let ((a (read)))\n (+ a (expt a 2) (expt a 3))))\n\n(format t \"~a~%\" (main))\n", "language": "Lisp", "metadata": {"date": 1593306414, "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/s237362953.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s237362953", "user_id": "u091381267"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": "(defun main ()\n (let ((a (read)))\n (+ a (expt a 2) (expt a 3))))\n\n(format t \"~a~%\" (main))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 95, "cpu_time_ms": 15, "memory_kb": 24376}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s547557176", "group_id": "codeNet:p02622", "input_text": "(let ((s1 (read-line))\n (s2 (read-line)))\n (format t \"~A~%\" (loop for c1 across s1\n for c2 across s2\n count (not (eql c1 c2)))))\n", "language": "Lisp", "metadata": {"date": 1593306488, "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/s547557176.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s547557176", "user_id": "u607637432"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((s1 (read-line))\n (s2 (read-line)))\n (format t \"~A~%\" (loop for c1 across s1\n for c2 across s2\n count (not (eql c1 c2)))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 44, "memory_kb": 29692}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s505156701", "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 1) 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 \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": 1593333238, "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/s505156701.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s505156701", "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 1) 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 \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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5908, "cpu_time_ms": 21, "memory_kb": 25164}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s487705044", "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 (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 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": 1593332658, "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/s487705044.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s487705044", "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 (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 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5903, "cpu_time_ms": 17, "memory_kb": 25064}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s277105264", "group_id": "codeNet:p02627", "input_text": "(defun input ()\n (coerce (read-line) 'character))\n\n(defun cap? (code)\n (cond ((< code 91) t)\n\t\t(t nil)))\n\n(defun main ()\n (let* ((chr (input))\n\t\t(code (char-code chr)))\n\t(if (cap? code)\n\t (format t \"A~%\")\n\t (format t \"a~%\")\n\t )))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1593346979, "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/s277105264.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s277105264", "user_id": "u735896835"}, "prompt_components": {"gold_output": "A\n", "input_to_evaluate": "(defun input ()\n (coerce (read-line) 'character))\n\n(defun cap? (code)\n (cond ((< code 91) t)\n\t\t(t nil)))\n\n(defun main ()\n (let* ((chr (input))\n\t\t(code (char-code chr)))\n\t(if (cap? code)\n\t (format t \"A~%\")\n\t (format t \"a~%\")\n\t )))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 244, "cpu_time_ms": 16, "memory_kb": 23552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s532540467", "group_id": "codeNet:p02627", "input_text": "(defun app ()\n (let* ((a (string (read-char)))\n (num (char-code (coerce a 'character))))\n\n (if (> 96 num)\n (format t \"A\")\n (format t \"~(a~)\")\n )\n )\n)\n(app )\n", "language": "Lisp", "metadata": {"date": 1592794644, "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/s532540467.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s532540467", "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 (> 96 num)\n (format t \"A\")\n (format t \"~(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 20, "memory_kb": 23376}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s242172300", "group_id": "codeNet:p02627", "input_text": "(defun letter-check (string)\n (string= (string-upcase string) string)\n )\n\n(defun solve (string)\n (if (letter-check string)\n (princ \"A\")\n (princ \"a\")\n )\n)\n (solve (read))", "language": "Lisp", "metadata": {"date": 1592788580, "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/s242172300.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s242172300", "user_id": "u765865533"}, "prompt_components": {"gold_output": "A\n", "input_to_evaluate": "(defun letter-check (string)\n (string= (string-upcase string) string)\n )\n\n(defun solve (string)\n (if (letter-check string)\n (princ \"A\")\n (princ \"a\")\n )\n)\n (solve (read))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 20, "memory_kb": 23620}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s987846368", "group_id": "codeNet:p02629", "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 (sb-int:named-let dfs ((x (- n 1)) (res nil))\n (if (<= 0 x 25)\n (loop for d in (cons x res)\n do (write-char (code-char (+ 97 d)))\n finally (terpri))\n (multiple-value-bind (quot rem) (floor x 26)\n (dfs (- quot 1) (cons rem 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\n\"\n \"b\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"27\n\"\n \"aa\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"123456789\n\"\n \"jjddja\n\")))\n", "language": "Lisp", "metadata": {"date": 1592791060, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02629.html", "problem_id": "p02629", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02629/input.txt", "sample_output_relpath": "derived/input_output/data/p02629/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02629/Lisp/s987846368.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s987846368", "user_id": "u352600849"}, "prompt_components": {"gold_output": "b\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 (sb-int:named-let dfs ((x (- n 1)) (res nil))\n (if (<= 0 x 25)\n (loop for d in (cons x res)\n do (write-char (code-char (+ 97 d)))\n finally (terpri))\n (multiple-value-bind (quot rem) (floor x 26)\n (dfs (- quot 1) (cons rem 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\n\"\n \"b\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"27\n\"\n \"aa\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"123456789\n\"\n \"jjddja\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\n1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:\n\nthe dogs numbered 1,2,\\cdots,26 were respectively given the names a, b, ..., z;\n\nthe dogs numbered 27,28,29,\\cdots,701,702 were respectively given the names aa, ab, ac, ..., zy, zz;\n\nthe dogs numbered 703,704,705,\\cdots,18277,18278 were respectively given the names aaa, aab, aac, ..., zzy, zzz;\n\nthe dogs numbered 18279,18280,18281,\\cdots,475253,475254 were respectively given the names aaaa, aaab, aaac, ..., zzzy, zzzz;\n\nthe dogs numbered 475255,475256,\\cdots were respectively given the names aaaaa, aaaab, ...;\n\nand so on.\n\nTo sum it up, the dogs numbered 1, 2, \\cdots were respectively given the following names:\n\na, b, ..., z, aa, ab, ..., az, ba, bb, ..., bz, ..., za, zb, ..., zz, aaa, aab, ..., aaz, aba, abb, ..., abz, ..., zzz, aaaa, ...\n\nNow, Roger asks you:\n\n\"What is the name for the dog numbered N?\"\n\nConstraints\n\nN is an integer.\n\n1 \\leq N \\leq 1000000000000001\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer to Roger's question as a string consisting of lowercase English letters.\n\nSample Input 1\n\n2\n\nSample Output 1\n\nb\n\nSample Input 2\n\n27\n\nSample Output 2\n\naa\n\nSample Input 3\n\n123456789\n\nSample Output 3\n\njjddja", "sample_input": "2\n"}, "reference_outputs": ["b\n"], "source_document_id": "p02629", "source_text": "Score : 300 points\n\nProblem Statement\n\n1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:\n\nthe dogs numbered 1,2,\\cdots,26 were respectively given the names a, b, ..., z;\n\nthe dogs numbered 27,28,29,\\cdots,701,702 were respectively given the names aa, ab, ac, ..., zy, zz;\n\nthe dogs numbered 703,704,705,\\cdots,18277,18278 were respectively given the names aaa, aab, aac, ..., zzy, zzz;\n\nthe dogs numbered 18279,18280,18281,\\cdots,475253,475254 were respectively given the names aaaa, aaab, aaac, ..., zzzy, zzzz;\n\nthe dogs numbered 475255,475256,\\cdots were respectively given the names aaaaa, aaaab, ...;\n\nand so on.\n\nTo sum it up, the dogs numbered 1, 2, \\cdots were respectively given the following names:\n\na, b, ..., z, aa, ab, ..., az, ba, bb, ..., bz, ..., za, zb, ..., zz, aaa, aab, ..., aaz, aba, abb, ..., abz, ..., zzz, aaaa, ...\n\nNow, Roger asks you:\n\n\"What is the name for the dog numbered N?\"\n\nConstraints\n\nN is an integer.\n\n1 \\leq N \\leq 1000000000000001\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer to Roger's question as a string consisting of lowercase English letters.\n\nSample Input 1\n\n2\n\nSample Output 1\n\nb\n\nSample Input 2\n\n27\n\nSample Output 2\n\naa\n\nSample Input 3\n\n123456789\n\nSample Output 3\n\njjddja", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3870, "cpu_time_ms": 21, "memory_kb": 23884}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s557919000", "group_id": "codeNet:p02629", "input_text": "(defun get-length (n m)\n (if (<= (expt 26 (1- m)) n (expt 26 m))\n m\n (get-length n (1+ m))))\n\n(let* ((n (read))\n (l (get-length n 1))\n (min (/ (1- (expt 26 l)) 25))\n (m (- n min)))\n (loop :for i :from l :downto 1\n :do (multiple-value-bind (x y) (floor m (expt 26 (1- i)))\n (format t \"~A\" (code-char (+ 97 x)))\n (setf m y))))\n(format t \"~%\")\n", "language": "Lisp", "metadata": {"date": 1592790381, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02629.html", "problem_id": "p02629", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02629/input.txt", "sample_output_relpath": "derived/input_output/data/p02629/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02629/Lisp/s557919000.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s557919000", "user_id": "u608227593"}, "prompt_components": {"gold_output": "b\n", "input_to_evaluate": "(defun get-length (n m)\n (if (<= (expt 26 (1- m)) n (expt 26 m))\n m\n (get-length n (1+ m))))\n\n(let* ((n (read))\n (l (get-length n 1))\n (min (/ (1- (expt 26 l)) 25))\n (m (- n min)))\n (loop :for i :from l :downto 1\n :do (multiple-value-bind (x y) (floor m (expt 26 (1- i)))\n (format t \"~A\" (code-char (+ 97 x)))\n (setf m y))))\n(format t \"~%\")\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\n1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:\n\nthe dogs numbered 1,2,\\cdots,26 were respectively given the names a, b, ..., z;\n\nthe dogs numbered 27,28,29,\\cdots,701,702 were respectively given the names aa, ab, ac, ..., zy, zz;\n\nthe dogs numbered 703,704,705,\\cdots,18277,18278 were respectively given the names aaa, aab, aac, ..., zzy, zzz;\n\nthe dogs numbered 18279,18280,18281,\\cdots,475253,475254 were respectively given the names aaaa, aaab, aaac, ..., zzzy, zzzz;\n\nthe dogs numbered 475255,475256,\\cdots were respectively given the names aaaaa, aaaab, ...;\n\nand so on.\n\nTo sum it up, the dogs numbered 1, 2, \\cdots were respectively given the following names:\n\na, b, ..., z, aa, ab, ..., az, ba, bb, ..., bz, ..., za, zb, ..., zz, aaa, aab, ..., aaz, aba, abb, ..., abz, ..., zzz, aaaa, ...\n\nNow, Roger asks you:\n\n\"What is the name for the dog numbered N?\"\n\nConstraints\n\nN is an integer.\n\n1 \\leq N \\leq 1000000000000001\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer to Roger's question as a string consisting of lowercase English letters.\n\nSample Input 1\n\n2\n\nSample Output 1\n\nb\n\nSample Input 2\n\n27\n\nSample Output 2\n\naa\n\nSample Input 3\n\n123456789\n\nSample Output 3\n\njjddja", "sample_input": "2\n"}, "reference_outputs": ["b\n"], "source_document_id": "p02629", "source_text": "Score : 300 points\n\nProblem Statement\n\n1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:\n\nthe dogs numbered 1,2,\\cdots,26 were respectively given the names a, b, ..., z;\n\nthe dogs numbered 27,28,29,\\cdots,701,702 were respectively given the names aa, ab, ac, ..., zy, zz;\n\nthe dogs numbered 703,704,705,\\cdots,18277,18278 were respectively given the names aaa, aab, aac, ..., zzy, zzz;\n\nthe dogs numbered 18279,18280,18281,\\cdots,475253,475254 were respectively given the names aaaa, aaab, aaac, ..., zzzy, zzzz;\n\nthe dogs numbered 475255,475256,\\cdots were respectively given the names aaaaa, aaaab, ...;\n\nand so on.\n\nTo sum it up, the dogs numbered 1, 2, \\cdots were respectively given the following names:\n\na, b, ..., z, aa, ab, ..., az, ba, bb, ..., bz, ..., za, zb, ..., zz, aaa, aab, ..., aaz, aba, abb, ..., abz, ..., zzz, aaaa, ...\n\nNow, Roger asks you:\n\n\"What is the name for the dog numbered N?\"\n\nConstraints\n\nN is an integer.\n\n1 \\leq N \\leq 1000000000000001\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the answer to Roger's question as a string consisting of lowercase English letters.\n\nSample Input 1\n\n2\n\nSample Output 1\n\nb\n\nSample Input 2\n\n27\n\nSample Output 2\n\naa\n\nSample Input 3\n\n123456789\n\nSample Output 3\n\njjddja", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 404, "cpu_time_ms": 23, "memory_kb": 24656}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s557721512", "group_id": "codeNet:p02631", "input_text": "(defun red-scarf(n a)\n (let* ((total_xor (reduce #'logxor a)))\n (loop for i from 0 below n\n collect (logxor (aref a i) total_xor))))\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 ~}~%\" (red-scarf n a)))\n \n", "language": "Lisp", "metadata": {"date": 1593180359, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02631.html", "problem_id": "p02631", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02631/input.txt", "sample_output_relpath": "derived/input_output/data/p02631/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02631/Lisp/s557721512.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s557721512", "user_id": "u324761590"}, "prompt_components": {"gold_output": "26 5 7 22\n", "input_to_evaluate": "(defun red-scarf(n a)\n (let* ((total_xor (reduce #'logxor a)))\n (loop for i from 0 below n\n collect (logxor (aref a i) total_xor))))\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 ~}~%\" (red-scarf n a)))\n \n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N Snuke Cats numbered 1, 2, \\ldots, N, where N is even.\n\nEach Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.\n\nRecently, they learned the operation called xor (exclusive OR).\n\nWhat is xor?\n\nFor n non-negative integers x_1, x_2, \\ldots, x_n, their xor, x_1~\\textrm{xor}~x_2~\\textrm{xor}~\\ldots~\\textrm{xor}~x_n is defined as follows:\n\nWhen x_1~\\textrm{xor}~x_2~\\textrm{xor}~\\ldots~\\textrm{xor}~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~\\textrm{xor}~5 = 6.\n\nThey wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.\n\nWe know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i.\nUsing this information, restore the integer written on the scarf of each Snuke Cat.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 200000\n\nN is even.\n\n0 \\leq a_i \\leq 10^9\n\nThere exists a combination of integers on the scarfs that is consistent with the given information.\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 line containing N integers separated with space.\n\nThe i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.\n\nIf there are multiple possible solutions, you may print any of them.\n\nSample Input 1\n\n4\n20 11 9 24\n\nSample Output 1\n\n26 5 7 22\n\n5~\\textrm{xor}~7~\\textrm{xor}~22 = 20\n\n26~\\textrm{xor}~7~\\textrm{xor}~22 = 11\n\n26~\\textrm{xor}~5~\\textrm{xor}~22 = 9\n\n26~\\textrm{xor}~5~\\textrm{xor}~7 = 24\n\nThus, this output is consistent with the given information.", "sample_input": "4\n20 11 9 24\n"}, "reference_outputs": ["26 5 7 22\n"], "source_document_id": "p02631", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N Snuke Cats numbered 1, 2, \\ldots, N, where N is even.\n\nEach Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.\n\nRecently, they learned the operation called xor (exclusive OR).\n\nWhat is xor?\n\nFor n non-negative integers x_1, x_2, \\ldots, x_n, their xor, x_1~\\textrm{xor}~x_2~\\textrm{xor}~\\ldots~\\textrm{xor}~x_n is defined as follows:\n\nWhen x_1~\\textrm{xor}~x_2~\\textrm{xor}~\\ldots~\\textrm{xor}~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~\\textrm{xor}~5 = 6.\n\nThey wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.\n\nWe know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i.\nUsing this information, restore the integer written on the scarf of each Snuke Cat.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 200000\n\nN is even.\n\n0 \\leq a_i \\leq 10^9\n\nThere exists a combination of integers on the scarfs that is consistent with the given information.\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 line containing N integers separated with space.\n\nThe i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.\n\nIf there are multiple possible solutions, you may print any of them.\n\nSample Input 1\n\n4\n20 11 9 24\n\nSample Output 1\n\n26 5 7 22\n\n5~\\textrm{xor}~7~\\textrm{xor}~22 = 20\n\n26~\\textrm{xor}~7~\\textrm{xor}~22 = 11\n\n26~\\textrm{xor}~5~\\textrm{xor}~22 = 9\n\n26~\\textrm{xor}~5~\\textrm{xor}~7 = 24\n\nThus, this output is consistent with the given information.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 352, "memory_kb": 78616}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s640548542", "group_id": "codeNet:p02639", "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(princ (1+ (position 0 (read-times 5))))\n", "language": "Lisp", "metadata": {"date": 1592185369, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02639.html", "problem_id": "p02639", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02639/input.txt", "sample_output_relpath": "derived/input_output/data/p02639/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02639/Lisp/s640548542.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s640548542", "user_id": "u493610446"}, "prompt_components": {"gold_output": "1\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(princ (1+ (position 0 (read-times 5))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have five variables x_1, x_2, x_3, x_4, and x_5.\n\nThe variable x_i was initially assigned a value of i.\n\nSnuke chose one of these variables and assigned it 0.\n\nYou are given the values of the five variables after this assignment.\n\nFind out which variable Snuke assigned 0.\n\nConstraints\n\nThe values of x_1, x_2, x_3, x_4, and x_5 given as input are a possible outcome of the assignment by Snuke.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx_1 x_2 x_3 x_4 x_5\n\nOutput\n\nIf the variable Snuke assigned 0 was x_i, print the integer i.\n\nSample Input 1\n\n0 2 3 4 5\n\nSample Output 1\n\n1\n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\nSample Input 2\n\n1 2 0 4 5\n\nSample Output 2\n\n3", "sample_input": "0 2 3 4 5\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02639", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have five variables x_1, x_2, x_3, x_4, and x_5.\n\nThe variable x_i was initially assigned a value of i.\n\nSnuke chose one of these variables and assigned it 0.\n\nYou are given the values of the five variables after this assignment.\n\nFind out which variable Snuke assigned 0.\n\nConstraints\n\nThe values of x_1, x_2, x_3, x_4, and x_5 given as input are a possible outcome of the assignment by Snuke.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nx_1 x_2 x_3 x_4 x_5\n\nOutput\n\nIf the variable Snuke assigned 0 was x_i, print the integer i.\n\nSample Input 1\n\n0 2 3 4 5\n\nSample Output 1\n\n1\n\nIn this case, Snuke assigned 0 to x_1, so we should print 1.\n\nSample Input 2\n\n1 2 0 4 5\n\nSample Output 2\n\n3", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5810, "cpu_time_ms": 25, "memory_kb": 25596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s137814064", "group_id": "codeNet:p02640", "input_text": "(defun main (x y)\n (and (<= (* 2 x) y)\n (<= y (* 4 x))))\n\n(princ (if (main (read) (read)) \"Yes\" \"No\"))\n", "language": "Lisp", "metadata": {"date": 1601002866, "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/s137814064.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s137814064", "user_id": "u761519515"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun main (x y)\n (and (<= (* 2 x) y)\n (<= y (* 4 x))))\n\n(princ (if (main (read) (read)) \"Yes\" \"No\"))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 24492}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s030408552", "group_id": "codeNet:p02640", "input_text": "(declaim (inline calc))\n(defun calc (x y)\n (let ((diff (- y (* x 2))))\n (cond ((= diff 0)\n \"Yes\")\n ((= x (+ diff (/ diff 2)))\n \"Yes\")\n (t \"No\"))))\n\n\n(princ (calc (read) (read)))\n", "language": "Lisp", "metadata": {"date": 1592250902, "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/s030408552.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s030408552", "user_id": "u631655863"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(declaim (inline calc))\n(defun calc (x y)\n (let ((diff (- y (* x 2))))\n (cond ((= diff 0)\n \"Yes\")\n ((= x (+ diff (/ diff 2)))\n \"Yes\")\n (t \"No\"))))\n\n\n(princ (calc (read) (read)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 220, "cpu_time_ms": 13, "memory_kb": 24508}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s550346051", "group_id": "codeNet:p02640", "input_text": "(defun main ()\n (let ((x (read))\n (y (read)))\n (princ (cond ((= x 1)\n (if (or (= y 4) (= y 2))\n \"Yes\"\n \"No\"))\n ((= (truncate (/ y 4)) 1)\n \"Yes\")\n ((= (truncate (/ y 2)) 1)\n \"Yes\")\n ((= (truncate (/ (/ y 4) 2)) 1)\n \"Yes\")\n (t\n \"No\")))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1592194086, "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/s550346051.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s550346051", "user_id": "u631655863"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun main ()\n (let ((x (read))\n (y (read)))\n (princ (cond ((= x 1)\n (if (or (= y 4) (= y 2))\n \"Yes\"\n \"No\"))\n ((= (truncate (/ y 4)) 1)\n \"Yes\")\n ((= (truncate (/ y 2)) 1)\n \"Yes\")\n ((= (truncate (/ (/ y 4) 2)) 1)\n \"Yes\")\n (t\n \"No\")))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 446, "cpu_time_ms": 13, "memory_kb": 23532}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s202442891", "group_id": "codeNet:p02640", "input_text": "(let* ((n (read))\n (m (read)))\n (loop :for k :from 0 :upto n\n :for j := (- n k)\n :if (= m (+ (* k 2) (* j 4)))\n :do(princ \"Yes\") :and :return 1\n :finally (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1592183067, "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/s202442891.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s202442891", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((n (read))\n (m (read)))\n (loop :for k :from 0 :upto n\n :for j := (- n k)\n :if (= m (+ (* k 2) (* j 4)))\n :do(princ \"Yes\") :and :return 1\n :finally (princ \"No\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 14, "memory_kb": 23640}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s175459471", "group_id": "codeNet:p02641", "input_text": "(let* ((n (read))\n (m (read))\n (lst (loop :repeat m :collect (read))))\n (loop :for k :from 0\n :for j := (if (oddp k)\n (+ n (- (/ (1+ k) 2)))\n (+ n (/ k 2)))\n :if (not (position j lst))\n :do (princ j) :and :return 1))", "language": "Lisp", "metadata": {"date": 1592183512, "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/s175459471.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s175459471", "user_id": "u610490393"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst (loop :repeat m :collect (read))))\n (loop :for k :from 0\n :for j := (if (oddp k)\n (+ n (- (/ (1+ k) 2)))\n (+ n (/ k 2)))\n :if (not (position j lst))\n :do (princ j) :and :return 1))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 24596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s705548482", "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 (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 (marked (make-array (list h w 4) :element-type 'bit :initial-element 0))\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) 1\n (aref marked start-x start-y 1) 1\n (aref marked start-x start-y 2) 1\n (aref marked start-x start-y 3) 1)\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 (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n (zerop (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) 1)\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 (zerop (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) 1)\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 (zerop (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) 1)\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 (zerop (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) 1)\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(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (k (read))\n (boundary (if (>= k 100000) 100000 0))\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 (if (<= boundary 100000)\n (progn\n (fill (array-storage-vector marked) 0)\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) 1\n (aref marked start-x start-y 1) 1\n (aref marked start-x start-y 2) 1\n (aref marked start-x start-y 3) 1)\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 (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n (zerop (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) 1)\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 (zerop (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) 1)\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 (zerop (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) 1)\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 (zerop (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) 1)\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 (progn\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": 1592188882, "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/s705548482.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s705548482", "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 (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 (marked (make-array (list h w 4) :element-type 'bit :initial-element 0))\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) 1\n (aref marked start-x start-y 1) 1\n (aref marked start-x start-y 2) 1\n (aref marked start-x start-y 3) 1)\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 (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n (zerop (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) 1)\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 (zerop (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) 1)\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 (zerop (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) 1)\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 (zerop (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) 1)\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(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (k (read))\n (boundary (if (>= k 100000) 100000 0))\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 (if (<= boundary 100000)\n (progn\n (fill (array-storage-vector marked) 0)\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) 1\n (aref marked start-x start-y 1) 1\n (aref marked start-x start-y 2) 1\n (aref marked start-x start-y 3) 1)\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 (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n (zerop (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) 1)\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 (zerop (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) 1)\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 (zerop (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) 1)\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 (zerop (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) 1)\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 (progn\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15289, "cpu_time_ms": 122, "memory_kb": 68584}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s310899791", "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 (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 (marked (make-array (list h w 4) :element-type 'bit :initial-element 0))\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) 1\n (aref marked start-x start-y 1) 1\n (aref marked start-x start-y 2) 1\n (aref marked start-x start-y 3) 1)\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 (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n (zerop (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) 1)\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 (zerop (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) 1)\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 (zerop (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) 1)\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 (zerop (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) 1)\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(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (k (read))\n (boundary (if (>= k 100000) 100000 0))\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 (if (<= boundary 100000)\n (progn\n (fill (array-storage-vector marked) 0)\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) 1\n (aref marked start-x start-y 1) 1\n (aref marked start-x start-y 2) 1\n (aref marked start-x start-y 3) 1)\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 (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n (zerop (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) 1)\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 (zerop (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) 1)\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 (zerop (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) 1)\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 (zerop (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) 1)\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 (progn\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": 1592188811, "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/s310899791.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s310899791", "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 (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 (marked (make-array (list h w 4) :element-type 'bit :initial-element 0))\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) 1\n (aref marked start-x start-y 1) 1\n (aref marked start-x start-y 2) 1\n (aref marked start-x start-y 3) 1)\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 (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n (zerop (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) 1)\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 (zerop (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) 1)\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 (zerop (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) 1)\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 (zerop (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) 1)\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(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (k (read))\n (boundary (if (>= k 100000) 100000 0))\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 (if (<= boundary 100000)\n (progn\n (fill (array-storage-vector marked) 0)\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) 1\n (aref marked start-x start-y 1) 1\n (aref marked start-x start-y 2) 1\n (aref marked start-x start-y 3) 1)\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 (loop for delta from 1 to k\n for new-x = (- x delta)\n while (and (>= new-x 0)\n (zerop (aref marked new-x y 0))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 0) 1)\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 (zerop (aref marked new-x y 1))\n (zerop (aref plan new-x y)))\n do (setf (aref marked new-x y 1) 1)\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 (zerop (aref marked x new-y 2))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 2) 1)\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 (zerop (aref marked x new-y 3))\n (zerop (aref plan x new-y)))\n do (setf (aref marked x new-y 3) 1)\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 (progn\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14954, "cpu_time_ms": 121, "memory_kb": 68476}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s723923599", "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 (boundary (if (>= k 100000) 100000 0))\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) boundary) (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) boundary) (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) boundary) (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) boundary) (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": 1592188593, "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/s723923599.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s723923599", "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 (boundary (if (>= k 100000) 100000 0))\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) boundary) (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) boundary) (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) boundary) (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) boundary) (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8855, "cpu_time_ms": 3309, "memory_kb": 68348}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s236879664", "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 (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": 1592188305, "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/s236879664.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s236879664", "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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8587, "cpu_time_ms": 3309, "memory_kb": 68448}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s709087944", "group_id": "codeNet:p02645", "input_text": "(defun Nickname ()\n (defparameter *my-string* (string (read)))\n (subseq *my-string* 0 3)\n)\n\n(format t \"~(~A~)~%\" (Nickname))", "language": "Lisp", "metadata": {"date": 1592097172, "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/s709087944.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s709087944", "user_id": "u136500538"}, "prompt_components": {"gold_output": "tak\n", "input_to_evaluate": "(defun Nickname ()\n (defparameter *my-string* (string (read)))\n (subseq *my-string* 0 3)\n)\n\n(format t \"~(~A~)~%\" (Nickname))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 13, "memory_kb": 23732}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s925384155", "group_id": "codeNet:p02646", "input_text": "(let* ((n (cons (read) (read)))\n (m (cons (read) (read)))\n (x (read)))\n (if (<= (car n) (car m))\n (if (<= (+ (car m) (* (cdr m) x))\n (+ (car n) (* (cdr n) x)))\n (princ \"YES\")\n (princ \"NO\"))\n (if (>= (- (car m) (* (cdr m) x))\n (- (car n) (* (cdr n) x)))\n (princ \"YES\")\n (princ \"NO\"))))", "language": "Lisp", "metadata": {"date": 1592097826, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02646.html", "problem_id": "p02646", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02646/input.txt", "sample_output_relpath": "derived/input_output/data/p02646/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02646/Lisp/s925384155.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s925384155", "user_id": "u610490393"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let* ((n (cons (read) (read)))\n (m (cons (read) (read)))\n (x (read)))\n (if (<= (car n) (car m))\n (if (<= (+ (car m) (* (cdr m) x))\n (+ (car n) (* (cdr n) x)))\n (princ \"YES\")\n (princ \"NO\"))\n (if (>= (- (car m) (* (cdr m) x))\n (- (car n) (* (cdr n) x)))\n (princ \"YES\")\n (princ \"NO\"))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTwo children are playing tag on a number line. (In the game of tag, the child called \"it\" tries to catch the other child.) The child who is \"it\" is now at coordinate A, and he can travel the distance of V per second.\nThe other child is now at coordinate B, and she can travel the distance of W per second.\n\nHe can catch her when his coordinate is the same as hers.\nDetermine whether he can catch her within T seconds (including exactly T seconds later).\nWe assume that both children move optimally.\n\nConstraints\n\n-10^9 \\leq A,B \\leq 10^9\n\n1 \\leq V,W \\leq 10^9\n\n1 \\leq T \\leq 10^9\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 V\nB W\nT\n\nOutput\n\nIf \"it\" can catch the other child, print YES; otherwise, print NO.\n\nSample Input 1\n\n1 2\n3 1\n3\n\nSample Output 1\n\nYES\n\nSample Input 2\n\n1 2\n3 2\n3\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n1 2\n3 3\n3\n\nSample Output 3\n\nNO", "sample_input": "1 2\n3 1\n3\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p02646", "source_text": "Score : 200 points\n\nProblem Statement\n\nTwo children are playing tag on a number line. (In the game of tag, the child called \"it\" tries to catch the other child.) The child who is \"it\" is now at coordinate A, and he can travel the distance of V per second.\nThe other child is now at coordinate B, and she can travel the distance of W per second.\n\nHe can catch her when his coordinate is the same as hers.\nDetermine whether he can catch her within T seconds (including exactly T seconds later).\nWe assume that both children move optimally.\n\nConstraints\n\n-10^9 \\leq A,B \\leq 10^9\n\n1 \\leq V,W \\leq 10^9\n\n1 \\leq T \\leq 10^9\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 V\nB W\nT\n\nOutput\n\nIf \"it\" can catch the other child, print YES; otherwise, print NO.\n\nSample Input 1\n\n1 2\n3 1\n3\n\nSample Output 1\n\nYES\n\nSample Input 2\n\n1 2\n3 2\n3\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n1 2\n3 3\n3\n\nSample Output 3\n\nNO", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 369, "cpu_time_ms": 15, "memory_kb": 24132}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s293025877", "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 (dotimes (i (- n 1))\n (format t \"~A \"(aref readLamps i))\n )\n (format t \"~A~%\" (aref readLamps (- n 1)))\n ans)\n \n)\n(format t \"~A~%\" (Lamps (read) (read)))", "language": "Lisp", "metadata": {"date": 1592160491, "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/s293025877.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s293025877", "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 (dotimes (i (- n 1))\n (format t \"~A \"(aref readLamps i))\n )\n (format t \"~A~%\" (aref readLamps (- n 1)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1344, "cpu_time_ms": 2207, "memory_kb": 80280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s051124458", "group_id": "codeNet:p02647", "input_text": "(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 ;; read \n (loop :for i :from 1 :to n\n :do (setf (aref a i) (read)))\n ;; maybe TLE\n (loop :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 (aref a i) (aref b i))\n :do (setf (aref b i) 0))))\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", "language": "Lisp", "metadata": {"date": 1592098731, "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/s051124458.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s051124458", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1 2 2 1 2\n", "input_to_evaluate": "(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 ;; read \n (loop :for i :from 1 :to n\n :do (setf (aref a i) (read)))\n ;; maybe TLE\n (loop :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 (aref a i) (aref b i))\n :do (setf (aref b i) 0))))\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", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 786, "cpu_time_ms": 2208, "memory_kb": 79960}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s338852141", "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 (max-l 0))\n (declare (uint31 n boundary max-l))\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 (maxf max-l l)\n (push (list v l i) (aref query-store v))))\n (labels ((make (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) (make 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) (make half-vs2 half-ws2 v w)\n (declare ((simple-array uint31 (*)) half-vs2 half-ws2))\n (if (aref query-store i)\n (progn\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 (progn\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": 1592109932, "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/s338852141.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s338852141", "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 (max-l 0))\n (declare (uint31 n boundary max-l))\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 (maxf max-l l)\n (push (list v l i) (aref query-store v))))\n (labels ((make (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) (make 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) (make half-vs2 half-ws2 v w)\n (declare ((simple-array uint31 (*)) half-vs2 half-ws2))\n (if (aref query-store i)\n (progn\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 (progn\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14591, "cpu_time_ms": 1087, "memory_kb": 91348}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s162323961", "group_id": "codeNet:p02648", "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(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 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 10)\n (vs (make-array n :element-type 'uint31 :initial-element 0))\n (ws (make-array n :element-type 'uint31 :initial-element 0))\n (max-l 0))\n (declare (uint31 n boundary max-l))\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 (maxf max-l l)\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 (labels ((make (half2 v w)\n (declare ((simple-array list (*)) half2)\n (uint31 v w))\n (let* ((new-half2 (make-array (* 2 (length half2)) :element-type 'list))\n (len (length half2))\n (pos1 0)\n (pos2 0)\n (end 0)\n (current-w -1)\n (current-v -1))\n (declare ((simple-array list (*)) new-half2)\n (uint31 pos1 pos2 end)\n (fixnum current-w current-v))\n (loop (when (= pos1 len)\n (loop for pos from pos2 below len\n for (v2 . w2) of-type (uint62 . uint62) = (aref half2 pos)\n when (and (> (+ v2 v) current-v)\n (> (+ w2 w) current-w))\n do (setf (aref new-half2 end) (cons (the fixnum (+ v2 v))\n (the fixnum (+ w2 w)))\n end (+ end 1)\n current-w (+ w2 w)\n current-v (+ v2 v)))\n (return))\n (destructuring-bind (v1 . w1) (aref half2 pos1)\n (destructuring-bind (v2 . w2) (aref half2 pos2)\n (declare (uint62 v1 v2 w1 w2))\n (cond ((< w1 (+ w2 w))\n (when (and (> w1 current-w)\n (> v1 current-v))\n (setf (aref new-half2 end) (cons v1 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-half2 end) (cons (the fixnum (+ v2 v))\n (the fixnum (+ 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 (uint62 max-v))\n (when (and (> w1 current-w)\n (> max-v current-v))\n (setf (aref new-half2 end) (cons max-v 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 (adjust-array new-half2 end))))\n (sb-int:named-let recur ((i 0)\n (depth 0)\n (half1 (make-array 1\n :element-type 'list\n :initial-element (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 (*)) half1 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 (make half1 v w)))\n (declare ((simple-array list (*)) new-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) across new-half1\n when (<= w1 q-l)\n maximize v1)))\n (when (= 1 (aref tree (+ (* i 2) 1)))\n (recur (+ (* i 2) 1) (+ depth 1) new-half1 half2))\n (when (= 1 (aref tree (+ (* i 2) 2)))\n (recur (+ (* i 2) 2) (+ depth 1) new-half1 half2)))\n (let* ((new-half2 (make half2 v w)))\n (declare ((simple-array list (*)) new-half2))\n ;; answer query\n ;; 各重みについて最大の価値しかいらない\n (if (aref query-store i)\n (progn\n (loop\n 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 for pos2 = (- (length new-half2) 1)\n do (loop for (v1 . w1) of-type (fixnum . fixnum) across half1\n ;; 重さがl-w1以下のものを見つける\n while (<= w1 q-l)\n do (loop\n (destructuring-bind (v2 . w2) (aref new-half2 pos2)\n (declare (fixnum v2 w2))\n (when (<= (+ w1 w2) q-l)\n (return))\n (decf pos2)))\n (destructuring-bind (v2 . w2) (aref new-half2 pos2)\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~%\" (+ 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": 1592108726, "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/s162323961.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s162323961", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\n3\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(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 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 10)\n (vs (make-array n :element-type 'uint31 :initial-element 0))\n (ws (make-array n :element-type 'uint31 :initial-element 0))\n (max-l 0))\n (declare (uint31 n boundary max-l))\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 (maxf max-l l)\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 (labels ((make (half2 v w)\n (declare ((simple-array list (*)) half2)\n (uint31 v w))\n (let* ((new-half2 (make-array (* 2 (length half2)) :element-type 'list))\n (len (length half2))\n (pos1 0)\n (pos2 0)\n (end 0)\n (current-w -1)\n (current-v -1))\n (declare ((simple-array list (*)) new-half2)\n (uint31 pos1 pos2 end)\n (fixnum current-w current-v))\n (loop (when (= pos1 len)\n (loop for pos from pos2 below len\n for (v2 . w2) of-type (uint62 . uint62) = (aref half2 pos)\n when (and (> (+ v2 v) current-v)\n (> (+ w2 w) current-w))\n do (setf (aref new-half2 end) (cons (the fixnum (+ v2 v))\n (the fixnum (+ w2 w)))\n end (+ end 1)\n current-w (+ w2 w)\n current-v (+ v2 v)))\n (return))\n (destructuring-bind (v1 . w1) (aref half2 pos1)\n (destructuring-bind (v2 . w2) (aref half2 pos2)\n (declare (uint62 v1 v2 w1 w2))\n (cond ((< w1 (+ w2 w))\n (when (and (> w1 current-w)\n (> v1 current-v))\n (setf (aref new-half2 end) (cons v1 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-half2 end) (cons (the fixnum (+ v2 v))\n (the fixnum (+ 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 (uint62 max-v))\n (when (and (> w1 current-w)\n (> max-v current-v))\n (setf (aref new-half2 end) (cons max-v 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 (adjust-array new-half2 end))))\n (sb-int:named-let recur ((i 0)\n (depth 0)\n (half1 (make-array 1\n :element-type 'list\n :initial-element (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 (*)) half1 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 (make half1 v w)))\n (declare ((simple-array list (*)) new-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) across new-half1\n when (<= w1 q-l)\n maximize v1)))\n (when (= 1 (aref tree (+ (* i 2) 1)))\n (recur (+ (* i 2) 1) (+ depth 1) new-half1 half2))\n (when (= 1 (aref tree (+ (* i 2) 2)))\n (recur (+ (* i 2) 2) (+ depth 1) new-half1 half2)))\n (let* ((new-half2 (make half2 v w)))\n (declare ((simple-array list (*)) new-half2))\n ;; answer query\n ;; 各重みについて最大の価値しかいらない\n (if (aref query-store i)\n (progn\n (loop\n 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 for pos2 = (- (length new-half2) 1)\n do (loop for (v1 . w1) of-type (fixnum . fixnum) across half1\n ;; 重さがl-w1以下のものを見つける\n while (<= w1 q-l)\n do (loop\n (destructuring-bind (v2 . w2) (aref new-half2 pos2)\n (declare (fixnum v2 w2))\n (when (<= (+ w1 w2) q-l)\n (return))\n (decf pos2)))\n (destructuring-bind (v2 . w2) (aref new-half2 pos2)\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~%\" (+ 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15879, "cpu_time_ms": 2633, "memory_kb": 93188}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s118290697", "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)\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 (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 (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 ;; #>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 (declare (uint62 v w))\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 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": 1592103134, "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/s118290697.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s118290697", "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)\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 (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 (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 ;; #>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 (declare (uint62 v w))\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 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 18271, "cpu_time_ms": 3311, "memory_kb": 94332}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s245698145", "group_id": "codeNet:p02651", "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(defun test (n as s)\n (dbg n as s)\n (with-cache (:array ((+ n 1) (ash 1 4)) :element-type 'int8 :initial-element -1)\n (labels ((dp (pos sum)\n (cond ((= pos n)\n (if (zerop sum) 0 1))\n ((char= #\\0 (aref s pos))\n (if (or (zerop (dp (+ pos 1) sum))\n (zerop (dp (+ pos 1) (logxor sum (aref as pos)))))\n 0\n 1))\n ((char= #\\1 (aref s pos))\n (if (or (= 1 (dp (+ pos 1) sum))\n (= 1 (dp (+ pos 1) (logxor sum (aref as pos)))))\n 1\n 0))\n (t (error \"Huh?\")))))\n (dp 0 0))))\n\n(defun main ()\n (let ((tt (read)))\n (dotimes (_ tt)\n (block continue\n (labels ((no () (println 1) (return-from continue)))\n (let* ((n (read))\n (as (make-array n :element-type 'uint62 :initial-element 0))\n (dp (make-array (+ n 1) :element-type 'list :initial-element nil)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n #>as\n (let ((s (read-line)))\n (loop for i from (- n 1) downto 0\n for a = (aref as i)\n for prev = (aref dp (+ i 1))\n do #>dp\n when (char= #\\0 (aref s i))\n do (loop for x in (aref dp (+ i 1))\n do (minf a (logxor a x))\n finally (setf (aref dp i)\n (if (zerop a)\n prev\n (sort (cons a prev) #'>))))\n else\n do (loop for x in (aref dp (+ i 1))\n do (minf a (logxor a x))\n finally (if (zerop a)\n (setf (aref dp i) prev)\n (no)))\n finally (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 \"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\n1 2\n10\n2\n1 1\n10\n6\n2 3 4 5 6 7\n111000\n\"\n \"1\n0\n0\n\")))\n", "language": "Lisp", "metadata": {"date": 1591671975, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02651.html", "problem_id": "p02651", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02651/input.txt", "sample_output_relpath": "derived/input_output/data/p02651/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02651/Lisp/s245698145.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s245698145", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n0\n0\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(defun test (n as s)\n (dbg n as s)\n (with-cache (:array ((+ n 1) (ash 1 4)) :element-type 'int8 :initial-element -1)\n (labels ((dp (pos sum)\n (cond ((= pos n)\n (if (zerop sum) 0 1))\n ((char= #\\0 (aref s pos))\n (if (or (zerop (dp (+ pos 1) sum))\n (zerop (dp (+ pos 1) (logxor sum (aref as pos)))))\n 0\n 1))\n ((char= #\\1 (aref s pos))\n (if (or (= 1 (dp (+ pos 1) sum))\n (= 1 (dp (+ pos 1) (logxor sum (aref as pos)))))\n 1\n 0))\n (t (error \"Huh?\")))))\n (dp 0 0))))\n\n(defun main ()\n (let ((tt (read)))\n (dotimes (_ tt)\n (block continue\n (labels ((no () (println 1) (return-from continue)))\n (let* ((n (read))\n (as (make-array n :element-type 'uint62 :initial-element 0))\n (dp (make-array (+ n 1) :element-type 'list :initial-element nil)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n #>as\n (let ((s (read-line)))\n (loop for i from (- n 1) downto 0\n for a = (aref as i)\n for prev = (aref dp (+ i 1))\n do #>dp\n when (char= #\\0 (aref s i))\n do (loop for x in (aref dp (+ i 1))\n do (minf a (logxor a x))\n finally (setf (aref dp i)\n (if (zerop a)\n prev\n (sort (cons a prev) #'>))))\n else\n do (loop for x in (aref dp (+ i 1))\n do (minf a (logxor a x))\n finally (if (zerop a)\n (setf (aref dp i) prev)\n (no)))\n finally (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 \"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\n1 2\n10\n2\n1 1\n10\n6\n2 3 4 5 6 7\n111000\n\"\n \"1\n0\n0\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are two persons, numbered 0 and 1, and a variable x whose initial value is 0.\nThe two persons now play a game.\nThe game is played in N rounds. The following should be done in the i-th round (1 \\leq i \\leq N):\n\nPerson S_i does one of the following:\n\nReplace x with x \\oplus A_i, where \\oplus represents bitwise XOR.\n\nDo nothing.\n\nPerson 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \\neq 0 at the end of the game.\n\nDetermine whether x becomes 0 at the end of the game when the two persons play optimally.\n\nSolve T test cases for each input file.\n\nConstraints\n\n1 \\leq T \\leq 100\n\n1 \\leq N \\leq 200\n\n1 \\leq A_i \\leq 10^{18}\n\nS is a string of length N consisting of 0 and 1.\n\nAll numbers in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format.\nThe first line is as follows:\n\nT\n\nThen, T test cases follow.\nEach test case is given in the following format:\n\nN\nA_1 A_2 \\cdots A_N\nS\n\nOutput\n\nFor each test case, print a line containing 0 if x becomes 0 at the end of the game, and 1 otherwise.\n\nSample Input 1\n\n3\n2\n1 2\n10\n2\n1 1\n10\n6\n2 3 4 5 6 7\n111000\n\nSample Output 1\n\n1\n0\n0\n\nIn the first test case, if Person 1 replaces x with 0 \\oplus 1=1, we surely have x \\neq 0 at the end of the game, regardless of the choice of Person 0.\n\nIn the second test case, regardless of the choice of Person 1, Person 0 can make x=0 with a suitable choice.", "sample_input": "3\n2\n1 2\n10\n2\n1 1\n10\n6\n2 3 4 5 6 7\n111000\n"}, "reference_outputs": ["1\n0\n0\n"], "source_document_id": "p02651", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are two persons, numbered 0 and 1, and a variable x whose initial value is 0.\nThe two persons now play a game.\nThe game is played in N rounds. The following should be done in the i-th round (1 \\leq i \\leq N):\n\nPerson S_i does one of the following:\n\nReplace x with x \\oplus A_i, where \\oplus represents bitwise XOR.\n\nDo nothing.\n\nPerson 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \\neq 0 at the end of the game.\n\nDetermine whether x becomes 0 at the end of the game when the two persons play optimally.\n\nSolve T test cases for each input file.\n\nConstraints\n\n1 \\leq T \\leq 100\n\n1 \\leq N \\leq 200\n\n1 \\leq A_i \\leq 10^{18}\n\nS is a string of length N consisting of 0 and 1.\n\nAll numbers in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format.\nThe first line is as follows:\n\nT\n\nThen, T test cases follow.\nEach test case is given in the following format:\n\nN\nA_1 A_2 \\cdots A_N\nS\n\nOutput\n\nFor each test case, print a line containing 0 if x becomes 0 at the end of the game, and 1 otherwise.\n\nSample Input 1\n\n3\n2\n1 2\n10\n2\n1 1\n10\n6\n2 3 4 5 6 7\n111000\n\nSample Output 1\n\n1\n0\n0\n\nIn the first test case, if Person 1 replaces x with 0 \\oplus 1=1, we surely have x \\neq 0 at the end of the game, regardless of the choice of Person 0.\n\nIn the second test case, regardless of the choice of Person 1, Person 0 can make x=0 with a suitable choice.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5775, "cpu_time_ms": 24, "memory_kb": 26824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s068149813", "group_id": "codeNet:p02657", "input_text": "(let ((a (read))\n (b (round (* (read) 100))))\n (princ (floor (* a b) 100)))", "language": "Lisp", "metadata": {"date": 1590981013, "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/s068149813.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s068149813", "user_id": "u425762225"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(let ((a (read))\n (b (round (* (read) 100))))\n (princ (floor (* a b) 100)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 15, "memory_kb": 24164}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s230488019", "group_id": "codeNet:p02660", "input_text": "(defun barasu (n &optional (acc 1))\n (cond ((= n acc)\n acc)\n ((< n acc)\n (1- acc))\n (t \n (barasu (- n acc) (1+ acc))))) \n\n(defun main (n)\n (let ((p-list '(2))\n (p 2)\n (d-list (list 0)))\n (labels ((next-prime! (num)\n (let ((next (1+ num))\n (can-div nil))\n (loop :named xxx\n :for q :in p-list\n :do (when (= (mod next q) 0)\n (setf can-div t)\n (return-from xxx)))\n (cond (can-div\n (next-prime! next))\n (t\n (setf p next)\n (push next p-list))))))\n ;;\n (loop :named yyy\n :do (cond ((= n 1)\n (return-from yyy))\n ((and (/= n p) (> p (sqrt n)))\n (push 1 d-list)\n (return-from yyy))\n ((= (mod n p) 0)\n (setf n (/ n p))\n (incf (car d-list)))\n (t\n (push 0 d-list)\n (next-prime! p))))\n ;;\n (loop :for d :in d-list :sum (barasu d)))))\n\n(let ((n (read)))\n (format t \"~A~%\" (main n)))\n\n", "language": "Lisp", "metadata": {"date": 1590979060, "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/s230488019.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s230488019", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun barasu (n &optional (acc 1))\n (cond ((= n acc)\n acc)\n ((< n acc)\n (1- acc))\n (t \n (barasu (- n acc) (1+ acc))))) \n\n(defun main (n)\n (let ((p-list '(2))\n (p 2)\n (d-list (list 0)))\n (labels ((next-prime! (num)\n (let ((next (1+ num))\n (can-div nil))\n (loop :named xxx\n :for q :in p-list\n :do (when (= (mod next q) 0)\n (setf can-div t)\n (return-from xxx)))\n (cond (can-div\n (next-prime! next))\n (t\n (setf p next)\n (push next p-list))))))\n ;;\n (loop :named yyy\n :do (cond ((= n 1)\n (return-from yyy))\n ((and (/= n p) (> p (sqrt n)))\n (push 1 d-list)\n (return-from yyy))\n ((= (mod n p) 0)\n (setf n (/ n p))\n (incf (car d-list)))\n (t\n (push 0 d-list)\n (next-prime! p))))\n ;;\n (loop :for d :in d-list :sum (barasu d)))))\n\n(let ((n (read)))\n (format t \"~A~%\" (main n)))\n\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1337, "cpu_time_ms": 2206, "memory_kb": 24448}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s823482957", "group_id": "codeNet:p02661", "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 (as (make-array n :element-type 'uint32 :initial-element 0))\n (bs (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (setq as (sort as #'<)\n bs (sort bs #'<))\n (println\n (if (evenp n)\n (let ((med1 (/ (+ (aref as (floor n 2))\n (aref as (- (floor n 2) 1)))\n 2))\n (med2 (/ (+ (aref bs (floor n 2))\n (aref bs (- (floor n 2) 1)))\n 2)))\n (+ 1 (* 2 (- med2 med1))))\n (let ((med1 (aref as (floor n 2)))\n (med2 (aref bs (floor n 2))))\n (+ 1 (- med2 med1)))))))\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\n2 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n100 100\n10 10000\n1 1000000000\n\"\n \"9991\n\")))\n", "language": "Lisp", "metadata": {"date": 1590974106, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02661.html", "problem_id": "p02661", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02661/input.txt", "sample_output_relpath": "derived/input_output/data/p02661/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02661/Lisp/s823482957.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s823482957", "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#-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 (as (make-array n :element-type 'uint32 :initial-element 0))\n (bs (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (setq as (sort as #'<)\n bs (sort bs #'<))\n (println\n (if (evenp n)\n (let ((med1 (/ (+ (aref as (floor n 2))\n (aref as (- (floor n 2) 1)))\n 2))\n (med2 (/ (+ (aref bs (floor n 2))\n (aref bs (- (floor n 2) 1)))\n 2)))\n (+ 1 (* 2 (- med2 med1))))\n (let ((med1 (aref as (floor n 2)))\n (med2 (aref bs (floor n 2))))\n (+ 1 (- med2 med1)))))))\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\n2 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n100 100\n10 10000\n1 1000000000\n\"\n \"9991\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N integers X_1, X_2, \\cdots, X_N, and we know that A_i \\leq X_i \\leq B_i.\nFind the number of different values that the median of X_1, X_2, \\cdots, X_N can take.\n\nNotes\n\nThe median of X_1, X_2, \\cdots, X_N is defined as follows. Let x_1, x_2, \\cdots, x_N be the result of sorting X_1, X_2, \\cdots, X_N in ascending order.\n\nIf N is odd, the median is x_{(N+1)/2};\n\nif N is even, the median is (x_{N/2} + x_{N/2+1}) / 2.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq B_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 B_1\nA_2 B_2\n:\nA_N B_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2\n1 2\n2 3\n\nSample Output 1\n\n3\n\nIf X_1 = 1 and X_2 = 2, the median is \\frac{3}{2};\n\nif X_1 = 1 and X_2 = 3, the median is 2;\n\nif X_1 = 2 and X_2 = 2, the median is 2;\n\nif X_1 = 2 and X_2 = 3, the median is \\frac{5}{2}.\n\nThus, the median can take three values: \\frac{3}{2}, 2, and \\frac{5}{2}.\n\nSample Input 2\n\n3\n100 100\n10 10000\n1 1000000000\n\nSample Output 2\n\n9991", "sample_input": "2\n1 2\n2 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02661", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N integers X_1, X_2, \\cdots, X_N, and we know that A_i \\leq X_i \\leq B_i.\nFind the number of different values that the median of X_1, X_2, \\cdots, X_N can take.\n\nNotes\n\nThe median of X_1, X_2, \\cdots, X_N is defined as follows. Let x_1, x_2, \\cdots, x_N be the result of sorting X_1, X_2, \\cdots, X_N in ascending order.\n\nIf N is odd, the median is x_{(N+1)/2};\n\nif N is even, the median is (x_{N/2} + x_{N/2+1}) / 2.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i \\leq B_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 B_1\nA_2 B_2\n:\nA_N B_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2\n1 2\n2 3\n\nSample Output 1\n\n3\n\nIf X_1 = 1 and X_2 = 2, the median is \\frac{3}{2};\n\nif X_1 = 1 and X_2 = 3, the median is 2;\n\nif X_1 = 2 and X_2 = 2, the median is 2;\n\nif X_1 = 2 and X_2 = 3, the median is \\frac{5}{2}.\n\nThus, the median can take three values: \\frac{3}{2}, 2, and \\frac{5}{2}.\n\nSample Input 2\n\n3\n100 100\n10 10000\n1 1000000000\n\nSample Output 2\n\n9991", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5454, "cpu_time_ms": 287, "memory_kb": 26532}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s679769230", "group_id": "codeNet:p02669", "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(defconstant +inf+ most-positive-fixnum)\n\n(defun main ()\n (declare #.OPT)\n (let* ((tt (read)))\n (macrolet ((frob (factor coef)\n `(min (let ((up (* ,factor (ceiling x ,factor))))\n (if (= (floor up ,factor) x)\n +inf+\n (+ (* d (- up x))\n ,coef\n (dp (floor up ,factor)))))\n (let ((down (* ,factor (floor x ,factor))))\n (if (= (floor down ,factor) x)\n +inf+\n (+ (* d (- x down))\n ,coef\n (dp (floor down ,factor))))))))\n (dotimes (_ tt)\n (let ((n (read))\n (a (read))\n (b (read))\n (c (read))\n (d (read)))\n (declare (uint62 n)\n (int31 a b c d))\n (println\n (with-cache (:hash-table :test #'eq :key #'identity)\n (sb-int:named-let dp ((x n))\n (declare (uint62 x))\n (if (= x 0)\n 0\n (min (* d x)\n (frob 2 a)\n (frob 3 b)\n (frob 5 c)))))))))))\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\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\"\n \"20\n19\n26\n3821859835\n23441258666\n\")))\n", "language": "Lisp", "metadata": {"date": 1590299569, "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/s679769230.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s679769230", "user_id": "u352600849"}, "prompt_components": {"gold_output": "20\n19\n26\n3821859835\n23441258666\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(defconstant +inf+ most-positive-fixnum)\n\n(defun main ()\n (declare #.OPT)\n (let* ((tt (read)))\n (macrolet ((frob (factor coef)\n `(min (let ((up (* ,factor (ceiling x ,factor))))\n (if (= (floor up ,factor) x)\n +inf+\n (+ (* d (- up x))\n ,coef\n (dp (floor up ,factor)))))\n (let ((down (* ,factor (floor x ,factor))))\n (if (= (floor down ,factor) x)\n +inf+\n (+ (* d (- x down))\n ,coef\n (dp (floor down ,factor))))))))\n (dotimes (_ tt)\n (let ((n (read))\n (a (read))\n (b (read))\n (c (read))\n (d (read)))\n (declare (uint62 n)\n (int31 a b c d))\n (println\n (with-cache (:hash-table :test #'eq :key #'identity)\n (sb-int:named-let dp ((x n))\n (declare (uint62 x))\n (if (= x 0)\n 0\n (min (* d x)\n (frob 2 a)\n (frob 3 b)\n (frob 5 c)))))))))))\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\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\"\n \"20\n19\n26\n3821859835\n23441258666\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 16907, "cpu_time_ms": 44, "memory_kb": 35400}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s553729913", "group_id": "codeNet:p02675", "input_text": "(let ((n (mod (read) 10)))\n (format t \"~a~%\"\n (cond\n ((= n 3) \"bon\")\n ((find n '(0 1 6 8)) \"pon\")\n (t \"hon\"))))\n", "language": "Lisp", "metadata": {"date": 1589763870, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02675.html", "problem_id": "p02675", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02675/input.txt", "sample_output_relpath": "derived/input_output/data/p02675/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02675/Lisp/s553729913.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s553729913", "user_id": "u690263481"}, "prompt_components": {"gold_output": "pon\n", "input_to_evaluate": "(let ((n (mod (read) 10)))\n (format t \"~a~%\"\n (cond\n ((= n 3) \"bon\")\n ((find n '(0 1 6 8)) \"pon\")\n (t \"hon\"))))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nThe cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.\n\nWhen counting pencils in Japanese, the counter word \"本\" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of \"本\" in the phrase \"N 本\" for a positive integer N not exceeding 999 is as follows:\n\nhon when the digit in the one's place of N is 2, 4, 5, 7, or 9;\n\npon when the digit in the one's place of N is 0, 1, 6 or 8;\n\nbon when the digit in the one's place of N is 3.\n\nGiven N, print the pronunciation of \"本\" in the phrase \"N 本\".\n\nConstraints\n\nN is a positive integer not exceeding 999.\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\n16\n\nSample Output 1\n\npon\n\nThe digit in the one's place of 16 is 6, so the \"本\" in \"16 本\" is pronounced pon.\n\nSample Input 2\n\n2\n\nSample Output 2\n\nhon\n\nSample Input 3\n\n183\n\nSample Output 3\n\nbon", "sample_input": "16\n"}, "reference_outputs": ["pon\n"], "source_document_id": "p02675", "source_text": "Score: 100 points\n\nProblem Statement\n\nThe cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.\n\nWhen counting pencils in Japanese, the counter word \"本\" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of \"本\" in the phrase \"N 本\" for a positive integer N not exceeding 999 is as follows:\n\nhon when the digit in the one's place of N is 2, 4, 5, 7, or 9;\n\npon when the digit in the one's place of N is 0, 1, 6 or 8;\n\nbon when the digit in the one's place of N is 3.\n\nGiven N, print the pronunciation of \"本\" in the phrase \"N 本\".\n\nConstraints\n\nN is a positive integer not exceeding 999.\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\n16\n\nSample Output 1\n\npon\n\nThe digit in the one's place of 16 is 6, so the \"本\" in \"16 本\" is pronounced pon.\n\nSample Input 2\n\n2\n\nSample Output 2\n\nhon\n\nSample Input 3\n\n183\n\nSample Output 3\n\nbon", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 23668}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s987350699", "group_id": "codeNet:p02675", "input_text": "(let ((n (read-line)))\n (if (or (equal (aref n (1- (length n))) #\\2)\n (equal (aref n (1- (length n))) #\\4)\n (equal (aref n (1- (length n))) #\\5)\n (equal (aref n (1- (length n))) #\\7)\n (equal (aref n (1- (length n))) #\\9))\n (format t \"hon\")\n (if (or (equal (aref n (1- (length n))) #\\0)\n (equal (aref n (1- (length n))) #\\1)\n (equal (aref n (1- (length n))) #\\6)\n (equal (aref n (1- (length n))) #\\8))\n (format t \"pon\")\n (format t \"bon\"))))", "language": "Lisp", "metadata": {"date": 1589763788, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02675.html", "problem_id": "p02675", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02675/input.txt", "sample_output_relpath": "derived/input_output/data/p02675/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02675/Lisp/s987350699.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s987350699", "user_id": "u425317134"}, "prompt_components": {"gold_output": "pon\n", "input_to_evaluate": "(let ((n (read-line)))\n (if (or (equal (aref n (1- (length n))) #\\2)\n (equal (aref n (1- (length n))) #\\4)\n (equal (aref n (1- (length n))) #\\5)\n (equal (aref n (1- (length n))) #\\7)\n (equal (aref n (1- (length n))) #\\9))\n (format t \"hon\")\n (if (or (equal (aref n (1- (length n))) #\\0)\n (equal (aref n (1- (length n))) #\\1)\n (equal (aref n (1- (length n))) #\\6)\n (equal (aref n (1- (length n))) #\\8))\n (format t \"pon\")\n (format t \"bon\"))))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nThe cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.\n\nWhen counting pencils in Japanese, the counter word \"本\" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of \"本\" in the phrase \"N 本\" for a positive integer N not exceeding 999 is as follows:\n\nhon when the digit in the one's place of N is 2, 4, 5, 7, or 9;\n\npon when the digit in the one's place of N is 0, 1, 6 or 8;\n\nbon when the digit in the one's place of N is 3.\n\nGiven N, print the pronunciation of \"本\" in the phrase \"N 本\".\n\nConstraints\n\nN is a positive integer not exceeding 999.\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\n16\n\nSample Output 1\n\npon\n\nThe digit in the one's place of 16 is 6, so the \"本\" in \"16 本\" is pronounced pon.\n\nSample Input 2\n\n2\n\nSample Output 2\n\nhon\n\nSample Input 3\n\n183\n\nSample Output 3\n\nbon", "sample_input": "16\n"}, "reference_outputs": ["pon\n"], "source_document_id": "p02675", "source_text": "Score: 100 points\n\nProblem Statement\n\nThe cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.\n\nWhen counting pencils in Japanese, the counter word \"本\" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of \"本\" in the phrase \"N 本\" for a positive integer N not exceeding 999 is as follows:\n\nhon when the digit in the one's place of N is 2, 4, 5, 7, or 9;\n\npon when the digit in the one's place of N is 0, 1, 6 or 8;\n\nbon when the digit in the one's place of N is 3.\n\nGiven N, print the pronunciation of \"本\" in the phrase \"N 本\".\n\nConstraints\n\nN is a positive integer not exceeding 999.\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\n16\n\nSample Output 1\n\npon\n\nThe digit in the one's place of 16 is 6, so the \"本\" in \"16 本\" is pronounced pon.\n\nSample Input 2\n\n2\n\nSample Output 2\n\nhon\n\nSample Input 3\n\n183\n\nSample Output 3\n\nbon", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 14, "memory_kb": 23180}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s171557780", "group_id": "codeNet:p02676", "input_text": "(let* ((n (read))\n (m (read-line)))\n (loop :for k :from 1\n :for j :across m\n :do(princ j)\n :if (< n k) :do(princ \"...\") :and :do(return)))", "language": "Lisp", "metadata": {"date": 1590419378, "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/s171557780.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s171557780", "user_id": "u610490393"}, "prompt_components": {"gold_output": "nikoand...\n", "input_to_evaluate": "(let* ((n (read))\n (m (read-line)))\n (loop :for k :from 1\n :for j :across m\n :do(princ j)\n :if (< n k) :do(princ \"...\") :and :do(return)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 166, "cpu_time_ms": 15, "memory_kb": 24396}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s633972258", "group_id": "codeNet:p02676", "input_text": "(defun main ()\n (let ((k (read))\n (s (read-line)))\n (if (> (length s) k)\n (format t \"~a...~%\" (subseq s 0 k))\n (format t \"~a~%\" s))))\n\n(main)\n \n", "language": "Lisp", "metadata": {"date": 1589765023, "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/s633972258.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s633972258", "user_id": "u091381267"}, "prompt_components": {"gold_output": "nikoand...\n", "input_to_evaluate": "(defun main ()\n (let ((k (read))\n (s (read-line)))\n (if (> (length s) k)\n (format t \"~a...~%\" (subseq s 0 k))\n (format t \"~a~%\" s))))\n\n(main)\n \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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 176, "cpu_time_ms": 18, "memory_kb": 24400}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s262767090", "group_id": "codeNet:p02677", "input_text": "(let ((*read-default-float-format* 'double-float)\n (a (read))\n (b (read))\n (h (read))\n (m (read)))\n (let* ((m-hand (* (/ m 60) 2 pi))\n (h-hand (* (/ (+ h (/ m 60)) 12) 2 pi))\n (angle (- (max m-hand h-hand)\n (min m-hand h-hand))))\n (format t \"~16,16f~%\"\n (sqrt (+ (* a a)\n (* b b)\n (* -2 a b (cos angle)))))))\n", "language": "Lisp", "metadata": {"date": 1589764798, "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/s262767090.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s262767090", "user_id": "u690263481"}, "prompt_components": {"gold_output": "5.00000000000000000000\n", "input_to_evaluate": "(let ((*read-default-float-format* 'double-float)\n (a (read))\n (b (read))\n (h (read))\n (m (read)))\n (let* ((m-hand (* (/ m 60) 2 pi))\n (h-hand (* (/ (+ h (/ m 60)) 12) 2 pi))\n (angle (- (max m-hand h-hand)\n (min m-hand h-hand))))\n (format t \"~16,16f~%\"\n (sqrt (+ (* a a)\n (* b b)\n (* -2 a b (cos angle)))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 418, "cpu_time_ms": 18, "memory_kb": 24148}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s123409942", "group_id": "codeNet:p02678", "input_text": "(defpackage :abc-167-d\n (:use :cl)\n (:shadow :search))\n(in-package :abc-167-d)\n\n(defun set-path (from table to)\n (unless (gethash from table)\n (setf (gethash from table) ()))\n (setf (gethash from table) (cons to (gethash from table))))\n\n(defun get-path (from table)\n (gethash from table))\n\n(defun set-mark (mark marks room)\n (if (= 0 (aref marks room))\n (setf (aref marks room) mark)))\n\n(defun get-mark (marks room)\n (aref marks room))\n\n(let* ((n (read))\n (m (read))\n (-> (make-hash-table :size (1+ n)))\n (at (make-array `(,(1+ n)) :initial-element 0)))\n ;; read\n (loop :for i :from 1 :to m\n :do (let ((ai (read))\n (bi (read)))\n (set-path ai -> bi)\n (set-path bi -> ai)))\n (labels ((search (rooms)\n (loop :for current :in rooms\n :append (loop :for room :in (get-path current ->)\n :if (set-mark current at room)\n :collect room))))\n ;; search\n (loop :for rooms := (search (if rooms rooms (list 1)))\n :while rooms)\n ;; TODO\n (block finally\n (loop :for i :from 2 :to n\n :if (= (get-mark at i) 0)\n :do (progn\n (format t \"No~%\")\n (return-from finally)))\n (format t \"Yes~%\")\n (loop :for i :from 2 :to n\n :do (format t \"~A~%\" (get-mark at i))))))\n", "language": "Lisp", "metadata": {"date": 1589768224, "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/s123409942.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s123409942", "user_id": "u608227593"}, "prompt_components": {"gold_output": "Yes\n1\n2\n2\n", "input_to_evaluate": "(defpackage :abc-167-d\n (:use :cl)\n (:shadow :search))\n(in-package :abc-167-d)\n\n(defun set-path (from table to)\n (unless (gethash from table)\n (setf (gethash from table) ()))\n (setf (gethash from table) (cons to (gethash from table))))\n\n(defun get-path (from table)\n (gethash from table))\n\n(defun set-mark (mark marks room)\n (if (= 0 (aref marks room))\n (setf (aref marks room) mark)))\n\n(defun get-mark (marks room)\n (aref marks room))\n\n(let* ((n (read))\n (m (read))\n (-> (make-hash-table :size (1+ n)))\n (at (make-array `(,(1+ n)) :initial-element 0)))\n ;; read\n (loop :for i :from 1 :to m\n :do (let ((ai (read))\n (bi (read)))\n (set-path ai -> bi)\n (set-path bi -> ai)))\n (labels ((search (rooms)\n (loop :for current :in rooms\n :append (loop :for room :in (get-path current ->)\n :if (set-mark current at room)\n :collect room))))\n ;; search\n (loop :for rooms := (search (if rooms rooms (list 1)))\n :while rooms)\n ;; TODO\n (block finally\n (loop :for i :from 2 :to n\n :if (= (get-mark at i) 0)\n :do (progn\n (format t \"No~%\")\n (return-from finally)))\n (format t \"Yes~%\")\n (loop :for i :from 2 :to n\n :do (format t \"~A~%\" (get-mark at i))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1422, "cpu_time_ms": 605, "memory_kb": 86824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s626231218", "group_id": "codeNet:p02680", "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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 +neg-inf+ #x-80000000)\n(defconstant +pos-inf+ #x7fffffff)\n\n(defun solve (n m as bs cs ds es fs)\n (declare #.OPT\n (uint31 n m)\n ((simple-array int32 (*)) as bs cs ds es fs))\n (let* ((init-i (- (position-if (lambda (c) (>= c 0)) cs) 1))\n (init-j (- (position-if (lambda (d) (>= d 0)) ds) 1))\n (marked (make-array '(1001 1001) :element-type 'bit :initial-element 0)))\n (sb-int:named-let dfs ((i init-i) (j init-j))\n (when (zerop (aref marked i j))\n (setf (aref marked i j) 1)\n (let ((d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (when (< i n)\n (let ((a (aref as (+ i 1)))\n (b (aref bs (+ i 1))))\n (unless (<= a d1 d2 b)\n (dfs (+ i 1) j))))\n (when (> i 0)\n (let ((a (aref as i))\n (b (aref bs i)))\n (unless (<= a d1 d2 b)\n (dfs (- i 1) j)))))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1))))\n (when (< j m)\n (let ((e (aref es (+ j 1)))\n (f (aref fs (+ j 1))))\n (unless (<= e c1 c2 f)\n (dfs i (+ j 1)))))\n (when (> j 0)\n (let ((e (aref es j))\n (f (aref fs j)))\n (unless (<= e c1 c2 f)\n (dfs i (- j 1))))))))\n (when (and (loop for i to n always (= 1 (aref marked i 0)))\n (loop for i to n always (= 1 (aref marked i m)))\n (loop for j to m always (= 1 (aref marked 0 j)))\n (loop for j to m always (= 1 (aref marked n j))))\n (return-from solve nil))\n (let ((res 0))\n (declare (int64 res))\n (dotimes (i n)\n (dotimes (j m)\n (when (= 1 (aref marked i j))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1)))\n (d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (incf res (the fixnum (* (- c2 c1) (- d2 d1))))))))\n res)))\n\n(declaim (inline intersect-p))\n(defun intersect-p (l1 r1 l2 r2)\n (and (<= l1 r2) (<= l2 r1)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (abcs (make-array (+ n 2)))\n (defs (make-array (+ m 2)))\n (as (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (bs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (cs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (ds (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (es (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (fs (make-array (+ m 2) :element-type 'int32 :initial-element 0)))\n (declare (uint16 n m))\n (dotimes (i n)\n (setf (aref abcs i) (list (read) (read) (read))))\n (setf (aref abcs n) (list 0 0 +neg-inf+)\n (aref abcs (+ n 1)) (list 0 0 +pos-inf+))\n (dotimes (i m)\n (setf (aref defs i) (list (read) (read) (read))))\n (setf (aref defs m) (list +neg-inf+ 0 0)\n (aref defs (+ m 1)) (list +pos-inf+ 0 0))\n (setq abcs (sort abcs (lambda (p1 p2)\n (or (< (third p1) (third p2))\n (and (= (third p1) (third p2))\n (< (second p1) (second p2)))))))\n (setq defs (sort defs (lambda (p1 p2)\n (or (< (first p1) (first p2))\n (and (= (first p1) (first p2))\n (< (third p1) (third p2)))))))\n (dotimes (i1 (+ n 2))\n (destructuring-bind (a1 b1 c1) (aref abcs i1)\n (declare (int32 a1 b1 c1))\n (loop for i2 from (+ i1 1) below (+ n 2)\n for (a2 b2 c2) of-type (int32 int32 int32) = (aref abcs i2)\n when (and (= c1 c2) (intersect-p a1 b1 a2 b2))\n do (minf a1 a2)\n (maxf b1 b2))\n (setf (aref as i1) a1\n (aref bs i1) b1\n (aref cs i1) c1)))\n (dotimes (j1 (+ m 2))\n (destructuring-bind (d1 e1 f1) (aref defs j1)\n (declare (int32 d1 e1 f1))\n (loop for j2 from (+ j1 1) below (+ m 2)\n for (d2 e2 f2) of-type (int32 int32 int32) = (aref defs j2)\n when (and (= d1 d2) (intersect-p e1 f1 e2 f2))\n do (minf e1 e2)\n (maxf f1 f2))\n (setf (aref ds j1) d1\n (aref es j1) e1\n (aref fs j1) f1)))\n (println (or (solve n m as bs cs ds es fs)\n \"INF\"))))\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 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\"\n \"INF\n\")))\n", "language": "Lisp", "metadata": {"date": 1589897673, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02680.html", "problem_id": "p02680", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02680/input.txt", "sample_output_relpath": "derived/input_output/data/p02680/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02680/Lisp/s626231218.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s626231218", "user_id": "u352600849"}, "prompt_components": {"gold_output": "13\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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 +neg-inf+ #x-80000000)\n(defconstant +pos-inf+ #x7fffffff)\n\n(defun solve (n m as bs cs ds es fs)\n (declare #.OPT\n (uint31 n m)\n ((simple-array int32 (*)) as bs cs ds es fs))\n (let* ((init-i (- (position-if (lambda (c) (>= c 0)) cs) 1))\n (init-j (- (position-if (lambda (d) (>= d 0)) ds) 1))\n (marked (make-array '(1001 1001) :element-type 'bit :initial-element 0)))\n (sb-int:named-let dfs ((i init-i) (j init-j))\n (when (zerop (aref marked i j))\n (setf (aref marked i j) 1)\n (let ((d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (when (< i n)\n (let ((a (aref as (+ i 1)))\n (b (aref bs (+ i 1))))\n (unless (<= a d1 d2 b)\n (dfs (+ i 1) j))))\n (when (> i 0)\n (let ((a (aref as i))\n (b (aref bs i)))\n (unless (<= a d1 d2 b)\n (dfs (- i 1) j)))))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1))))\n (when (< j m)\n (let ((e (aref es (+ j 1)))\n (f (aref fs (+ j 1))))\n (unless (<= e c1 c2 f)\n (dfs i (+ j 1)))))\n (when (> j 0)\n (let ((e (aref es j))\n (f (aref fs j)))\n (unless (<= e c1 c2 f)\n (dfs i (- j 1))))))))\n (when (and (loop for i to n always (= 1 (aref marked i 0)))\n (loop for i to n always (= 1 (aref marked i m)))\n (loop for j to m always (= 1 (aref marked 0 j)))\n (loop for j to m always (= 1 (aref marked n j))))\n (return-from solve nil))\n (let ((res 0))\n (declare (int64 res))\n (dotimes (i n)\n (dotimes (j m)\n (when (= 1 (aref marked i j))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1)))\n (d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (incf res (the fixnum (* (- c2 c1) (- d2 d1))))))))\n res)))\n\n(declaim (inline intersect-p))\n(defun intersect-p (l1 r1 l2 r2)\n (and (<= l1 r2) (<= l2 r1)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (abcs (make-array (+ n 2)))\n (defs (make-array (+ m 2)))\n (as (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (bs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (cs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (ds (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (es (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (fs (make-array (+ m 2) :element-type 'int32 :initial-element 0)))\n (declare (uint16 n m))\n (dotimes (i n)\n (setf (aref abcs i) (list (read) (read) (read))))\n (setf (aref abcs n) (list 0 0 +neg-inf+)\n (aref abcs (+ n 1)) (list 0 0 +pos-inf+))\n (dotimes (i m)\n (setf (aref defs i) (list (read) (read) (read))))\n (setf (aref defs m) (list +neg-inf+ 0 0)\n (aref defs (+ m 1)) (list +pos-inf+ 0 0))\n (setq abcs (sort abcs (lambda (p1 p2)\n (or (< (third p1) (third p2))\n (and (= (third p1) (third p2))\n (< (second p1) (second p2)))))))\n (setq defs (sort defs (lambda (p1 p2)\n (or (< (first p1) (first p2))\n (and (= (first p1) (first p2))\n (< (third p1) (third p2)))))))\n (dotimes (i1 (+ n 2))\n (destructuring-bind (a1 b1 c1) (aref abcs i1)\n (declare (int32 a1 b1 c1))\n (loop for i2 from (+ i1 1) below (+ n 2)\n for (a2 b2 c2) of-type (int32 int32 int32) = (aref abcs i2)\n when (and (= c1 c2) (intersect-p a1 b1 a2 b2))\n do (minf a1 a2)\n (maxf b1 b2))\n (setf (aref as i1) a1\n (aref bs i1) b1\n (aref cs i1) c1)))\n (dotimes (j1 (+ m 2))\n (destructuring-bind (d1 e1 f1) (aref defs j1)\n (declare (int32 d1 e1 f1))\n (loop for j2 from (+ j1 1) below (+ m 2)\n for (d2 e2 f2) of-type (int32 int32 int32) = (aref defs j2)\n when (and (= d1 d2) (intersect-p e1 f1 e2 f2))\n do (minf e1 e2)\n (maxf f1 f2))\n (setf (aref ds j1) d1\n (aref es j1) e1\n (aref fs j1) f1)))\n (println (or (solve n m as bs cs ds es fs)\n \"INF\"))))\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 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\"\n \"INF\n\")))\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "sample_input": "5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n"}, "reference_outputs": ["13\n"], "source_document_id": "p02680", "source_text": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8742, "cpu_time_ms": 113, "memory_kb": 134840}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s407965572", "group_id": "codeNet:p02680", "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* ((a (read))\n (b (read))\n (h (read))\n (m (read))\n (h-rad (* (/ (+ (* h 60) m) (* 12 60)) (* 2 pi)))\n (m-rad (* (/ m 60) (* 2 pi))))\n (println (abs (- (* a (cis h-rad))\n (* b (cis m-rad)))))))\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 9 0\n\"\n \"5.00000000000000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 4 10 40\n\"\n \"4.56425719433005567605\n\")))\n", "language": "Lisp", "metadata": {"date": 1589846877, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02680.html", "problem_id": "p02680", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02680/input.txt", "sample_output_relpath": "derived/input_output/data/p02680/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02680/Lisp/s407965572.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s407965572", "user_id": "u352600849"}, "prompt_components": {"gold_output": "13\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* ((a (read))\n (b (read))\n (h (read))\n (m (read))\n (h-rad (* (/ (+ (* h 60) m) (* 12 60)) (* 2 pi)))\n (m-rad (* (/ m 60) (* 2 pi))))\n (println (abs (- (* a (cis h-rad))\n (* b (cis m-rad)))))))\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 9 0\n\"\n \"5.00000000000000000000\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 4 10 40\n\"\n \"4.56425719433005567605\n\")))\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "sample_input": "5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n"}, "reference_outputs": ["13\n"], "source_document_id": "p02680", "source_text": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3783, "cpu_time_ms": 18, "memory_kb": 25348}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s687052316", "group_id": "codeNet:p02680", "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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 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 (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;;;\n;;; Sort multiple vectors\n;;;\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 (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(defun parallel-shuffle! (vector &rest vectors)\n \"Destructively shuffles VECTOR and applies the same permutation to all the\nvectors in VECTORS.\"\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 (dolist (v vectors)\n (rotatef (aref v i) (aref v j)))\n finally (return vector)))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:define-source-transform parallel-shuffle! (vector &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 (loop for i from (- (length ,vec) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref ,vec i) (aref ,vec j))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym i) (aref ,sym j)))\n finally (return ,vec))))))\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 +neg-inf+ #x-80000000)\n(defconstant +pos-inf+ #x7fffffff)\n\n(defun solve (n m as bs cs ds es fs graph)\n (declare #.OPT\n (uint31 n m)\n ((simple-array int32 (*)) as bs cs ds es fs)\n ((simple-array list (*)) graph))\n (labels ((to-idx (i j) (+ i (* j 1001)))\n (rev (idx)\n (multiple-value-bind (quot rem) (floor idx 1001)\n (values rem quot))))\n (declare (inline to-idx rev))\n (loop\n for i from 0 to n\n do (loop\n for j from 0 to m\n do (let ((d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (when (< i n)\n (let ((a (aref as (+ i 1)))\n (b (aref bs (+ i 1))))\n (unless (<= a d1 d2 b)\n (push (to-idx (+ i 1) j) (aref graph (to-idx i j))))))\n (when (> i 0)\n (let ((a (aref as i))\n (b (aref bs i)))\n (unless (<= a d1 d2 b)\n (push (to-idx (- i 1) j) (aref graph (to-idx i j)))))))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1))))\n (when (< j m)\n (let ((e (aref es (+ j 1)))\n (f (aref fs (+ j 1))))\n (unless (<= e c1 c2 f)\n (push (to-idx i (+ j 1)) (aref graph (to-idx i j))))))\n (when (> j 0)\n (let ((e (aref es j))\n (f (aref fs j)))\n (unless (<= e c1 c2 f)\n (push (to-idx i (- j 1)) (aref graph (to-idx i j)))))))))\n (let* ((init-i (- (bisect-left cs 0) 1))\n (init-j (- (bisect-left ds 0) 1))\n (init (to-idx init-i init-j))\n (marked (make-array #.(* 1001 1001) :element-type 'bit :initial-element 0)))\n (sb-int:named-let dfs ((v init))\n (setf (aref marked v) 1)\n (dolist (next (aref graph v))\n (when (zerop (aref marked next))\n (dfs next))))\n (when (and (loop for i to n always (= 1 (aref marked (to-idx i 0))))\n (loop for i to n always (= 1 (aref marked (to-idx i m))))\n (loop for j to m always (= 1 (aref marked (to-idx 0 j))))\n (loop for j to m always (= 1 (aref marked (to-idx n j)))))\n (return-from solve nil))\n (let ((res 0))\n (dotimes (idx (length marked))\n (when (= 1 (aref marked idx))\n (multiple-value-bind (i j) (rev idx)\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1)))\n (d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (incf res (* (- c2 c1) (- d2 d1)))))))\n res))))\n\n(declaim (inline intersect-p))\n(defun intersect-p (l1 r1 l2 r2)\n (and (<= l1 r2) (<= l2 r1)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (abcs (make-array (+ n 2)))\n (defs (make-array (+ m 2)))\n (as (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (bs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (cs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (ds (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (es (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (fs (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (graph (make-array #.(* 1001 1001) :element-type 'list :initial-element nil)))\n (declare (uint16 n m))\n (dotimes (i n)\n (setf (aref abcs i) (list (read) (read) (read))))\n (setf (aref abcs n) (list 0 0 +neg-inf+)\n (aref abcs (+ n 1)) (list 0 0 +pos-inf+))\n (dotimes (i m)\n (setf (aref defs i) (list (read) (read) (read))))\n (setf (aref defs m) (list +neg-inf+ 0 0)\n (aref defs (+ m 1)) (list +pos-inf+ 0 0))\n (setq abcs (sort abcs (lambda (p1 p2)\n (or (< (third p1) (third p2))\n (and (= (third p1) (third p2))\n (< (second p1) (second p2)))))))\n (setq defs (sort defs (lambda (p1 p2)\n (or (< (first p1) (first p2))\n (and (= (first p1) (first p2))\n (< (third p1) (third p2)))))))\n (dotimes (i1 (+ n 2))\n (destructuring-bind (a1 b1 c1) (aref abcs i1)\n (declare (int32 a1 b1 c1))\n (loop for i2 from (+ i1 1) below (+ n 2)\n for (a2 b2 c2) of-type (int32 int32 int32) = (aref abcs i2)\n when (and (= c1 c2) (intersect-p a1 b1 a2 b2))\n do (minf a1 a2)\n (maxf b1 b2))\n (setf (aref as i1) a1\n (aref bs i1) b1\n (aref cs i1) c1)))\n (dotimes (j1 (+ m 2))\n (destructuring-bind (d1 e1 f1) (aref defs j1)\n (declare (int32 d1 e1 f1))\n (loop for j2 from (+ j1 1) below (+ m 2)\n for (d2 e2 f2) of-type (int32 int32 int32) = (aref defs j2)\n when (and (= d1 d2) (intersect-p e1 f1 e2 f2))\n do (minf e1 e2)\n (maxf f1 f2))\n (setf (aref ds j1) d1\n (aref es j1) e1\n (aref fs j1) f1)))\n (println (or (solve n m as bs cs ds es fs graph)\n \"INF\"))))\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 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\"\n \"INF\n\")))\n", "language": "Lisp", "metadata": {"date": 1589846608, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02680.html", "problem_id": "p02680", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02680/input.txt", "sample_output_relpath": "derived/input_output/data/p02680/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02680/Lisp/s687052316.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s687052316", "user_id": "u352600849"}, "prompt_components": {"gold_output": "13\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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 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 (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;;;\n;;; Sort multiple vectors\n;;;\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 (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(defun parallel-shuffle! (vector &rest vectors)\n \"Destructively shuffles VECTOR and applies the same permutation to all the\nvectors in VECTORS.\"\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 (dolist (v vectors)\n (rotatef (aref v i) (aref v j)))\n finally (return vector)))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:define-source-transform parallel-shuffle! (vector &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 (loop for i from (- (length ,vec) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref ,vec i) (aref ,vec j))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym i) (aref ,sym j)))\n finally (return ,vec))))))\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 +neg-inf+ #x-80000000)\n(defconstant +pos-inf+ #x7fffffff)\n\n(defun solve (n m as bs cs ds es fs graph)\n (declare #.OPT\n (uint31 n m)\n ((simple-array int32 (*)) as bs cs ds es fs)\n ((simple-array list (*)) graph))\n (labels ((to-idx (i j) (+ i (* j 1001)))\n (rev (idx)\n (multiple-value-bind (quot rem) (floor idx 1001)\n (values rem quot))))\n (declare (inline to-idx rev))\n (loop\n for i from 0 to n\n do (loop\n for j from 0 to m\n do (let ((d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (when (< i n)\n (let ((a (aref as (+ i 1)))\n (b (aref bs (+ i 1))))\n (unless (<= a d1 d2 b)\n (push (to-idx (+ i 1) j) (aref graph (to-idx i j))))))\n (when (> i 0)\n (let ((a (aref as i))\n (b (aref bs i)))\n (unless (<= a d1 d2 b)\n (push (to-idx (- i 1) j) (aref graph (to-idx i j)))))))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1))))\n (when (< j m)\n (let ((e (aref es (+ j 1)))\n (f (aref fs (+ j 1))))\n (unless (<= e c1 c2 f)\n (push (to-idx i (+ j 1)) (aref graph (to-idx i j))))))\n (when (> j 0)\n (let ((e (aref es j))\n (f (aref fs j)))\n (unless (<= e c1 c2 f)\n (push (to-idx i (- j 1)) (aref graph (to-idx i j)))))))))\n (let* ((init-i (- (bisect-left cs 0) 1))\n (init-j (- (bisect-left ds 0) 1))\n (init (to-idx init-i init-j))\n (marked (make-array #.(* 1001 1001) :element-type 'bit :initial-element 0)))\n (sb-int:named-let dfs ((v init))\n (setf (aref marked v) 1)\n (dolist (next (aref graph v))\n (when (zerop (aref marked next))\n (dfs next))))\n (when (and (loop for i to n always (= 1 (aref marked (to-idx i 0))))\n (loop for i to n always (= 1 (aref marked (to-idx i m))))\n (loop for j to m always (= 1 (aref marked (to-idx 0 j))))\n (loop for j to m always (= 1 (aref marked (to-idx n j)))))\n (return-from solve nil))\n (let ((res 0))\n (dotimes (idx (length marked))\n (when (= 1 (aref marked idx))\n (multiple-value-bind (i j) (rev idx)\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1)))\n (d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (incf res (* (- c2 c1) (- d2 d1)))))))\n res))))\n\n(declaim (inline intersect-p))\n(defun intersect-p (l1 r1 l2 r2)\n (and (<= l1 r2) (<= l2 r1)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (abcs (make-array (+ n 2)))\n (defs (make-array (+ m 2)))\n (as (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (bs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (cs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (ds (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (es (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (fs (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (graph (make-array #.(* 1001 1001) :element-type 'list :initial-element nil)))\n (declare (uint16 n m))\n (dotimes (i n)\n (setf (aref abcs i) (list (read) (read) (read))))\n (setf (aref abcs n) (list 0 0 +neg-inf+)\n (aref abcs (+ n 1)) (list 0 0 +pos-inf+))\n (dotimes (i m)\n (setf (aref defs i) (list (read) (read) (read))))\n (setf (aref defs m) (list +neg-inf+ 0 0)\n (aref defs (+ m 1)) (list +pos-inf+ 0 0))\n (setq abcs (sort abcs (lambda (p1 p2)\n (or (< (third p1) (third p2))\n (and (= (third p1) (third p2))\n (< (second p1) (second p2)))))))\n (setq defs (sort defs (lambda (p1 p2)\n (or (< (first p1) (first p2))\n (and (= (first p1) (first p2))\n (< (third p1) (third p2)))))))\n (dotimes (i1 (+ n 2))\n (destructuring-bind (a1 b1 c1) (aref abcs i1)\n (declare (int32 a1 b1 c1))\n (loop for i2 from (+ i1 1) below (+ n 2)\n for (a2 b2 c2) of-type (int32 int32 int32) = (aref abcs i2)\n when (and (= c1 c2) (intersect-p a1 b1 a2 b2))\n do (minf a1 a2)\n (maxf b1 b2))\n (setf (aref as i1) a1\n (aref bs i1) b1\n (aref cs i1) c1)))\n (dotimes (j1 (+ m 2))\n (destructuring-bind (d1 e1 f1) (aref defs j1)\n (declare (int32 d1 e1 f1))\n (loop for j2 from (+ j1 1) below (+ m 2)\n for (d2 e2 f2) of-type (int32 int32 int32) = (aref defs j2)\n when (and (= d1 d2) (intersect-p e1 f1 e2 f2))\n do (minf e1 e2)\n (maxf f1 f2))\n (setf (aref ds j1) d1\n (aref es j1) e1\n (aref fs j1) f1)))\n (println (or (solve n m as bs cs ds es fs graph)\n \"INF\"))))\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 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\"\n \"INF\n\")))\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "sample_input": "5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n"}, "reference_outputs": ["13\n"], "source_document_id": "p02680", "source_text": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 17532, "cpu_time_ms": 231, "memory_kb": 154564}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s487861476", "group_id": "codeNet:p02680", "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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 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;;;\n;;; Sort multiple vectors\n;;;\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 (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(defun parallel-shuffle! (vector &rest vectors)\n \"Destructively shuffles VECTOR and applies the same permutation to all the\nvectors in VECTORS.\"\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 (dolist (v vectors)\n (rotatef (aref v i) (aref v j)))\n finally (return vector)))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:define-source-transform parallel-shuffle! (vector &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 (loop for i from (- (length ,vec) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref ,vec i) (aref ,vec j))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym i) (aref ,sym j)))\n finally (return ,vec))))))\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 +neg-inf+ #x-80000000)\n(defconstant +pos-inf+ #x7fffffff)\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (bs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (cs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (ds (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (es (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (fs (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (graph (make-array (* (+ n 1) (+ m 1)) :element-type 'list :initial-element nil)))\n (labels ((to-idx (i j) (+ i (* j (+ n 1))))\n (rev (idx)\n (multiple-value-bind (quot rem) (floor idx (+ n 1))\n (values rem quot))))\n (dotimes (i n)\n (setf (aref as i) (read)\n (aref bs i) (read)\n (aref cs i) (read)))\n (setf (aref cs n) +neg-inf+\n (aref cs (+ n 1)) +pos-inf+)\n (dotimes (i m)\n (setf (aref ds i) (read)\n (aref es i) (read)\n (aref fs i) (read)))\n (setf (aref ds m) +neg-inf+\n (aref ds (+ m 1)) +pos-inf+)\n (parallel-sort! cs #'< as bs)\n (parallel-sort! ds #'< es fs)\n (loop\n for i from 0 to n\n do (loop\n for j from 0 to m\n do (let ((d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (when (< i n)\n (let ((a (aref as (+ i 1)))\n (b (aref bs (+ i 1))))\n (unless (<= a d1 d2 b)\n (push (to-idx (+ i 1) j) (aref graph (to-idx i j))))))\n (when (> i 0)\n (let ((a (aref as i))\n (b (aref bs i)))\n (unless (<= a d1 d2 b)\n (push (to-idx (- i 1) j) (aref graph (to-idx i j)))))))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1))))\n (when (< j m)\n (let ((e (aref es (+ j 1)))\n (f (aref fs (+ j 1))))\n (unless (<= e c1 c2 f)\n (push (to-idx i (+ j 1)) (aref graph (to-idx i j))))))\n (when (> j 0)\n (let ((e (aref es j))\n (f (aref fs j)))\n (unless (<= e c1 c2 f)\n (push (to-idx i (- j 1)) (aref graph (to-idx i j)))))))))\n (let* ((init-i (- (bisect-left cs 0) 1))\n (init-j (- (bisect-left ds 0) 1))\n (init (to-idx init-i init-j))\n (marked (make-array (* (+ n 1) (+ m 1)) :element-type 'bit :initial-element 0)))\n (sb-int:named-let dfs ((v init))\n (setf (aref marked v) 1)\n (dolist (next (aref graph v))\n (when (zerop (aref marked next))\n (dfs next))))\n (let ((res 0))\n (dotimes (idx (length marked))\n (when (= 1 (aref marked idx))\n (multiple-value-bind (i j) (rev idx)\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1)))\n (d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (incf res (* (- c2 c1) (- d2 d1)))))))\n (when (and (loop for i to n always (= 1 (aref marked (to-idx i 0))))\n (loop for i to n always (= 1 (aref marked (to-idx i m))))\n (loop for j to m always (= 1 (aref marked (to-idx 0 j))))\n (loop for j to m always (= 1 (aref marked (to-idx n j)))))\n (write-line \"INF\")\n (return-from main))\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 \"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\"\n \"INF\n\")))\n", "language": "Lisp", "metadata": {"date": 1589785014, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02680.html", "problem_id": "p02680", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02680/input.txt", "sample_output_relpath": "derived/input_output/data/p02680/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02680/Lisp/s487861476.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s487861476", "user_id": "u352600849"}, "prompt_components": {"gold_output": "13\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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 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;;;\n;;; Sort multiple vectors\n;;;\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 (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(defun parallel-shuffle! (vector &rest vectors)\n \"Destructively shuffles VECTOR and applies the same permutation to all the\nvectors in VECTORS.\"\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 (dolist (v vectors)\n (rotatef (aref v i) (aref v j)))\n finally (return vector)))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:define-source-transform parallel-shuffle! (vector &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 (loop for i from (- (length ,vec) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref ,vec i) (aref ,vec j))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym i) (aref ,sym j)))\n finally (return ,vec))))))\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 +neg-inf+ #x-80000000)\n(defconstant +pos-inf+ #x7fffffff)\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (bs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (cs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (ds (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (es (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (fs (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (graph (make-array (* (+ n 1) (+ m 1)) :element-type 'list :initial-element nil)))\n (labels ((to-idx (i j) (+ i (* j (+ n 1))))\n (rev (idx)\n (multiple-value-bind (quot rem) (floor idx (+ n 1))\n (values rem quot))))\n (dotimes (i n)\n (setf (aref as i) (read)\n (aref bs i) (read)\n (aref cs i) (read)))\n (setf (aref cs n) +neg-inf+\n (aref cs (+ n 1)) +pos-inf+)\n (dotimes (i m)\n (setf (aref ds i) (read)\n (aref es i) (read)\n (aref fs i) (read)))\n (setf (aref ds m) +neg-inf+\n (aref ds (+ m 1)) +pos-inf+)\n (parallel-sort! cs #'< as bs)\n (parallel-sort! ds #'< es fs)\n (loop\n for i from 0 to n\n do (loop\n for j from 0 to m\n do (let ((d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (when (< i n)\n (let ((a (aref as (+ i 1)))\n (b (aref bs (+ i 1))))\n (unless (<= a d1 d2 b)\n (push (to-idx (+ i 1) j) (aref graph (to-idx i j))))))\n (when (> i 0)\n (let ((a (aref as i))\n (b (aref bs i)))\n (unless (<= a d1 d2 b)\n (push (to-idx (- i 1) j) (aref graph (to-idx i j)))))))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1))))\n (when (< j m)\n (let ((e (aref es (+ j 1)))\n (f (aref fs (+ j 1))))\n (unless (<= e c1 c2 f)\n (push (to-idx i (+ j 1)) (aref graph (to-idx i j))))))\n (when (> j 0)\n (let ((e (aref es j))\n (f (aref fs j)))\n (unless (<= e c1 c2 f)\n (push (to-idx i (- j 1)) (aref graph (to-idx i j)))))))))\n (let* ((init-i (- (bisect-left cs 0) 1))\n (init-j (- (bisect-left ds 0) 1))\n (init (to-idx init-i init-j))\n (marked (make-array (* (+ n 1) (+ m 1)) :element-type 'bit :initial-element 0)))\n (sb-int:named-let dfs ((v init))\n (setf (aref marked v) 1)\n (dolist (next (aref graph v))\n (when (zerop (aref marked next))\n (dfs next))))\n (let ((res 0))\n (dotimes (idx (length marked))\n (when (= 1 (aref marked idx))\n (multiple-value-bind (i j) (rev idx)\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1)))\n (d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (incf res (* (- c2 c1) (- d2 d1)))))))\n (when (and (loop for i to n always (= 1 (aref marked (to-idx i 0))))\n (loop for i to n always (= 1 (aref marked (to-idx i m))))\n (loop for j to m always (= 1 (aref marked (to-idx 0 j))))\n (loop for j to m always (= 1 (aref marked (to-idx n j)))))\n (write-line \"INF\")\n (return-from main))\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 \"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\"\n \"INF\n\")))\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "sample_input": "5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n"}, "reference_outputs": ["13\n"], "source_document_id": "p02680", "source_text": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15728, "cpu_time_ms": 379, "memory_kb": 289332}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s143892929", "group_id": "codeNet:p02680", "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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 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;;;\n;;; Sort multiple vectors\n;;;\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 (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(defun parallel-shuffle! (vector &rest vectors)\n \"Destructively shuffles VECTOR and applies the same permutation to all the\nvectors in VECTORS.\"\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 (dolist (v vectors)\n (rotatef (aref v i) (aref v j)))\n finally (return vector)))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:define-source-transform parallel-shuffle! (vector &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 (loop for i from (- (length ,vec) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref ,vec i) (aref ,vec j))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym i) (aref ,sym j)))\n finally (return ,vec))))))\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 +neg-inf+ #x-80000000)\n(defconstant +pos-inf+ #x7fffffff)\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (bs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (cs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (ds (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (es (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (fs (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (graph (make-array (* (+ n 1) (+ m 1)) :element-type 'list :initial-element nil)))\n (labels ((to-idx (i j) (+ i (* j (+ n 1))))\n (rev (idx)\n (multiple-value-bind (quot rem) (floor idx (+ n 1))\n (values rem quot))))\n (dotimes (i n)\n (setf (aref as i) (read)\n (aref bs i) (read)\n (aref cs i) (read)))\n (setf (aref cs n) +neg-inf+\n (aref cs (+ n 1)) +pos-inf+)\n (dotimes (i m)\n (setf (aref ds i) (read)\n (aref es i) (read)\n (aref fs i) (read)))\n (setf (aref ds m) +neg-inf+\n (aref ds (+ m 1)) +pos-inf+)\n (parallel-sort! cs #'< as bs)\n (parallel-sort! ds #'< es fs)\n (loop\n for i from 1 below n\n do (loop\n for j from 1 below m\n do (let ((d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (let ((a (aref as (+ i 1)))\n (b (aref bs (+ i 1))))\n (unless (<= a d1 d2 b)\n (push (to-idx (+ i 1) j) (aref graph (to-idx i j)))))\n (let ((a (aref as i))\n (b (aref bs i)))\n (unless (<= a d1 d2 b)\n (push (to-idx (- i 1) j) (aref graph (to-idx i j))))))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1))))\n (let ((e (aref es (+ j 1)))\n (f (aref fs (+ j 1))))\n (unless (<= e c1 c2 f)\n (push (to-idx i (+ j 1)) (aref graph (to-idx i j)))))\n (let ((e (aref es j))\n (f (aref fs j)))\n (unless (<= e c1 c2 f)\n (push (to-idx i (- j 1)) (aref graph (to-idx i j))))))))\n (let* ((init-i (- (bisect-left cs 0) 1))\n (init-j (- (bisect-left ds 0) 1))\n (init (to-idx init-i init-j))\n (marked (make-array (* (+ n 1) (+ m 1)) :element-type 'bit :initial-element 0)))\n (sb-int:named-let dfs ((v init))\n (setf (aref marked v) 1)\n (dolist (next (aref graph v))\n (when (zerop (aref marked next))\n (dfs next))))\n (let ((res 0))\n (dotimes (idx (length marked))\n (when (= 1 (aref marked idx))\n (multiple-value-bind (i j) (rev idx)\n (when (or (= i 0) (= j 0) (= n i) (= m j))\n (write-line \"INF\")\n (return-from main))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1)))\n (d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (incf res (* (- c2 c1) (- d2 d1)))))))\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 \"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\"\n \"INF\n\")))\n", "language": "Lisp", "metadata": {"date": 1589784444, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02680.html", "problem_id": "p02680", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02680/input.txt", "sample_output_relpath": "derived/input_output/data/p02680/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02680/Lisp/s143892929.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s143892929", "user_id": "u352600849"}, "prompt_components": {"gold_output": "13\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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx opt\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 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;;;\n;;; Sort multiple vectors\n;;;\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 (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(defun parallel-shuffle! (vector &rest vectors)\n \"Destructively shuffles VECTOR and applies the same permutation to all the\nvectors in VECTORS.\"\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 (dolist (v vectors)\n (rotatef (aref v i) (aref v j)))\n finally (return vector)))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:define-source-transform parallel-shuffle! (vector &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 (loop for i from (- (length ,vec) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref ,vec i) (aref ,vec j))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym i) (aref ,sym j)))\n finally (return ,vec))))))\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 +neg-inf+ #x-80000000)\n(defconstant +pos-inf+ #x7fffffff)\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (bs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (cs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (ds (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (es (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (fs (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (graph (make-array (* (+ n 1) (+ m 1)) :element-type 'list :initial-element nil)))\n (labels ((to-idx (i j) (+ i (* j (+ n 1))))\n (rev (idx)\n (multiple-value-bind (quot rem) (floor idx (+ n 1))\n (values rem quot))))\n (dotimes (i n)\n (setf (aref as i) (read)\n (aref bs i) (read)\n (aref cs i) (read)))\n (setf (aref cs n) +neg-inf+\n (aref cs (+ n 1)) +pos-inf+)\n (dotimes (i m)\n (setf (aref ds i) (read)\n (aref es i) (read)\n (aref fs i) (read)))\n (setf (aref ds m) +neg-inf+\n (aref ds (+ m 1)) +pos-inf+)\n (parallel-sort! cs #'< as bs)\n (parallel-sort! ds #'< es fs)\n (loop\n for i from 1 below n\n do (loop\n for j from 1 below m\n do (let ((d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (let ((a (aref as (+ i 1)))\n (b (aref bs (+ i 1))))\n (unless (<= a d1 d2 b)\n (push (to-idx (+ i 1) j) (aref graph (to-idx i j)))))\n (let ((a (aref as i))\n (b (aref bs i)))\n (unless (<= a d1 d2 b)\n (push (to-idx (- i 1) j) (aref graph (to-idx i j))))))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1))))\n (let ((e (aref es (+ j 1)))\n (f (aref fs (+ j 1))))\n (unless (<= e c1 c2 f)\n (push (to-idx i (+ j 1)) (aref graph (to-idx i j)))))\n (let ((e (aref es j))\n (f (aref fs j)))\n (unless (<= e c1 c2 f)\n (push (to-idx i (- j 1)) (aref graph (to-idx i j))))))))\n (let* ((init-i (- (bisect-left cs 0) 1))\n (init-j (- (bisect-left ds 0) 1))\n (init (to-idx init-i init-j))\n (marked (make-array (* (+ n 1) (+ m 1)) :element-type 'bit :initial-element 0)))\n (sb-int:named-let dfs ((v init))\n (setf (aref marked v) 1)\n (dolist (next (aref graph v))\n (when (zerop (aref marked next))\n (dfs next))))\n (let ((res 0))\n (dotimes (idx (length marked))\n (when (= 1 (aref marked idx))\n (multiple-value-bind (i j) (rev idx)\n (when (or (= i 0) (= j 0) (= n i) (= m j))\n (write-line \"INF\")\n (return-from main))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1)))\n (d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (incf res (* (- c2 c1) (- d2 d1)))))))\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 \"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\"\n \"INF\n\")))\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "sample_input": "5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n"}, "reference_outputs": ["13\n"], "source_document_id": "p02680", "source_text": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15324, "cpu_time_ms": 293, "memory_kb": 247360}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s060396227", "group_id": "codeNet:p02680", "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 (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;;;\n;;; Sort multiple vectors\n;;;\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 (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(defun parallel-shuffle! (vector &rest vectors)\n \"Destructively shuffles VECTOR and applies the same permutation to all the\nvectors in VECTORS.\"\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 (dolist (v vectors)\n (rotatef (aref v i) (aref v j)))\n finally (return vector)))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:define-source-transform parallel-shuffle! (vector &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 (loop for i from (- (length ,vec) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref ,vec i) (aref ,vec j))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym i) (aref ,sym j)))\n finally (return ,vec))))))\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 +neg-inf+ #x-80000000)\n(defconstant +pos-inf+ #x7fffffff)\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (bs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (cs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (ds (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (es (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (fs (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (graph (make-array (* (+ n 1) (+ m 1)) :element-type 'list :initial-element nil)))\n (labels ((to-idx (i j) (+ i (* j (+ n 1))))\n (rev (idx)\n (multiple-value-bind (quot rem) (floor idx (+ n 1))\n (values rem quot))))\n (dotimes (i n)\n (setf (aref as i) (read)\n (aref bs i) (read)\n (aref cs i) (read)))\n (setf (aref cs n) +neg-inf+\n (aref cs (+ n 1)) +pos-inf+)\n (dotimes (i m)\n (setf (aref ds i) (read)\n (aref es i) (read)\n (aref fs i) (read)))\n (setf (aref ds m) +neg-inf+\n (aref ds (+ m 1)) +pos-inf+)\n (parallel-sort! cs #'< as bs)\n (parallel-sort! ds #'< es fs)\n (loop\n for i from 1 below n\n do (loop\n for j from 1 below m\n do (let ((d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (let ((a (aref as (+ i 1)))\n (b (aref bs (+ i 1))))\n (unless (<= a d1 d2 b)\n (push (to-idx (+ i 1) j) (aref graph (to-idx i j)))))\n (let ((a (aref as i))\n (b (aref bs i)))\n (unless (<= a d1 d2 b)\n (push (to-idx (- i 1) j) (aref graph (to-idx i j))))))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1))))\n (let ((e (aref es (+ j 1)))\n (f (aref fs (+ j 1))))\n (unless (<= e c1 c2 f)\n (push (to-idx i (+ j 1)) (aref graph (to-idx i j)))))\n (let ((e (aref es j))\n (f (aref fs j)))\n (unless (<= e c1 c2 f)\n (push (to-idx i (- j 1)) (aref graph (to-idx i j))))))))\n (let* ((init-i (- (bisect-left cs 0) 1))\n (init-j (- (bisect-left ds 0) 1))\n (init (to-idx init-i init-j))\n (marked (make-array (* (+ n 1) (+ m 1)) :element-type 'bit :initial-element 0)))\n (sb-int:named-let dfs ((v init))\n (setf (aref marked v) 1)\n (dolist (next (aref graph v))\n (when (zerop (aref marked next))\n (dfs next))))\n (let ((res 0))\n (dotimes (idx (length marked))\n (when (= 1 (aref marked idx))\n (multiple-value-bind (i j) (rev idx)\n (when (or (= i 0) (= j 0) (= (+ n 1) i) (= (+ n 1) j))\n (write-line \"INF\")\n (return-from main))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1)))\n (d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (incf res (* (- c2 c1) (- d2 d1)))))))\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 \"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\"\n \"INF\n\")))\n", "language": "Lisp", "metadata": {"date": 1589770554, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02680.html", "problem_id": "p02680", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02680/input.txt", "sample_output_relpath": "derived/input_output/data/p02680/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02680/Lisp/s060396227.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s060396227", "user_id": "u352600849"}, "prompt_components": {"gold_output": "13\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 (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;;;\n;;; Sort multiple vectors\n;;;\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 (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(defun parallel-shuffle! (vector &rest vectors)\n \"Destructively shuffles VECTOR and applies the same permutation to all the\nvectors in VECTORS.\"\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 (dolist (v vectors)\n (rotatef (aref v i) (aref v j)))\n finally (return vector)))\n\n#+sbcl\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:define-source-transform parallel-shuffle! (vector &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 (loop for i from (- (length ,vec) 1) above 0\n for j = (random (+ i 1))\n do (rotatef (aref ,vec i) (aref ,vec j))\n ,@(loop for sym in vecs\n collect `(rotatef (aref ,sym i) (aref ,sym j)))\n finally (return ,vec))))))\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 +neg-inf+ #x-80000000)\n(defconstant +pos-inf+ #x7fffffff)\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (bs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (cs (make-array (+ n 2) :element-type 'int32 :initial-element 0))\n (ds (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (es (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (fs (make-array (+ m 2) :element-type 'int32 :initial-element 0))\n (graph (make-array (* (+ n 1) (+ m 1)) :element-type 'list :initial-element nil)))\n (labels ((to-idx (i j) (+ i (* j (+ n 1))))\n (rev (idx)\n (multiple-value-bind (quot rem) (floor idx (+ n 1))\n (values rem quot))))\n (dotimes (i n)\n (setf (aref as i) (read)\n (aref bs i) (read)\n (aref cs i) (read)))\n (setf (aref cs n) +neg-inf+\n (aref cs (+ n 1)) +pos-inf+)\n (dotimes (i m)\n (setf (aref ds i) (read)\n (aref es i) (read)\n (aref fs i) (read)))\n (setf (aref ds m) +neg-inf+\n (aref ds (+ m 1)) +pos-inf+)\n (parallel-sort! cs #'< as bs)\n (parallel-sort! ds #'< es fs)\n (loop\n for i from 1 below n\n do (loop\n for j from 1 below m\n do (let ((d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (let ((a (aref as (+ i 1)))\n (b (aref bs (+ i 1))))\n (unless (<= a d1 d2 b)\n (push (to-idx (+ i 1) j) (aref graph (to-idx i j)))))\n (let ((a (aref as i))\n (b (aref bs i)))\n (unless (<= a d1 d2 b)\n (push (to-idx (- i 1) j) (aref graph (to-idx i j))))))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1))))\n (let ((e (aref es (+ j 1)))\n (f (aref fs (+ j 1))))\n (unless (<= e c1 c2 f)\n (push (to-idx i (+ j 1)) (aref graph (to-idx i j)))))\n (let ((e (aref es j))\n (f (aref fs j)))\n (unless (<= e c1 c2 f)\n (push (to-idx i (- j 1)) (aref graph (to-idx i j))))))))\n (let* ((init-i (- (bisect-left cs 0) 1))\n (init-j (- (bisect-left ds 0) 1))\n (init (to-idx init-i init-j))\n (marked (make-array (* (+ n 1) (+ m 1)) :element-type 'bit :initial-element 0)))\n (sb-int:named-let dfs ((v init))\n (setf (aref marked v) 1)\n (dolist (next (aref graph v))\n (when (zerop (aref marked next))\n (dfs next))))\n (let ((res 0))\n (dotimes (idx (length marked))\n (when (= 1 (aref marked idx))\n (multiple-value-bind (i j) (rev idx)\n (when (or (= i 0) (= j 0) (= (+ n 1) i) (= (+ n 1) j))\n (write-line \"INF\")\n (return-from main))\n (let ((c1 (aref cs i))\n (c2 (aref cs (+ i 1)))\n (d1 (aref ds j))\n (d2 (aref ds (+ j 1))))\n (incf res (* (- c2 c1) (- d2 d1)))))))\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 \"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\"\n \"13\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\"\n \"INF\n\")))\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "sample_input": "5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n"}, "reference_outputs": ["13\n"], "source_document_id": "p02680", "source_text": "Score: 600 points\n\nProblem Statement\n\nThere is a grass field that stretches infinitely.\n\nIn this field, there is a negligibly small cow. Let (x, y) denote the point that is x\\ \\mathrm{cm} south and y\\ \\mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).\n\nThere are also N north-south lines and M east-west lines drawn on the field. The i-th north-south line is the segment connecting the points (A_i, C_i) and (B_i, C_i), and the j-th east-west line is the segment connecting the points (D_j, E_j) and (D_j, F_j).\n\nWhat is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.\n\nConstraints\n\nAll values in input are integers between -10^9 and 10^9 (inclusive).\n\n1 \\leq N, M \\leq 1000\n\nA_i < B_i\\ (1 \\leq i \\leq N)\n\nE_j < F_j\\ (1 \\leq j \\leq M)\n\nThe point (0, 0) does not lie on any of the given segments.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1 C_1\n:\nA_N B_N C_N\nD_1 E_1 F_1\n:\nD_M E_M F_M\n\nOutput\n\nIf the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in \\mathrm{cm^2}.\n\n(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)\n\nSample Input 1\n\n5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4\n\nSample Output 1\n\n13\n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\nSample Input 2\n\n6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4\n\nSample Output 2\n\nINF\n\nThe area of the region the cow can reach is infinite.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15336, "cpu_time_ms": 274, "memory_kb": 198904}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s461008065", "group_id": "codeNet:p02682", "input_text": "(let ((a (read))\n (b (read))\n (c (read))\n (k (read)))\n (declare (ignore c))\n (cond ((<= k a)\n (format t \"~A~%\" k))\n ((<= k (+ a b))\n (format t \"~A~%\" a))\n (t\n (format t \"~A~%\" (- a (- k a b))))))\n", "language": "Lisp", "metadata": {"date": 1589159542, "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/s461008065.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s461008065", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read))\n (k (read)))\n (declare (ignore c))\n (cond ((<= k a)\n (format t \"~A~%\" k))\n ((<= k (+ a b))\n (format t \"~A~%\" a))\n (t\n (format t \"~A~%\" (- a (- k a b))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 251, "cpu_time_ms": 15, "memory_kb": 24288}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s595628698", "group_id": "codeNet:p02682", "input_text": "(defun solve (A B C K)\n (cond\n ((>= A K) K)\n ((>= (+ A B) K) A)\n (t (- A (- K A B)))))\n\n(princ (solve (read) (read) (read) (read)))", "language": "Lisp", "metadata": {"date": 1589159372, "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/s595628698.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s595628698", "user_id": "u334552723"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve (A B C K)\n (cond\n ((>= A K) K)\n ((>= (+ A B) K) A)\n (t (- A (- K A B)))))\n\n(princ (solve (read) (read) (read) (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 15, "memory_kb": 24296}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s296819206", "group_id": "codeNet:p02683", "input_text": ";;; Utils (quoted from https://competitive12.blogspot.com/2020/03/common-lisp.html)\n\n\n;; Read fixnum\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\n;; invoke child process\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; Write code here\n;-------------------\n\n(defparameter *inf* (expt 10 7))\n\n\n;; scores: '((0 . score0) (1 . score1) ...)\n\n\n(defun solve (n m x cost table)\n (labels ((dp (amount-of-books scores)\n (cond\n ((zerop amount-of-books)\n (if (every (lambda (score) (<= (rest score) 0)) scores)\n 0\n *inf*))\n (t\n (min (dp (1- amount-of-books) scores)\n (+ (dp (1- amount-of-books)\n (mapcar (lambda (score)\n (cons (first score)\n (- (rest score) (aref table (1- amount-of-books) (first score)))))\n scores))\n (aref cost (1- amount-of-books))))))))\n (let (scores)\n (dotimes (i m)\n (push `(,i . ,x) scores))\n (let ((ans (dp n (reverse scores))))\n (if (= ans *inf*)\n -1\n ans)))))\n\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (x (read))\n (cost (make-array n))\n (table (make-array `(,n ,m))))\n (dotimes (i n)\n (setf (aref cost i) (read-fixnum))\n (dotimes (j m)\n (setf (aref table i j) (read-fixnum))))\n (princ (solve n m x cost table))\n (fresh-line)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1594845884, "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/s296819206.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s296819206", "user_id": "u425762225"}, "prompt_components": {"gold_output": "120\n", "input_to_evaluate": ";;; Utils (quoted from https://competitive12.blogspot.com/2020/03/common-lisp.html)\n\n\n;; Read fixnum\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\n;; invoke child process\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; Write code here\n;-------------------\n\n(defparameter *inf* (expt 10 7))\n\n\n;; scores: '((0 . score0) (1 . score1) ...)\n\n\n(defun solve (n m x cost table)\n (labels ((dp (amount-of-books scores)\n (cond\n ((zerop amount-of-books)\n (if (every (lambda (score) (<= (rest score) 0)) scores)\n 0\n *inf*))\n (t\n (min (dp (1- amount-of-books) scores)\n (+ (dp (1- amount-of-books)\n (mapcar (lambda (score)\n (cons (first score)\n (- (rest score) (aref table (1- amount-of-books) (first score)))))\n scores))\n (aref cost (1- amount-of-books))))))))\n (let (scores)\n (dotimes (i m)\n (push `(,i . ,x) scores))\n (let ((ans (dp n (reverse scores))))\n (if (= ans *inf*)\n -1\n ans)))))\n\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (x (read))\n (cost (make-array n))\n (table (make-array `(,n ,m))))\n (dotimes (i n)\n (setf (aref cost i) (read-fixnum))\n (dotimes (j m)\n (setf (aref table i j) (read-fixnum))))\n (princ (solve n m x cost table))\n (fresh-line)))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3108, "cpu_time_ms": 38, "memory_kb": 27008}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s878292121", "group_id": "codeNet:p02683", "input_text": "(defun collect-list (N M &optional result)\n (when (= N 0)\n (return-from collect-list (reverse result)))\n (let ((C (read))\n (column))\n (dotimes (x M)\n (push (read) column))\n (push (list C (reverse column)) result)\n (collect-list (- N 1) M result)))\n\n(defun check-X-over-or-equal (l X)\n (let ((count 0))\n (dolist (a l)\n (when (<= X a)\n (incf count)))\n (= count (length l))))\n\n(defun calc (N M X l &optional (base 0) (result nil))\n (when (= base N)\n (return-from calc result))\n (when (check-X-over-or-equal (cadr (nth base l)) X)\n (push (nth base l) result))\n (do ((tmp-c (car (nth base l)))\n (tmp-l (cadr (nth base l)))\n (pos 0)\n (height-count 0)\n (height 1))\n ((= height N) (calc N M X l (1+ base) result))\n (cond ((<= N pos)\n (incf height)\n (setq pos 0)\n (setq height-count 0)\n (setq tmp-c (car (nth base l)))\n (setq tmp-l (cadr (nth base l))))\n ((= height height-count)\n (when (check-X-over-or-equal tmp-l X)\n (push (list tmp-c tmp-l) result))\n (setq tmp-c (car (nth base l)))\n (setq tmp-l (cadr (nth base l)))\n (setq height-count 0))\n (t\n (unless (= pos base)\n (setq tmp-c (+ tmp-c (car (nth pos l))))\n (setq tmp-l (mapcar #'+ tmp-l (cadr (nth pos l)))))\n (incf height-count)\n (incf pos)))))\n\n(defmacro sort-from-than-smaller (l)\n `(sort ,l #'(lambda (a b)\n (< (car a) (car b)))))\n\n(defmacro remove-not-value-over-or-equal (l target)\n (let ((count (gensym)))\n `(remove-if-not #'(lambda (a)\n (let ((,count 0))\n (dolist (b (cadr a ))\n (when (<= ,target b)\n (incf ,count)))\n (= ,count (length (cadr a)))))\n ,l)))\n\n(defun main ()\n (let ((N (read))\n (M (read))\n (X (read)))\n (let ((tmp (collect-list N M)))\n (let* ((all-combination (calc N M X tmp))\n (result (sort-from-than-smaller all-combination)))\n (princ (if result (caar result) -1))))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1589328321, "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/s878292121.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s878292121", "user_id": "u631655863"}, "prompt_components": {"gold_output": "120\n", "input_to_evaluate": "(defun collect-list (N M &optional result)\n (when (= N 0)\n (return-from collect-list (reverse result)))\n (let ((C (read))\n (column))\n (dotimes (x M)\n (push (read) column))\n (push (list C (reverse column)) result)\n (collect-list (- N 1) M result)))\n\n(defun check-X-over-or-equal (l X)\n (let ((count 0))\n (dolist (a l)\n (when (<= X a)\n (incf count)))\n (= count (length l))))\n\n(defun calc (N M X l &optional (base 0) (result nil))\n (when (= base N)\n (return-from calc result))\n (when (check-X-over-or-equal (cadr (nth base l)) X)\n (push (nth base l) result))\n (do ((tmp-c (car (nth base l)))\n (tmp-l (cadr (nth base l)))\n (pos 0)\n (height-count 0)\n (height 1))\n ((= height N) (calc N M X l (1+ base) result))\n (cond ((<= N pos)\n (incf height)\n (setq pos 0)\n (setq height-count 0)\n (setq tmp-c (car (nth base l)))\n (setq tmp-l (cadr (nth base l))))\n ((= height height-count)\n (when (check-X-over-or-equal tmp-l X)\n (push (list tmp-c tmp-l) result))\n (setq tmp-c (car (nth base l)))\n (setq tmp-l (cadr (nth base l)))\n (setq height-count 0))\n (t\n (unless (= pos base)\n (setq tmp-c (+ tmp-c (car (nth pos l))))\n (setq tmp-l (mapcar #'+ tmp-l (cadr (nth pos l)))))\n (incf height-count)\n (incf pos)))))\n\n(defmacro sort-from-than-smaller (l)\n `(sort ,l #'(lambda (a b)\n (< (car a) (car b)))))\n\n(defmacro remove-not-value-over-or-equal (l target)\n (let ((count (gensym)))\n `(remove-if-not #'(lambda (a)\n (let ((,count 0))\n (dolist (b (cadr a ))\n (when (<= ,target b)\n (incf ,count)))\n (= ,count (length (cadr a)))))\n ,l)))\n\n(defun main ()\n (let ((N (read))\n (M (read))\n (X (read)))\n (let ((tmp (collect-list N M)))\n (let* ((all-combination (calc N M X tmp))\n (result (sort-from-than-smaller all-combination)))\n (princ (if result (caar result) -1))))))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2219, "cpu_time_ms": 17, "memory_kb": 24804}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s985075073", "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 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": 1589162203, "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/s985075073.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s985075073", "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 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 913, "cpu_time_ms": 22, "memory_kb": 27712}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s481093433", "group_id": "codeNet:p02686", "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;;;\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 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(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;; delta . min-delta\n(define-binary-heap heap\n :order (lambda (node1 node2)\n (> (the fixnum (car node1)) (the fixnum (car node2))))\n :element-type list)\n\n(defun main ()\n (let* ((n (read))\n (deltas+ (make-array n :element-type 'list :fill-pointer 0))\n (deltas0 (make-array n :element-type 'list :fill-pointer 0))\n (deltas- (make-array n :element-type 'list :fill-pointer 0)))\n (labels ((no () (write-line \"No\") (return-from main)))\n (let ((potential 0))\n (dotimes (i n)\n (let ((s (read-line))\n (delta 0)\n (min-delta 0))\n (dotimes (j (length s))\n (ecase (aref s j)\n (#\\( (incf delta))\n (#\\) (decf delta)))\n (minf min-delta delta))\n (incf potential delta)\n (cond ((> delta 0)\n (vector-push (cons delta min-delta) deltas+))\n ((< delta 0)\n (vector-push (cons delta min-delta) deltas-))\n (t\n (vector-push (cons delta min-delta) deltas0)))))\n (unless (zerop potential)\n (no)))\n (setq deltas+ (sort deltas+ #'> :key #'cdr))\n (setq deltas- (sort deltas- #'< :key #'cdr))\n #>deltas+\n #>deltas0\n #>deltas-\n (let ((potential 0))\n (loop for (delta . min-delta) across deltas+\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta))\n (loop for (delta . min-delta) across deltas0\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta))\n (loop for (delta . min-delta) across deltas-\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta)))\n (error \"Huh?\")\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 \"2\n)\n(()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n)(\n()\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n((()))\n((((((\n))))))\n()()()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n(((\n)\n)\n\"\n \"No\n\")))\n", "language": "Lisp", "metadata": {"date": 1589164295, "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/s481093433.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s481093433", "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;;;\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 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(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;; delta . min-delta\n(define-binary-heap heap\n :order (lambda (node1 node2)\n (> (the fixnum (car node1)) (the fixnum (car node2))))\n :element-type list)\n\n(defun main ()\n (let* ((n (read))\n (deltas+ (make-array n :element-type 'list :fill-pointer 0))\n (deltas0 (make-array n :element-type 'list :fill-pointer 0))\n (deltas- (make-array n :element-type 'list :fill-pointer 0)))\n (labels ((no () (write-line \"No\") (return-from main)))\n (let ((potential 0))\n (dotimes (i n)\n (let ((s (read-line))\n (delta 0)\n (min-delta 0))\n (dotimes (j (length s))\n (ecase (aref s j)\n (#\\( (incf delta))\n (#\\) (decf delta)))\n (minf min-delta delta))\n (incf potential delta)\n (cond ((> delta 0)\n (vector-push (cons delta min-delta) deltas+))\n ((< delta 0)\n (vector-push (cons delta min-delta) deltas-))\n (t\n (vector-push (cons delta min-delta) deltas0)))))\n (unless (zerop potential)\n (no)))\n (setq deltas+ (sort deltas+ #'> :key #'cdr))\n (setq deltas- (sort deltas- #'< :key #'cdr))\n #>deltas+\n #>deltas0\n #>deltas-\n (let ((potential 0))\n (loop for (delta . min-delta) across deltas+\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta))\n (loop for (delta . min-delta) across deltas0\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta))\n (loop for (delta . min-delta) across deltas-\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta)))\n (error \"Huh?\")\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 \"2\n)\n(()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n)(\n()\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n((()))\n((((((\n))))))\n()()()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n(((\n)\n)\n\"\n \"No\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11385, "cpu_time_ms": 376, "memory_kb": 105252}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s048898048", "group_id": "codeNet:p02686", "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;;;\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 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(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;; delta . min-delta\n(define-binary-heap heap\n :order (lambda (node1 node2)\n (> (the fixnum (car node1)) (the fixnum (car node2))))\n :element-type list)\n\n(defun main ()\n (let* ((n (read))\n (deltas+ (make-array n :element-type 'list :fill-pointer 0))\n (deltas0 (make-array n :element-type 'list :fill-pointer 0))\n (deltas- (make-array n :element-type 'list :fill-pointer 0)))\n (labels ((no () (write-line \"No\") (return-from main)))\n (let ((potential 0))\n (dotimes (i n)\n (let ((s (read-line))\n (delta 0)\n (min-delta 0))\n (dotimes (j (length s))\n (ecase (aref s j)\n (#\\( (incf delta))\n (#\\) (decf delta)))\n (minf min-delta delta))\n (incf potential delta)\n (cond ((> delta 0)\n (vector-push (cons delta min-delta) deltas+))\n ((< delta 0)\n (vector-push (cons delta min-delta) deltas-))\n (t\n (vector-push (cons delta min-delta) deltas0)))))\n (unless (zerop potential)\n (no)))\n (setq deltas+ (sort deltas+ #'> :key #'cdr))\n (setq deltas- (sort deltas- #'< :key #'cdr))\n #>deltas+\n #>deltas0\n #>deltas-\n (let ((potential 0))\n (loop for (delta . min-delta) across deltas+\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta))\n (loop for (delta . min-delta) across deltas0\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta))\n (loop for (delta . min-delta) across deltas-\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta)))\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 \"2\n)\n(()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n)(\n()\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n((()))\n((((((\n))))))\n()()()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n(((\n)\n)\n\"\n \"No\n\")))\n", "language": "Lisp", "metadata": {"date": 1589164091, "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/s048898048.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s048898048", "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;;;\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 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(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;; delta . min-delta\n(define-binary-heap heap\n :order (lambda (node1 node2)\n (> (the fixnum (car node1)) (the fixnum (car node2))))\n :element-type list)\n\n(defun main ()\n (let* ((n (read))\n (deltas+ (make-array n :element-type 'list :fill-pointer 0))\n (deltas0 (make-array n :element-type 'list :fill-pointer 0))\n (deltas- (make-array n :element-type 'list :fill-pointer 0)))\n (labels ((no () (write-line \"No\") (return-from main)))\n (let ((potential 0))\n (dotimes (i n)\n (let ((s (read-line))\n (delta 0)\n (min-delta 0))\n (dotimes (j (length s))\n (ecase (aref s j)\n (#\\( (incf delta))\n (#\\) (decf delta)))\n (minf min-delta delta))\n (incf potential delta)\n (cond ((> delta 0)\n (vector-push (cons delta min-delta) deltas+))\n ((< delta 0)\n (vector-push (cons delta min-delta) deltas-))\n (t\n (vector-push (cons delta min-delta) deltas0)))))\n (unless (zerop potential)\n (no)))\n (setq deltas+ (sort deltas+ #'> :key #'cdr))\n (setq deltas- (sort deltas- #'< :key #'cdr))\n #>deltas+\n #>deltas0\n #>deltas-\n (let ((potential 0))\n (loop for (delta . min-delta) across deltas+\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta))\n (loop for (delta . min-delta) across deltas0\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta))\n (loop for (delta . min-delta) across deltas-\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta)))\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 \"2\n)\n(()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n)(\n()\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n((()))\n((((((\n))))))\n()()()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n(((\n)\n)\n\"\n \"No\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11364, "cpu_time_ms": 380, "memory_kb": 103284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s425542574", "group_id": "codeNet:p02686", "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;;;\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 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(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;; delta . min-delta\n(define-binary-heap heap\n :order (lambda (node1 node2)\n (> (the fixnum (car node1)) (the fixnum (car node2))))\n :element-type list)\n\n(defun main ()\n (let* ((n (read))\n (deltas+ (make-array n :element-type 'list :fill-pointer 0))\n (deltas- (make-array n :element-type 'list :fill-pointer 0)))\n (labels ((no () (write-line \"No\") (return-from main)))\n (let ((potential 0))\n (dotimes (i n)\n (let ((s (read-line))\n (delta 0)\n (min-delta most-positive-fixnum))\n (dotimes (j (length s))\n (ecase (aref s j)\n (#\\( (incf delta))\n (#\\) (decf delta)))\n (minf min-delta delta))\n (incf potential delta)\n (if (> delta 0)\n (vector-push (cons delta min-delta) deltas+)\n (vector-push (cons delta min-delta) deltas-))))\n (unless (zerop potential)\n (no)))\n (setq deltas+ (sort deltas+ #'> :key #'cdr))\n (setq deltas- (sort deltas- #'< :key #'cdr))\n (let ((potential 0))\n (loop for (delta . min-delta) across deltas+\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta))\n (loop for (delta . min-delta) across deltas-\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta)))\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 \"2\n)\n(()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n)(\n()\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n((()))\n((((((\n))))))\n()()()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n(((\n)\n)\n\"\n \"No\n\")))\n", "language": "Lisp", "metadata": {"date": 1589163874, "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/s425542574.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s425542574", "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;;;\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 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(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;; delta . min-delta\n(define-binary-heap heap\n :order (lambda (node1 node2)\n (> (the fixnum (car node1)) (the fixnum (car node2))))\n :element-type list)\n\n(defun main ()\n (let* ((n (read))\n (deltas+ (make-array n :element-type 'list :fill-pointer 0))\n (deltas- (make-array n :element-type 'list :fill-pointer 0)))\n (labels ((no () (write-line \"No\") (return-from main)))\n (let ((potential 0))\n (dotimes (i n)\n (let ((s (read-line))\n (delta 0)\n (min-delta most-positive-fixnum))\n (dotimes (j (length s))\n (ecase (aref s j)\n (#\\( (incf delta))\n (#\\) (decf delta)))\n (minf min-delta delta))\n (incf potential delta)\n (if (> delta 0)\n (vector-push (cons delta min-delta) deltas+)\n (vector-push (cons delta min-delta) deltas-))))\n (unless (zerop potential)\n (no)))\n (setq deltas+ (sort deltas+ #'> :key #'cdr))\n (setq deltas- (sort deltas- #'< :key #'cdr))\n (let ((potential 0))\n (loop for (delta . min-delta) across deltas+\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta))\n (loop for (delta . min-delta) across deltas-\n when (< (+ potential min-delta) 0)\n do (no)\n do (incf potential delta)))\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 \"2\n)\n(()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n)(\n()\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n((()))\n((((((\n))))))\n()()()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n(((\n)\n)\n\"\n \"No\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10972, "cpu_time_ms": 417, "memory_kb": 103676}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s943308939", "group_id": "codeNet:p02686", "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;;; 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 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(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;; delta\n(define-binary-heap heap\n :order #'>\n :element-type fixnum)\n\n(defun main ()\n (let* ((n (read))\n (deltas (make-array n :element-type 'list))\n (que (make-heap n)))\n (dotimes (i n)\n (let ((s (read-line))\n (delta 0)\n (min-delta 0))\n (dotimes (j (length s))\n (ecase (aref s j)\n (#\\( (incf delta))\n (#\\) (decf delta)))\n (minf min-delta delta))\n (setf (aref deltas i) (cons delta min-delta))))\n (setq deltas (sort deltas #'> :key #'cdr))\n (unless (zerop (reduce #'+ deltas :key #'car))\n (write-line \"No\")\n (return-from main))\n (let ((potential 0)\n (pos 0))\n (dotimes (i n)\n (loop (when (= pos n)\n (return))\n (destructuring-bind (delta . min-delta) (aref deltas pos)\n (when (< (+ potential min-delta) 0)\n (return))\n (heap-push delta que)\n (incf pos)))\n (when (heap-empty-p que)\n (write-line \"No\")\n (return-from main))\n (let ((delta (heap-pop que)))\n (incf potential delta))))\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 \"2\n)\n(()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n)(\n()\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n((()))\n((((((\n))))))\n()()()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n(((\n)\n)\n\"\n \"No\n\")))\n", "language": "Lisp", "metadata": {"date": 1589161933, "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/s943308939.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s943308939", "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;;; 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 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(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;; delta\n(define-binary-heap heap\n :order #'>\n :element-type fixnum)\n\n(defun main ()\n (let* ((n (read))\n (deltas (make-array n :element-type 'list))\n (que (make-heap n)))\n (dotimes (i n)\n (let ((s (read-line))\n (delta 0)\n (min-delta 0))\n (dotimes (j (length s))\n (ecase (aref s j)\n (#\\( (incf delta))\n (#\\) (decf delta)))\n (minf min-delta delta))\n (setf (aref deltas i) (cons delta min-delta))))\n (setq deltas (sort deltas #'> :key #'cdr))\n (unless (zerop (reduce #'+ deltas :key #'car))\n (write-line \"No\")\n (return-from main))\n (let ((potential 0)\n (pos 0))\n (dotimes (i n)\n (loop (when (= pos n)\n (return))\n (destructuring-bind (delta . min-delta) (aref deltas pos)\n (when (< (+ potential min-delta) 0)\n (return))\n (heap-push delta que)\n (incf pos)))\n (when (heap-empty-p que)\n (write-line \"No\")\n (return-from main))\n (let ((delta (heap-pop que)))\n (incf potential delta))))\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 \"2\n)\n(()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n)(\n()\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n((()))\n((((((\n))))))\n()()()\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n(((\n)\n)\n\"\n \"No\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10684, "cpu_time_ms": 650, "memory_kb": 111452}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s814457938", "group_id": "codeNet:p02687", "input_text": "(let ((s (read-line)))\n (format t \"~a~%\" (if (string= s \"ABC\")\n \"ARC\"\n \"ABC\")))\n", "language": "Lisp", "metadata": {"date": 1588554069, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02687.html", "problem_id": "p02687", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02687/input.txt", "sample_output_relpath": "derived/input_output/data/p02687/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02687/Lisp/s814457938.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s814457938", "user_id": "u690263481"}, "prompt_components": {"gold_output": "ARC\n", "input_to_evaluate": "(let ((s (read-line)))\n (format t \"~a~%\" (if (string= s \"ABC\")\n \"ARC\"\n \"ABC\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAtCoder Inc. holds a contest every Saturday.\n\nThere are two types of contests called ABC and ARC, and just one of them is held at a time.\n\nThe company holds these two types of contests alternately: an ARC follows an ABC and vice versa.\n\nGiven a string S representing the type of the contest held last week, print the string representing the type of the contest held this week.\n\nConstraints\n\nS is ABC or ARC.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the string representing the type of the contest held this week.\n\nSample Input 1\n\nABC\n\nSample Output 1\n\nARC\n\nThey held an ABC last week, so they will hold an ARC this week.", "sample_input": "ABC\n"}, "reference_outputs": ["ARC\n"], "source_document_id": "p02687", "source_text": "Score : 100 points\n\nProblem Statement\n\nAtCoder Inc. holds a contest every Saturday.\n\nThere are two types of contests called ABC and ARC, and just one of them is held at a time.\n\nThe company holds these two types of contests alternately: an ARC follows an ABC and vice versa.\n\nGiven a string S representing the type of the contest held last week, print the string representing the type of the contest held this week.\n\nConstraints\n\nS is ABC or ARC.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the string representing the type of the contest held this week.\n\nSample Input 1\n\nABC\n\nSample Output 1\n\nARC\n\nThey held an ABC last week, so they will hold an ARC this week.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 13, "memory_kb": 24200}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s165689827", "group_id": "codeNet:p02688", "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 *sunuke-n* *okashi-n*))\n(defvar *sunuke-n* (read))\n(defvar *okashi-n* (read))\n\n(declaim (type (simple-array boolean (*)) *victims*))\n;; sunuke n is a victim when (aref *victims* (1- n))\n(defvar *victims* (make-array *sunuke-n*\n\t\t\t :initial-element t\n\t\t\t :element-type 'boolean))\n\n(dotimes (okashi-i *okashi-n*)\n (let ((d (read)))\n (declare (type fixnum d))\n (dotimes (i d)\n (let ((sunuke-id (read)))\n\t(declare (type fixnum sunuke-id))\n\t(setf (aref *victims* (1- sunuke-id)) nil)))))\n\n(princ (count t *victims*))\n", "language": "Lisp", "metadata": {"date": 1590177950, "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/s165689827.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s165689827", "user_id": "u203134021"}, "prompt_components": {"gold_output": "1\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 *sunuke-n* *okashi-n*))\n(defvar *sunuke-n* (read))\n(defvar *okashi-n* (read))\n\n(declaim (type (simple-array boolean (*)) *victims*))\n;; sunuke n is a victim when (aref *victims* (1- n))\n(defvar *victims* (make-array *sunuke-n*\n\t\t\t :initial-element t\n\t\t\t :element-type 'boolean))\n\n(dotimes (okashi-i *okashi-n*)\n (let ((d (read)))\n (declare (type fixnum d))\n (dotimes (i d)\n (let ((sunuke-id (read)))\n\t(declare (type fixnum sunuke-id))\n\t(setf (aref *victims* (1- sunuke-id)) nil)))))\n\n(princ (count t *victims*))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 730, "cpu_time_ms": 18, "memory_kb": 29828}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s915190337", "group_id": "codeNet:p02688", "input_text": "(let ((N (read)))\n (defvar arr (make-array N :initial-element 1))\n (loop repeat (read) do\n (loop repeat (read) do\n (setf (aref arr (1- (read))) 0)))\n (princ (loop for x across arr sum x)))", "language": "Lisp", "metadata": {"date": 1588554365, "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/s915190337.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s915190337", "user_id": "u334552723"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((N (read)))\n (defvar arr (make-array N :initial-element 1))\n (loop repeat (read) do\n (loop repeat (read) do\n (setf (aref arr (1- (read))) 0)))\n (princ (loop for x across arr sum x)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 226, "cpu_time_ms": 21, "memory_kb": 29880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s218697737", "group_id": "codeNet:p02688", "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 (k (read))\n (mat (make-array (list n k) :element-type 'bit :initial-element 0)))\n (dotimes (j k)\n (let ((d (read)))\n (dotimes (_ d)\n (let ((a (- (read) 1)))\n (setf (aref mat a j) 1)))))\n (println\n (loop for i below n\n count (loop for j below k\n always (zerop (aref mat i j)))))))\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\n2\n1 3\n1\n3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1\n3\n1\n3\n1\n3\n\"\n \"2\n\")))\n", "language": "Lisp", "metadata": {"date": 1588554173, "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/s218697737.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s218697737", "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(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 (k (read))\n (mat (make-array (list n k) :element-type 'bit :initial-element 0)))\n (dotimes (j k)\n (let ((d (read)))\n (dotimes (_ d)\n (let ((a (- (read) 1)))\n (setf (aref mat a j) 1)))))\n (println\n (loop for i below n\n count (loop for j below k\n always (zerop (aref mat i j)))))))\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\n2\n1 3\n1\n3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1\n3\n1\n3\n1\n3\n\"\n \"2\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3882, "cpu_time_ms": 20, "memory_kb": 30116}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s495449045", "group_id": "codeNet:p02689", "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(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 solve (n)\n n)\n\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (h (read-numbers-to-array n))\n (edges (make-array n :initial-element nil)))\n (loop repeat m do\n (let ((a (1- (read)))\n (b (1- (read))))\n (push a (aref edges b))\n (push b (aref edges a))))\n (let ((res 0))\n (loop for i below n do\n (let ((edges-i (aref edges i))\n (flag t))\n (loop for edge in edges-i do\n (when (<= (aref h i)\n (aref h edge))\n (setf flag nil))\n finally\n (when flag\n (incf res))))\n finally\n (format t \"~a~&\" res)))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1599188776, "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/s495449045.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s495449045", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\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(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 solve (n)\n n)\n\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (h (read-numbers-to-array n))\n (edges (make-array n :initial-element nil)))\n (loop repeat m do\n (let ((a (1- (read)))\n (b (1- (read))))\n (push a (aref edges b))\n (push b (aref edges a))))\n (let ((res 0))\n (loop for i below n do\n (let ((edges-i (aref edges i))\n (flag t))\n (loop for edge in edges-i do\n (when (<= (aref h i)\n (aref h edge))\n (setf flag nil))\n finally\n (when flag\n (incf res))))\n finally\n (format t \"~a~&\" res)))))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2692, "cpu_time_ms": 315, "memory_kb": 85568}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s449318561", "group_id": "codeNet:p02689", "input_text": "(let* ((N (read))\n (M (read))\n (H-array (make-array N))\n (graph (make-hash-table))\n (result 0))\n (loop for i below N\n do (progn\n (setf (aref H-array i) (read))\n (setf (gethash i graph) nil)))\n (dotimes (x M)\n (let ((l (- (read) 1))\n (r (- (read) 1)))\n (push l (gethash r graph))\n (push r (gethash l graph))))\n (maphash (lambda (key value)\n (if value\n (let ((tmp 0))\n (dolist (x value)\n (when (< (aref H-array x) (aref H-array key))\n (incf tmp)))\n (when (= tmp (length value))\n (incf result)))\n (incf result)))\n graph)\n (princ result))\n", "language": "Lisp", "metadata": {"date": 1588562475, "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/s449318561.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s449318561", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((N (read))\n (M (read))\n (H-array (make-array N))\n (graph (make-hash-table))\n (result 0))\n (loop for i below N\n do (progn\n (setf (aref H-array i) (read))\n (setf (gethash i graph) nil)))\n (dotimes (x M)\n (let ((l (- (read) 1))\n (r (- (read) 1)))\n (push l (gethash r graph))\n (push r (gethash l graph))))\n (maphash (lambda (key value)\n (if value\n (let ((tmp 0))\n (dolist (x value)\n (when (< (aref H-array x) (aref H-array key))\n (incf tmp)))\n (when (= tmp (length value))\n (incf result)))\n (incf result)))\n graph)\n (princ result))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 768, "cpu_time_ms": 316, "memory_kb": 87252}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s609819878", "group_id": "codeNet:p02689", "input_text": "(defun calc (n hs lst)\n (loop with c = 0\n for i from 1 to n\n do (loop with ok-flag = 1\n for j in lst\n if (find i j)\n do (if (<= (aref hs (1- i))\n (aref hs (1- (car (remove i j)))))\n (setf ok-flag 0))\n finally (if (= 1 ok-flag)\n (incf c)))\n finally (return c)))\n\n(let* ((n (read))\n (m (read))\n (hs (make-array n\n :initial-contents\n (loop repeat n collect (read))))\n (lst (loop repeat m\n collect (list (read) (read)))))\n (format t \"~A\" (calc n hs lst)))", "language": "Lisp", "metadata": {"date": 1588562365, "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/s609819878.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s609819878", "user_id": "u425317134"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun calc (n hs lst)\n (loop with c = 0\n for i from 1 to n\n do (loop with ok-flag = 1\n for j in lst\n if (find i j)\n do (if (<= (aref hs (1- i))\n (aref hs (1- (car (remove i j)))))\n (setf ok-flag 0))\n finally (if (= 1 ok-flag)\n (incf c)))\n finally (return c)))\n\n(let* ((n (read))\n (m (read))\n (hs (make-array n\n :initial-contents\n (loop repeat n collect (read))))\n (lst (loop repeat m\n collect (list (read) (read)))))\n (format t \"~A\" (calc n hs lst)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 699, "cpu_time_ms": 2208, "memory_kb": 85060}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s227745307", "group_id": "codeNet:p02689", "input_text": "(let* ((N (read))\n (M (read))\n (H-array (make-array N))\n (graph (make-hash-table))\n (result 0))\n (loop for i below N\n do (progn\n (setf (aref H-array i) (read))\n (setf (gethash (1+ i) graph) nil)))\n (dotimes (x M)\n (let ((l (- (read) 1))\n (r (- (read) 1)))\n (push l (gethash r graph))\n (push r (gethash l graph))))\n (maphash (lambda (key value)\n (when value\n (let ((tmp 0))\n (dolist (x value)\n (when (<= (aref H-array x) (aref H-array key))\n (incf tmp)))\n (when (= tmp (length value))\n (incf result)))))\n graph)\n (princ result))", "language": "Lisp", "metadata": {"date": 1588562129, "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/s227745307.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s227745307", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((N (read))\n (M (read))\n (H-array (make-array N))\n (graph (make-hash-table))\n (result 0))\n (loop for i below N\n do (progn\n (setf (aref H-array i) (read))\n (setf (gethash (1+ i) graph) nil)))\n (dotimes (x M)\n (let ((l (- (read) 1))\n (r (- (read) 1)))\n (push l (gethash r graph))\n (push r (gethash l graph))))\n (maphash (lambda (key value)\n (when value\n (let ((tmp 0))\n (dolist (x value)\n (when (<= (aref H-array x) (aref H-array key))\n (incf tmp)))\n (when (= tmp (length value))\n (incf result)))))\n graph)\n (princ result))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 351, "memory_kb": 87252}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s267996367", "group_id": "codeNet:p02689", "input_text": "(let* ((n (read))\n (m (read))\n (h (make-array n :element-type 'fixnum :initial-contents (loop :repeat n :collect (read))))\n (ans (make-array n :element-type 'fixnum :initial-element 0)))\n (loop :repeat m :do (funcall (lambda (x y)\n (cond ((< (aref h x) (aref h y))\n (incf (aref ans x)))\n ((> (aref h x) (aref h y))\n (incf (aref ans y)))\n ((= (aref h x) (aref h y))\n (incf (aref ans x))\n (incf (aref ans y)))))\n (1- (read)) (1- (read))))\n (princ (count 0 ans)))", "language": "Lisp", "metadata": {"date": 1588556301, "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/s267996367.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s267996367", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (h (make-array n :element-type 'fixnum :initial-contents (loop :repeat n :collect (read))))\n (ans (make-array n :element-type 'fixnum :initial-element 0)))\n (loop :repeat m :do (funcall (lambda (x y)\n (cond ((< (aref h x) (aref h y))\n (incf (aref ans x)))\n ((> (aref h x) (aref h y))\n (incf (aref ans y)))\n ((= (aref h x) (aref h y))\n (incf (aref ans x))\n (incf (aref ans y)))))\n (1- (read)) (1- (read))))\n (princ (count 0 ans)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 774, "cpu_time_ms": 307, "memory_kb": 80444}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s054010904", "group_id": "codeNet:p02689", "input_text": "(let* ((n (read))\n (m (read))\n (h (make-array n :element-type 'fixnum :initial-contents (loop :repeat n :collect (read))))\n (ans (make-array n :element-type 'fixnum :initial-element 0)))\n (loop :repeat m :do (funcall (lambda (x y) (if (< (aref h x) (aref h x))\n (incf (aref ans x))\n (incf (aref ans y)))) (1- (read)) (1- (read))))\n (princ (count 0 ans)))", "language": "Lisp", "metadata": {"date": 1588554996, "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/s054010904.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s054010904", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (h (make-array n :element-type 'fixnum :initial-contents (loop :repeat n :collect (read))))\n (ans (make-array n :element-type 'fixnum :initial-element 0)))\n (loop :repeat m :do (funcall (lambda (x y) (if (< (aref h x) (aref h x))\n (incf (aref ans x))\n (incf (aref ans y)))) (1- (read)) (1- (read))))\n (princ (count 0 ans)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 470, "cpu_time_ms": 308, "memory_kb": 80420}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s590108018", "group_id": "codeNet:p02690", "input_text": "(let ((x (read)))\n (loop :named main\n :for i :from -118 :to 119\n :do (loop :for j :from -118 :to (1- i)\n :if (= (- (expt i 5) (expt j 5)) x)\n :do (progn\n (format t \"~A ~A~%\" i j)\n (return-from main)))))\n", "language": "Lisp", "metadata": {"date": 1594256767, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02690.html", "problem_id": "p02690", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02690/input.txt", "sample_output_relpath": "derived/input_output/data/p02690/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02690/Lisp/s590108018.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s590108018", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2 -1\n", "input_to_evaluate": "(let ((x (read)))\n (loop :named main\n :for i :from -118 :to 119\n :do (loop :for j :from -118 :to (1- i)\n :if (= (- (expt i 5) (expt j 5)) x)\n :do (progn\n (format t \"~A ~A~%\" i j)\n (return-from main)))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGive a pair of integers (A, B) such that A^5-B^5 = X.\nIt is guaranteed that there exists such a pair for the given integer X.\n\nConstraints\n\n1 \\leq X \\leq 10^9\n\nX is an integer.\n\nThere exists a pair of integers (A, B) satisfying the condition in Problem Statement.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint A and B, with space in between.\nIf there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.\n\nA B\n\nSample Input 1\n\n33\n\nSample Output 1\n\n2 -1\n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n0 -1", "sample_input": "33\n"}, "reference_outputs": ["2 -1\n"], "source_document_id": "p02690", "source_text": "Score : 400 points\n\nProblem Statement\n\nGive a pair of integers (A, B) such that A^5-B^5 = X.\nIt is guaranteed that there exists such a pair for the given integer X.\n\nConstraints\n\n1 \\leq X \\leq 10^9\n\nX is an integer.\n\nThere exists a pair of integers (A, B) satisfying the condition in Problem Statement.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint A and B, with space in between.\nIf there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.\n\nA B\n\nSample Input 1\n\n33\n\nSample Output 1\n\n2 -1\n\nFor A=2 and B=-1, A^5-B^5 = 33.\n\nSample Input 2\n\n1\n\nSample Output 2\n\n0 -1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 298, "cpu_time_ms": 16, "memory_kb": 24432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s648518101", "group_id": "codeNet:p02691", "input_text": "(let* ((n (read))\n (a (make-array (1+ n))))\n (loop for i from 1 to n\n do (setf (aref a i) (read)))\n (format t \"~A~%\" (loop for i from 1 to (1- n)\n sum (loop for j from (1+ i) to n\n count (eql (- j i) (+ (aref a i) (aref a j)))))))", "language": "Lisp", "metadata": {"date": 1588559172, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02691.html", "problem_id": "p02691", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02691/input.txt", "sample_output_relpath": "derived/input_output/data/p02691/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02691/Lisp/s648518101.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s648518101", "user_id": "u607637432"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((n (read))\n (a (make-array (1+ n))))\n (loop for i from 1 to n\n do (setf (aref a i) (read)))\n (format t \"~A~%\" (loop for i from 1 to (1- n)\n sum (loop for j from (1+ i) to n\n count (eql (- j i) (+ (aref a i) (aref a j)))))))", "problem_context": "Score: 500 points\n\nProblem Statement\n\nYou are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.\n\nThere are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i.\n\nAccording to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.\n\nThe absolute difference of their attendee numbers is equal to the sum of their heights.\n\nThere are \\frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above?\n\nP.S.: We cannot let you know the secret.\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\\ (1 \\leq i \\leq N)\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 number of pairs satisfying the condition.\n\nSample Input 1\n\n6\n2 3 3 1 3 1\n\nSample Output 1\n\n3\n\nA_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n\nA_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n\nA_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\nSample Input 2\n\n6\n5 2 4 2 8 8\n\nSample Output 2\n\n0\n\nNo pair satisfies the condition, so you should print 0.\n\nSample Input 3\n\n32\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5\n\nSample Output 3\n\n22", "sample_input": "6\n2 3 3 1 3 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02691", "source_text": "Score: 500 points\n\nProblem Statement\n\nYou are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.\n\nThere are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i.\n\nAccording to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.\n\nThe absolute difference of their attendee numbers is equal to the sum of their heights.\n\nThere are \\frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above?\n\nP.S.: We cannot let you know the secret.\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\\ (1 \\leq i \\leq N)\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 number of pairs satisfying the condition.\n\nSample Input 1\n\n6\n2 3 3 1 3 1\n\nSample Output 1\n\n3\n\nA_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n\nA_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n\nA_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\nSample Input 2\n\n6\n5 2 4 2 8 8\n\nSample Output 2\n\n0\n\nNo pair satisfies the condition, so you should print 0.\n\nSample Input 3\n\n32\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5\n\nSample Output 3\n\n22", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2207, "memory_kb": 77644}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s932421458", "group_id": "codeNet:p02693", "input_text": "(let* ((n (read))\n (m (cons (read) (read))))\n (if (loop :for k :from (car m) :upto (cdr m)\n :never (= 0 (mod k n)))\n (princ \"NG\")\n (princ \"OK\")))", "language": "Lisp", "metadata": {"date": 1588606634, "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/s932421458.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s932421458", "user_id": "u610490393"}, "prompt_components": {"gold_output": "OK\n", "input_to_evaluate": "(let* ((n (read))\n (m (cons (read) (read))))\n (if (loop :for k :from (car m) :upto (cdr m)\n :never (= 0 (mod k n)))\n (princ \"NG\")\n (princ \"OK\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 14, "memory_kb": 23820}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s606297515", "group_id": "codeNet:p02693", "input_text": "(let* ((k (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\"\n (if (or (>= (- (truncate b k)\n (truncate a k))\n 1)\n (zerop (mod a k)))\n \"OK\"\n \"NG\")))", "language": "Lisp", "metadata": {"date": 1588485275, "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/s606297515.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s606297515", "user_id": "u607637432"}, "prompt_components": {"gold_output": "OK\n", "input_to_evaluate": "(let* ((k (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\"\n (if (or (>= (- (truncate b k)\n (truncate a k))\n 1)\n (zerop (mod a k)))\n \"OK\"\n \"NG\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 257, "cpu_time_ms": 15, "memory_kb": 24096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s825007580", "group_id": "codeNet:p02693", "input_text": "(let* ((k (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\"\n (if (>= (- (truncate b k)\n (truncate a k))\n 1)\n \"OK\"\n \"NG\")))", "language": "Lisp", "metadata": {"date": 1588485143, "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/s825007580.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s825007580", "user_id": "u607637432"}, "prompt_components": {"gold_output": "OK\n", "input_to_evaluate": "(let* ((k (read))\n (a (read))\n (b (read)))\n (format t \"~A~%\"\n (if (>= (- (truncate b k)\n (truncate a k))\n 1)\n \"OK\"\n \"NG\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 14, "memory_kb": 24144}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s829718579", "group_id": "codeNet:p02693", "input_text": "(defmacro while (test &body body) \n 2 `(do () \n 3 ((not ,test)) \n 4 ,@body)) \n 5 \n 6(defun main () \n 7 (let ((k (read)) \n 8 (a (read)) \n 9 (b (read)) \n10 (ans \"NG\")) \n11 (while (<= a b) \n12 (when (zerop (rem a k)) \n13 (setf ans \"OK\") \n14 (return)) \n15 (incf a)) \n16 (format t \"~a~%\" ans))) \n17 \n18(main) ", "language": "Lisp", "metadata": {"date": 1588469352, "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/s829718579.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s829718579", "user_id": "u091381267"}, "prompt_components": {"gold_output": "OK\n", "input_to_evaluate": "(defmacro while (test &body body) \n 2 `(do () \n 3 ((not ,test)) \n 4 ,@body)) \n 5 \n 6(defun main () \n 7 (let ((k (read)) \n 8 (a (read)) \n 9 (b (read)) \n10 (ans \"NG\")) \n11 (while (<= a b) \n12 (when (zerop (rem a k)) \n13 (setf ans \"OK\") \n14 (return)) \n15 (incf a)) \n16 (format t \"~a~%\" ans))) \n17 \n18(main) ", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3520, "cpu_time_ms": 86, "memory_kb": 26868}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s786515374", "group_id": "codeNet:p02693", "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* ((k (read))\n (a (read))\n (b (read)))\n (loop for x from a to b\n when (zerop (mod x k))\n do (write-line \"OK\")\n (return-from main))\n (write-line \"NG\")))\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\n500 600\n\"\n \"OK\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n5 7\n\"\n \"NG\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n11 11\n\"\n \"OK\n\")))\n", "language": "Lisp", "metadata": {"date": 1588468249, "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/s786515374.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s786515374", "user_id": "u352600849"}, "prompt_components": {"gold_output": "OK\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* ((k (read))\n (a (read))\n (b (read)))\n (loop for x from a to b\n when (zerop (mod x k))\n do (write-line \"OK\")\n (return-from main))\n (write-line \"NG\")))\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\n500 600\n\"\n \"OK\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n5 7\n\"\n \"NG\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n11 11\n\"\n \"OK\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3764, "cpu_time_ms": 18, "memory_kb": 23972}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s205461752", "group_id": "codeNet:p02694", "input_text": "(defun calc (target &optional (n 100) (year 0))\n (if (<= target n)\n year\n (calc target (+ n (floor (* n 0.01))) (1+ year))))\n\n(princ (calc (read)))", "language": "Lisp", "metadata": {"date": 1588477454, "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/s205461752.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s205461752", "user_id": "u631655863"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun calc (target &optional (n 100) (year 0))\n (if (<= target n)\n year\n (calc target (+ n (floor (* n 0.01))) (1+ year))))\n\n(princ (calc (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 158, "cpu_time_ms": 17, "memory_kb": 24420}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s831282416", "group_id": "codeNet:p02694", "input_text": "(format t \"~d~%\"\n\t(1+ (loop with x = (read)\n\t for y = (floor (* 100 101) 100) then (floor (* y 101) 100)\n\t until (<= x y)\n\t count t)))", "language": "Lisp", "metadata": {"date": 1588470659, "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/s831282416.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s831282416", "user_id": "u320993798"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(format t \"~d~%\"\n\t(1+ (loop with x = (read)\n\t for y = (floor (* 100 101) 100) then (floor (* y 101) 100)\n\t until (<= x y)\n\t count t)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 24408}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s836602699", "group_id": "codeNet:p02694", "input_text": "(defun calc (x)\n (loop with c = 0\n with now = 100\n while (< now x)\n do (setf now (floor (* now 1.01)))\n (incf c)\n finally (return c)))\n\n(let ((x (read)))\n (format t \"~A\" (calc x)))\n", "language": "Lisp", "metadata": {"date": 1588469293, "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/s836602699.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s836602699", "user_id": "u425317134"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun calc (x)\n (loop with c = 0\n with now = 100\n while (< now x)\n do (setf now (floor (* now 1.01)))\n (incf c)\n finally (return c)))\n\n(let ((x (read)))\n (format t \"~A\" (calc x)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 24476}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s369326002", "group_id": "codeNet:p02696", "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* ((a (read))\n (b (read))\n (n (read)))\n (labels ((calc (x)\n (- (floor (* a x) b)\n (* a (floor x b)))))\n (println\n (cond ((= b 1) 0)\n ((<= (- b 1) n)\n (calc (- b 1)))\n (t (calc 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 \"5 7 4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"11 10 9\n\"\n \"9\n\")))\n", "language": "Lisp", "metadata": {"date": 1588469696, "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/s369326002.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s369326002", "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 #\\# #\\> (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* ((a (read))\n (b (read))\n (n (read)))\n (labels ((calc (x)\n (- (floor (* a x) b)\n (* a (floor x b)))))\n (println\n (cond ((= b 1) 0)\n ((<= (- b 1) n)\n (calc (- b 1)))\n (t (calc 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 \"5 7 4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"11 10 9\n\"\n \"9\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3764, "cpu_time_ms": 16, "memory_kb": 24808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s790474805", "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 (let ((lst (calc n m)))\n (if (and (evenp n)\n (evenp m))\n (progn\n (incf (caar lst))\n (loop for i in lst\n do (format t \"~A ~A~&\" (car i) (cadr i))))\n (loop for i in (calc n m)\n do (format t \"~A ~A~&\" (car i) (cadr i))))))\n", "language": "Lisp", "metadata": {"date": 1588474380, "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/s790474805.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s790474805", "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 (let ((lst (calc n m)))\n (if (and (evenp n)\n (evenp m))\n (progn\n (incf (caar lst))\n (loop for i in lst\n do (format t \"~A ~A~&\" (car i) (cadr i))))\n (loop for i in (calc n m)\n do (format t \"~A ~A~&\" (car i) (cadr i))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 525, "cpu_time_ms": 249, "memory_kb": 55080}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s149653532", "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 (assert (<= m (floor n 2)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (cond ((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 flag = nil\n for i from 1 below m\n for j = (+ 1 (- n i))\n do (when (zerop (mod (abs (- i j)) (ash n -1)))\n (setq flag t))\n (dbg i j flag)\n (if flag\n (format t \"~D ~D~%\" i (- j 1))\n (format t \"~D ~D~%\" i j)))\n (format t \"~D ~D~%\" m (- n m))\n ;; (error \"Huh?\")\n )\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": 1588474113, "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/s149653532.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s149653532", "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 (assert (<= m (floor n 2)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (cond ((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 flag = nil\n for i from 1 below m\n for j = (+ 1 (- n i))\n do (when (zerop (mod (abs (- i j)) (ash n -1)))\n (setq flag t))\n (dbg i j flag)\n (if flag\n (format t \"~D ~D~%\" i (- j 1))\n (format t \"~D ~D~%\" i j)))\n (format t \"~D ~D~%\" m (- n m))\n ;; (error \"Huh?\")\n )\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5178, "cpu_time_ms": 52, "memory_kb": 27348}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s133037883", "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 main ()\n (let* ((n (read))\n (m (read)))\n (assert (<= m (floor n 2)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (cond ((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 ;; (loop for i from 1 below m\n ;; do (format t \"~D ~D~%\" i (+ 1 (- n i))))\n ;; (format t \"~D ~D~%\" m (- n m))\n ;; (error \"Huh?\")\n )\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": 1588473403, "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/s133037883.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s133037883", "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 main ()\n (let* ((n (read))\n (m (read)))\n (assert (<= m (floor n 2)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (cond ((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 ;; (loop for i from 1 below m\n ;; do (format t \"~D ~D~%\" i (+ 1 (- n i))))\n ;; (format t \"~D ~D~%\" m (- n m))\n ;; (error \"Huh?\")\n )\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4176, "cpu_time_ms": 103, "memory_kb": 27500}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s947784740", "group_id": "codeNet:p02698", "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 (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(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;;; 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 (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 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(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 the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of the elements in 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 (optimize (speed 3))\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(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP 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 (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 (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 (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 (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;; merge/split version of itreap-query (a bit slower but simpler)\n;; FIXME: might be problematic when two priorities collide.\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 ((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\n;; merge/split version of itreap-update (a bit slower but simpler)\n#|\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\n\n;;;\n;;; Utilities for sorted treap\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\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 (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31 :initial-element 0))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-itreap n))\n (res (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((table (make-monotone-inverse-table! (copy-seq as))))\n (dotimes (i n)\n (setf (aref as i) (gethash (aref as i) table))))\n (dotimes (i (- n 1))\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (push u (aref graph v))\n (push v (aref graph u))))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (let* ((a (aref as v))\n (prev-value (itreap-ref dp a))\n (current-max (itreap-query dp 0 a)))\n (declare (fixnum prev-value current-max))\n (when (> (+ current-max 1) prev-value)\n (setf (itreap-ref dp a) (+ current-max 1)))\n (setf (aref res v) (itreap-query dp 0 n))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (dfs child v)))\n (setf (itreap-ref dp a) prev-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 \"10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n\"\n \"1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n\")))\n", "language": "Lisp", "metadata": {"date": 1588483510, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02698.html", "problem_id": "p02698", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02698/input.txt", "sample_output_relpath": "derived/input_output/data/p02698/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02698/Lisp/s947784740.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s947784740", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n2\n3\n3\n4\n4\n5\n2\n2\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(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(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;;; 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 (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 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(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 the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of the elements in 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 (optimize (speed 3))\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(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP 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 (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 (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 (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 (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;; merge/split version of itreap-query (a bit slower but simpler)\n;; FIXME: might be problematic when two priorities collide.\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 ((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\n;; merge/split version of itreap-update (a bit slower but simpler)\n#|\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\n\n;;;\n;;; Utilities for sorted treap\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\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 (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint31 :initial-element 0))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-itreap n))\n (res (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((table (make-monotone-inverse-table! (copy-seq as))))\n (dotimes (i n)\n (setf (aref as i) (gethash (aref as i) table))))\n (dotimes (i (- n 1))\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (push u (aref graph v))\n (push v (aref graph u))))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (let* ((a (aref as v))\n (prev-value (itreap-ref dp a))\n (current-max (itreap-query dp 0 a)))\n (declare (fixnum prev-value current-max))\n (when (> (+ current-max 1) prev-value)\n (setf (itreap-ref dp a) (+ current-max 1)))\n (setf (aref res v) (itreap-query dp 0 n))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (dfs child v)))\n (setf (itreap-ref dp a) prev-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 \"10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n\"\n \"1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices, whose i-th edge connects Vertex u_i and Vertex v_i.\nVertex i has an integer a_i written on it.\nFor every integer k from 1 through N, solve the following problem:\n\nWe will make a sequence by lining up the integers written on the vertices along the shortest path from Vertex 1 to Vertex k, in the order they appear. Find the length of the longest increasing subsequence of this sequence.\n\nHere, the longest increasing subsequence of a sequence A of length L is the subsequence A_{i_1} , A_{i_2} , ... , A_{i_M} with the greatest possible value of M such that 1 \\leq i_1 < i_2 < ... < i_M \\leq L and A_{i_1} < A_{i_2} < ... < A_{i_M}.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq a_i \\leq 10^9\n\n1 \\leq u_i , v_i \\leq N\n\nu_i \\neq v_i\n\nThe given graph is a tree.\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\nu_1 v_1\nu_2 v_2\n:\nu_{N-1} v_{N-1}\n\nOutput\n\nPrint N lines. The k-th line, print the length of the longest increasing subsequence of the sequence obtained from the shortest path from Vertex 1 to Vertex k.\n\nSample Input 1\n\n10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n\nSample Output 1\n\n1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n\nFor example, the sequence A obtained from the shortest path from Vertex 1 to Vertex 5 is 1,2,5,3,4. Its longest increasing subsequence is A_1, A_2, A_4, A_5, with the length of 4.", "sample_input": "10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n"}, "reference_outputs": ["1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n"], "source_document_id": "p02698", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices, whose i-th edge connects Vertex u_i and Vertex v_i.\nVertex i has an integer a_i written on it.\nFor every integer k from 1 through N, solve the following problem:\n\nWe will make a sequence by lining up the integers written on the vertices along the shortest path from Vertex 1 to Vertex k, in the order they appear. Find the length of the longest increasing subsequence of this sequence.\n\nHere, the longest increasing subsequence of a sequence A of length L is the subsequence A_{i_1} , A_{i_2} , ... , A_{i_M} with the greatest possible value of M such that 1 \\leq i_1 < i_2 < ... < i_M \\leq L and A_{i_1} < A_{i_2} < ... < A_{i_M}.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq a_i \\leq 10^9\n\n1 \\leq u_i , v_i \\leq N\n\nu_i \\neq v_i\n\nThe given graph is a tree.\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\nu_1 v_1\nu_2 v_2\n:\nu_{N-1} v_{N-1}\n\nOutput\n\nPrint N lines. The k-th line, print the length of the longest increasing subsequence of the sequence obtained from the shortest path from Vertex 1 to Vertex k.\n\nSample Input 1\n\n10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n\nSample Output 1\n\n1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n\nFor example, the sequence A obtained from the shortest path from Vertex 1 to Vertex 5 is 1,2,5,3,4. Its longest increasing subsequence is A_1, A_2, A_4, A_5, with the length of 4.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 27355, "cpu_time_ms": 425, "memory_kb": 79016}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s490632091", "group_id": "codeNet:p02698", "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 (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(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;;; 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 (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 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 (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(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(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 the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of the elements in 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 (optimize (speed 3))\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(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP 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 (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 (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 (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 (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;; merge/split version of itreap-query (a bit slower but simpler)\n;; FIXME: might be problematic when two priorities collide.\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 ((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\n;; merge/split version of itreap-update (a bit slower but simpler)\n#|\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\n\n;;;\n;;; Utilities for sorted treap\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\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 (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-itreap n))\n (res (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((table (make-monotone-inverse-table! (copy-seq as))))\n (dotimes (i n)\n (setf (aref as i) (gethash (aref as i) table))))\n #>as\n (dotimes (i (- n 1))\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (push u (aref graph v))\n (push v (aref graph u))))\n #>dp\n (sb-int:named-let dfs ((v 0) (parent -1))\n (let* ((a (aref as v))\n (prev-value (itreap-ref dp a))\n (current-max (itreap-query dp 0 a)))\n (when (> (+ current-max 1) prev-value)\n (setf (itreap-ref dp a) (+ current-max 1)))\n (setf (aref res v) (itreap-query dp 0 n))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (dfs child v)))\n (setf (itreap-ref dp a) prev-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 \"10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n\"\n \"1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n\")))\n", "language": "Lisp", "metadata": {"date": 1588471201, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02698.html", "problem_id": "p02698", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02698/input.txt", "sample_output_relpath": "derived/input_output/data/p02698/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02698/Lisp/s490632091.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s490632091", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n2\n3\n3\n4\n4\n5\n2\n2\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(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(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;;; 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 (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 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 (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(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(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 the ITREAP into two nodes [0, INDEX) and [INDEX, N),\nwhere N is the number of the elements in 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 (optimize (speed 3))\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(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP 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 (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 (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 (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 (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;; merge/split version of itreap-query (a bit slower but simpler)\n;; FIXME: might be problematic when two priorities collide.\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 ((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\n;; merge/split version of itreap-update (a bit slower but simpler)\n#|\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\n\n;;;\n;;; Utilities for sorted treap\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\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 (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-itreap n))\n (res (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (let ((table (make-monotone-inverse-table! (copy-seq as))))\n (dotimes (i n)\n (setf (aref as i) (gethash (aref as i) table))))\n #>as\n (dotimes (i (- n 1))\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (push u (aref graph v))\n (push v (aref graph u))))\n #>dp\n (sb-int:named-let dfs ((v 0) (parent -1))\n (let* ((a (aref as v))\n (prev-value (itreap-ref dp a))\n (current-max (itreap-query dp 0 a)))\n (when (> (+ current-max 1) prev-value)\n (setf (itreap-ref dp a) (+ current-max 1)))\n (setf (aref res v) (itreap-query dp 0 n))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (dfs child v)))\n (setf (itreap-ref dp a) prev-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 \"10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n\"\n \"1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices, whose i-th edge connects Vertex u_i and Vertex v_i.\nVertex i has an integer a_i written on it.\nFor every integer k from 1 through N, solve the following problem:\n\nWe will make a sequence by lining up the integers written on the vertices along the shortest path from Vertex 1 to Vertex k, in the order they appear. Find the length of the longest increasing subsequence of this sequence.\n\nHere, the longest increasing subsequence of a sequence A of length L is the subsequence A_{i_1} , A_{i_2} , ... , A_{i_M} with the greatest possible value of M such that 1 \\leq i_1 < i_2 < ... < i_M \\leq L and A_{i_1} < A_{i_2} < ... < A_{i_M}.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq a_i \\leq 10^9\n\n1 \\leq u_i , v_i \\leq N\n\nu_i \\neq v_i\n\nThe given graph is a tree.\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\nu_1 v_1\nu_2 v_2\n:\nu_{N-1} v_{N-1}\n\nOutput\n\nPrint N lines. The k-th line, print the length of the longest increasing subsequence of the sequence obtained from the shortest path from Vertex 1 to Vertex k.\n\nSample Input 1\n\n10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n\nSample Output 1\n\n1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n\nFor example, the sequence A obtained from the shortest path from Vertex 1 to Vertex 5 is 1,2,5,3,4. Its longest increasing subsequence is A_1, A_2, A_4, A_5, with the length of 4.", "sample_input": "10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n"}, "reference_outputs": ["1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n"], "source_document_id": "p02698", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices, whose i-th edge connects Vertex u_i and Vertex v_i.\nVertex i has an integer a_i written on it.\nFor every integer k from 1 through N, solve the following problem:\n\nWe will make a sequence by lining up the integers written on the vertices along the shortest path from Vertex 1 to Vertex k, in the order they appear. Find the length of the longest increasing subsequence of this sequence.\n\nHere, the longest increasing subsequence of a sequence A of length L is the subsequence A_{i_1} , A_{i_2} , ... , A_{i_M} with the greatest possible value of M such that 1 \\leq i_1 < i_2 < ... < i_M \\leq L and A_{i_1} < A_{i_2} < ... < A_{i_M}.\n\nConstraints\n\n2 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq a_i \\leq 10^9\n\n1 \\leq u_i , v_i \\leq N\n\nu_i \\neq v_i\n\nThe given graph is a tree.\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\nu_1 v_1\nu_2 v_2\n:\nu_{N-1} v_{N-1}\n\nOutput\n\nPrint N lines. The k-th line, print the length of the longest increasing subsequence of the sequence obtained from the shortest path from Vertex 1 to Vertex k.\n\nSample Input 1\n\n10\n1 2 5 3 4 6 7 3 2 4\n1 2\n2 3\n3 4\n4 5\n3 6\n6 7\n1 8\n8 9\n9 10\n\nSample Output 1\n\n1\n2\n3\n3\n4\n4\n5\n2\n2\n3\n\nFor example, the sequence A obtained from the shortest path from Vertex 1 to Vertex 5 is 1,2,5,3,4. Its longest increasing subsequence is A_1, A_2, A_4, A_5, with the length of 4.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 27311, "cpu_time_ms": 458, "memory_kb": 91936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s203355259", "group_id": "codeNet:p02699", "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 *sheep-n* (read))\n(defvar *wolf-n* (read))\n\n(format t \"~:[safe~;unsafe~]\" (>= *wolf-n* *sheep-n*))\n", "language": "Lisp", "metadata": {"date": 1590266113, "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/s203355259.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s203355259", "user_id": "u203134021"}, "prompt_components": {"gold_output": "unsafe\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 *sheep-n* (read))\n(defvar *wolf-n* (read))\n\n(format t \"~:[safe~;unsafe~]\" (>= *wolf-n* *sheep-n*))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 281, "cpu_time_ms": 14, "memory_kb": 23836}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s967497282", "group_id": "codeNet:p02699", "input_text": "(if (<= (read) (read))\n (princ \"unsafe\")\n (princ \"safe\"))", "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/s967497282.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s967497282", "user_id": "u610490393"}, "prompt_components": {"gold_output": "unsafe\n", "input_to_evaluate": "(if (<= (read) (read))\n (princ \"unsafe\")\n (princ \"safe\"))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 63, "cpu_time_ms": 14, "memory_kb": 24124}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s561337007", "group_id": "codeNet:p02701", "input_text": "(princ (length (remove-duplicates (loop for i below (read) collect (read)) :test #'equal)))\n", "language": "Lisp", "metadata": {"date": 1592878891, "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/s561337007.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s561337007", "user_id": "u136500538"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ (length (remove-duplicates (loop for i below (read) collect (read)) :test #'equal)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 511, "memory_kb": 92884}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s448366915", "group_id": "codeNet:p02701", "input_text": "(let* ((N (read))\n (result 0)\n (exist-array (make-array N))\n (pos 0))\n (dotimes (x N)\n (let ((tmp (read-line)))\n (unless (find tmp exist-array :test #'equal)\n (incf result)\n (setf (aref exist-array pos) tmp)\n (incf pos))))\n (princ result))\n", "language": "Lisp", "metadata": {"date": 1587954918, "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/s448366915.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s448366915", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((N (read))\n (result 0)\n (exist-array (make-array N))\n (pos 0))\n (dotimes (x N)\n (let ((tmp (read-line)))\n (unless (find tmp exist-array :test #'equal)\n (incf result)\n (setf (aref exist-array pos) tmp)\n (incf pos))))\n (princ result))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2206, "memory_kb": 75348}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s734563988", "group_id": "codeNet:p02701", "input_text": "(princ (length (delete-duplicates (loop for i below (read) collect (read)) :test #'equal)))", "language": "Lisp", "metadata": {"date": 1587954472, "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/s734563988.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s734563988", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ (length (delete-duplicates (loop for i below (read) collect (read)) :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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2208, "memory_kb": 91920}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s676617599", "group_id": "codeNet:p02701", "input_text": "(let ((n (read)))\n (declare (type fixnum n))\n (loop with arr = (make-array 10\n :initial-contents\n (loop repeat 10\n collect '()))\n repeat n\n do (let ((word (read-line)))\n (if (not (find word (aref arr (1- (length word))) \n :test #'string=))\n (push word (aref arr (1- (length word))))))\n finally (format t \"~A\" (apply #'+\n (mapcar #'length\n (coerce arr 'list))))))\n", "language": "Lisp", "metadata": {"date": 1587952517, "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/s676617599.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s676617599", "user_id": "u425317134"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((n (read)))\n (declare (type fixnum n))\n (loop with arr = (make-array 10\n :initial-contents\n (loop repeat 10\n collect '()))\n repeat n\n do (let ((word (read-line)))\n (if (not (find word (aref arr (1- (length word))) \n :test #'string=))\n (push word (aref arr (1- (length word))))))\n finally (format t \"~A\" (apply #'+\n (mapcar #'length\n (coerce arr 'list))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 667, "cpu_time_ms": 2206, "memory_kb": 77004}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s534291112", "group_id": "codeNet:p02704", "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 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(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-condition infeasible () ())\n\n(defun solve (n rows cols mat)\n (declare ((simple-array bit (* *)) mat))\n (setq rows (sort rows #'> :key #'second))\n (setq cols (sort cols #'> :key #'second))\n (loop for row-node in rows\n for col-node in cols\n for (row row-lo row-hi) = row-node\n for (col col-lo col-hi) = col-node\n while (and (> row-lo 0) (> col-lo 0))\n do (setf (aref mat row col) 1)\n (decf (second row-node))\n (decf (second col-node))\n (decf (third row-node))\n (decf (third col-node)))\n (let ((cols cols)\n (pos (position-if (lambda (node) (> (second node) 0)) rows)))\n (when pos\n (loop for row-node in (nthcdr pos rows)\n for (row row-lo row-hi) = row-node\n when (> row-lo 0)\n do (assert (<= row-lo 1))\n (loop (when (<= row-lo 0)\n (return))\n (unless (car cols)\n (error 'infeasible))\n (destructuring-bind (col col-lo col-hi) (car cols)\n (if (<= col-hi 0)\n (pop cols)\n (progn\n (decf row-lo)\n (decf row-hi)\n (decf (second row-node))\n (decf (third row-node))\n (decf (second (car cols)))\n (decf (third (car cols)))\n (setf (aref mat row col) 1)\n (return))))))))\n (let ((rows rows)\n (pos (position-if (lambda (node) (> (second node) 0)) cols)))\n (when pos\n (loop for col-node in (nthcdr pos cols)\n for (col col-lo col-hi) = col-node\n when (> col-lo 0)\n do (assert (<= col-lo 1))\n (loop (when (<= col-lo 0)\n (return))\n (unless (car rows)\n (error 'infeasible))\n (destructuring-bind (row row-lo row-hi) (car rows)\n (if (<= row-hi 0)\n (pop rows)\n (progn\n (decf col-lo)\n (decf col-hi)\n (decf (second col-node))\n (decf (third col-node))\n (decf (second (car rows)))\n (decf (third (car rows)))\n (setf (aref mat row col) 1)\n (return))))))))\n mat)\n\n(defun main ()\n (let* ((n (read))\n (ss (make-array n :element-type 'bit :initial-element 0))\n (ts (make-array n :element-type 'bit :initial-element 0))\n (us (make-array n :element-type 'uint64 :initial-element 0))\n (vs (make-array n :element-type 'uint64 :initial-element 0))\n (res (make-array (list n n) :element-type 'uint64 :initial-element 0)))\n (dotimes (i n)\n (setf (aref ss i) (read)))\n (dotimes (i n)\n (setf (aref ts i) (read)))\n (dotimes (i n)\n (setf (aref us i) (read)))\n (dotimes (i n)\n (setf (aref vs i) (read)))\n (handler-bind ((infeasible (lambda (c) (println -1) (return-from main))))\n (dotimes (pos 64)\n (let (rows ; row lo hi\n cols\n (row-offset 0)\n (col-offset 0)\n (mat (make-array (list n n) :element-type 'bit :initial-element 0)))\n (declare ((simple-array bit (* *)) mat))\n (dotimes (row n)\n (let ((s (aref ss row))\n (u (ldb (byte 1 pos) (aref us row))))\n (when (and (= s 0) (= u 1))\n (incf col-offset)\n (dotimes (j n)\n (setf (aref mat row j) 1)))))\n (dotimes (col n)\n (let ((tt (aref ts col))\n (v (ldb (byte 1 pos) (aref vs col))))\n (when (and (= tt 0) (= v 1))\n (incf row-offset)\n (dotimes (i n)\n (setf (aref mat i col) 1)))))\n (dotimes (row n)\n (let ((s (aref ss row))\n (u (ldb (byte 1 pos) (aref us row))))\n (cond ((and (= s 0) (= u 0))\n (when (< (- n 1 row-offset) 0)\n (error 'infeasible))\n (push (list row 0 (- n 1 row-offset)) rows))\n ((and (= s 1) (= u 1))\n (when (< (- 1 row-offset) 0)\n (error 'infeasible))\n (push (list row (- 1 row-offset) (- n row-offset)) rows)))))\n (dotimes (col n)\n (let ((tt (aref ts col))\n (v (ldb (byte 1 pos) (aref vs col))))\n (cond ((and (= tt 0) (= v 0))\n (when (< (- n 1 col-offset) 0)\n (error 'infeasible))\n (push (list col 0 (- n 1 col-offset)) cols))\n ((and (= tt 1) (= v 1))\n (when (< (- 1 col-offset) 0)\n (error 'infeasible))\n (push (list col (- 1 col-offset) (- n col-offset)) cols)))))\n (solve n rows cols mat)\n (dotimes (i n)\n (dotimes (j n)\n (setf (ldb (byte 1 pos) (aref res i j))\n (aref mat i j)))))))\n (println-matrix 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\n0 1\n1 0\n1 1\n1 0\n\"\n \"1 1\n1 0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 1\n1 0\n15 15\n15 11\n\"\n \"15 11\n15 11\n\")))\n", "language": "Lisp", "metadata": {"date": 1587955042, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02704.html", "problem_id": "p02704", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02704/input.txt", "sample_output_relpath": "derived/input_output/data/p02704/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02704/Lisp/s534291112.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s534291112", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 1\n1 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(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(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-condition infeasible () ())\n\n(defun solve (n rows cols mat)\n (declare ((simple-array bit (* *)) mat))\n (setq rows (sort rows #'> :key #'second))\n (setq cols (sort cols #'> :key #'second))\n (loop for row-node in rows\n for col-node in cols\n for (row row-lo row-hi) = row-node\n for (col col-lo col-hi) = col-node\n while (and (> row-lo 0) (> col-lo 0))\n do (setf (aref mat row col) 1)\n (decf (second row-node))\n (decf (second col-node))\n (decf (third row-node))\n (decf (third col-node)))\n (let ((cols cols)\n (pos (position-if (lambda (node) (> (second node) 0)) rows)))\n (when pos\n (loop for row-node in (nthcdr pos rows)\n for (row row-lo row-hi) = row-node\n when (> row-lo 0)\n do (assert (<= row-lo 1))\n (loop (when (<= row-lo 0)\n (return))\n (unless (car cols)\n (error 'infeasible))\n (destructuring-bind (col col-lo col-hi) (car cols)\n (if (<= col-hi 0)\n (pop cols)\n (progn\n (decf row-lo)\n (decf row-hi)\n (decf (second row-node))\n (decf (third row-node))\n (decf (second (car cols)))\n (decf (third (car cols)))\n (setf (aref mat row col) 1)\n (return))))))))\n (let ((rows rows)\n (pos (position-if (lambda (node) (> (second node) 0)) cols)))\n (when pos\n (loop for col-node in (nthcdr pos cols)\n for (col col-lo col-hi) = col-node\n when (> col-lo 0)\n do (assert (<= col-lo 1))\n (loop (when (<= col-lo 0)\n (return))\n (unless (car rows)\n (error 'infeasible))\n (destructuring-bind (row row-lo row-hi) (car rows)\n (if (<= row-hi 0)\n (pop rows)\n (progn\n (decf col-lo)\n (decf col-hi)\n (decf (second col-node))\n (decf (third col-node))\n (decf (second (car rows)))\n (decf (third (car rows)))\n (setf (aref mat row col) 1)\n (return))))))))\n mat)\n\n(defun main ()\n (let* ((n (read))\n (ss (make-array n :element-type 'bit :initial-element 0))\n (ts (make-array n :element-type 'bit :initial-element 0))\n (us (make-array n :element-type 'uint64 :initial-element 0))\n (vs (make-array n :element-type 'uint64 :initial-element 0))\n (res (make-array (list n n) :element-type 'uint64 :initial-element 0)))\n (dotimes (i n)\n (setf (aref ss i) (read)))\n (dotimes (i n)\n (setf (aref ts i) (read)))\n (dotimes (i n)\n (setf (aref us i) (read)))\n (dotimes (i n)\n (setf (aref vs i) (read)))\n (handler-bind ((infeasible (lambda (c) (println -1) (return-from main))))\n (dotimes (pos 64)\n (let (rows ; row lo hi\n cols\n (row-offset 0)\n (col-offset 0)\n (mat (make-array (list n n) :element-type 'bit :initial-element 0)))\n (declare ((simple-array bit (* *)) mat))\n (dotimes (row n)\n (let ((s (aref ss row))\n (u (ldb (byte 1 pos) (aref us row))))\n (when (and (= s 0) (= u 1))\n (incf col-offset)\n (dotimes (j n)\n (setf (aref mat row j) 1)))))\n (dotimes (col n)\n (let ((tt (aref ts col))\n (v (ldb (byte 1 pos) (aref vs col))))\n (when (and (= tt 0) (= v 1))\n (incf row-offset)\n (dotimes (i n)\n (setf (aref mat i col) 1)))))\n (dotimes (row n)\n (let ((s (aref ss row))\n (u (ldb (byte 1 pos) (aref us row))))\n (cond ((and (= s 0) (= u 0))\n (when (< (- n 1 row-offset) 0)\n (error 'infeasible))\n (push (list row 0 (- n 1 row-offset)) rows))\n ((and (= s 1) (= u 1))\n (when (< (- 1 row-offset) 0)\n (error 'infeasible))\n (push (list row (- 1 row-offset) (- n row-offset)) rows)))))\n (dotimes (col n)\n (let ((tt (aref ts col))\n (v (ldb (byte 1 pos) (aref vs col))))\n (cond ((and (= tt 0) (= v 0))\n (when (< (- n 1 col-offset) 0)\n (error 'infeasible))\n (push (list col 0 (- n 1 col-offset)) cols))\n ((and (= tt 1) (= v 1))\n (when (< (- 1 col-offset) 0)\n (error 'infeasible))\n (push (list col (- 1 col-offset) (- n col-offset)) cols)))))\n (solve n rows cols mat)\n (dotimes (i n)\n (dotimes (j n)\n (setf (ldb (byte 1 pos) (aref res i j))\n (aref mat i j)))))))\n (println-matrix 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\n0 1\n1 0\n1 1\n1 0\n\"\n \"1 1\n1 0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 1\n1 0\n15 15\n15 11\n\"\n \"15 11\n15 11\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are an integer N and arrays S, T, U, and V, each of length N.\nConstruct an N×N matrix a that satisfy the following conditions:\n\na_{i,j} is an integer.\n\n0 \\leq a_{i,j} \\lt 2^{64}.\n\nIf S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.\n\nIf S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.\n\nIf T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.\n\nIf T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.\n\nHowever, there may be cases where no matrix satisfies the conditions.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 500\n\n0 \\leq S_{i} \\leq 1\n\n0 \\leq T_{i} \\leq 1\n\n0 \\leq U_{i} \\lt 2^{64}\n\n0 \\leq V_{i} \\lt 2^{64}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_{1} S_{2} ... S_{N}\nT_{1} T_{2} ... T_{N}\nU_{1} U_{2} ... U_{N}\nV_{1} V_{2} ... V_{N}\n\nOutput\n\nIf there exists a matrix that satisfies the conditions, print one such matrix in the following format:\n\na_{1,1} ... a_{1,N}\n:\na_{N,1} ... a_{N,N}\n\nNote that any matrix satisfying the conditions is accepted.\n\nIf no matrix satisfies the conditions, print -1.\n\nSample Input 1\n\n2\n0 1\n1 0\n1 1\n1 0\n\nSample Output 1\n\n1 1\n1 0\n\nIn Sample Input 1, we need to find a matrix such that:\n\nthe bitwise AND of the elements in the 1-st row is 1;\n\nthe bitwise OR of the elements in the 2-nd row is 1;\n\nthe bitwise OR of the elements in the 1-st column is 1;\n\nthe bitwise AND of the elements in the 2-nd column is 0.\n\nSample Input 2\n\n2\n1 1\n1 0\n15 15\n15 11\n\nSample Output 2\n\n15 11\n15 11", "sample_input": "2\n0 1\n1 0\n1 1\n1 0\n"}, "reference_outputs": ["1 1\n1 0\n"], "source_document_id": "p02704", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are an integer N and arrays S, T, U, and V, each of length N.\nConstruct an N×N matrix a that satisfy the following conditions:\n\na_{i,j} is an integer.\n\n0 \\leq a_{i,j} \\lt 2^{64}.\n\nIf S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.\n\nIf S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.\n\nIf T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.\n\nIf T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.\n\nHowever, there may be cases where no matrix satisfies the conditions.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 500\n\n0 \\leq S_{i} \\leq 1\n\n0 \\leq T_{i} \\leq 1\n\n0 \\leq U_{i} \\lt 2^{64}\n\n0 \\leq V_{i} \\lt 2^{64}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_{1} S_{2} ... S_{N}\nT_{1} T_{2} ... T_{N}\nU_{1} U_{2} ... U_{N}\nV_{1} V_{2} ... V_{N}\n\nOutput\n\nIf there exists a matrix that satisfies the conditions, print one such matrix in the following format:\n\na_{1,1} ... a_{1,N}\n:\na_{N,1} ... a_{N,N}\n\nNote that any matrix satisfying the conditions is accepted.\n\nIf no matrix satisfies the conditions, print -1.\n\nSample Input 1\n\n2\n0 1\n1 0\n1 1\n1 0\n\nSample Output 1\n\n1 1\n1 0\n\nIn Sample Input 1, we need to find a matrix such that:\n\nthe bitwise AND of the elements in the 1-st row is 1;\n\nthe bitwise OR of the elements in the 2-nd row is 1;\n\nthe bitwise OR of the elements in the 1-st column is 1;\n\nthe bitwise AND of the elements in the 2-nd column is 0.\n\nSample Input 2\n\n2\n1 1\n1 0\n15 15\n15 11\n\nSample Output 2\n\n15 11\n15 11", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9660, "cpu_time_ms": 458, "memory_kb": 50364}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s521181085", "group_id": "codeNet:p02706", "input_text": "(let ((n (read))\n\t (m (read)))\n (loop repeat m\n\t\t summing (read) into sum\n\t\t finally (format t \"~D~%\" (if (< n sum) -1 (- n sum)))))", "language": "Lisp", "metadata": {"date": 1587347335, "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/s521181085.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s521181085", "user_id": "u756033787"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": "(let ((n (read))\n\t (m (read)))\n (loop repeat m\n\t\t summing (read) into sum\n\t\t finally (format t \"~D~%\" (if (< n sum) -1 (- n sum)))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 21, "memory_kb": 29700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s680755340", "group_id": "codeNet:p02707", "input_text": "(let* ((n (read)))\n (loop :for k :from 1 :upto n\n :with j := (loop :repeat (1- n) :collect (read))\n :do(format t \"~A~%\" (count k j :test #'=))))", "language": "Lisp", "metadata": {"date": 1588059310, "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/s680755340.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s680755340", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n2\n0\n0\n0\n", "input_to_evaluate": "(let* ((n (read)))\n (loop :for k :from 1 :upto n\n :with j := (loop :repeat (1- n) :collect (read))\n :do(format t \"~A~%\" (count k j :test #'=))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2208, "memory_kb": 80124}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s232398216", "group_id": "codeNet:p02707", "input_text": "(let* ((N (read))\n (member-number (loop for i below N\n collect 0))\n (boss-list (loop for i below (- N 1)\n collect (read))))\n (dolist (x boss-list)\n (unless (< (- x 1) 0)\n (incf (nth (- x 1) member-number))))\n (dolist (x member-number) (princ x) (fresh-line)))\n", "language": "Lisp", "metadata": {"date": 1587874533, "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/s232398216.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s232398216", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2\n2\n0\n0\n0\n", "input_to_evaluate": "(let* ((N (read))\n (member-number (loop for i below N\n collect 0))\n (boss-list (loop for i below (- N 1)\n collect (read))))\n (dolist (x boss-list)\n (unless (< (- x 1) 0)\n (incf (nth (- x 1) member-number))))\n (dolist (x member-number) (princ x) (fresh-line)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2208, "memory_kb": 83060}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s632342440", "group_id": "codeNet:p02707", "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 &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\t (reverse (cons str acc)))))\n\n(defparameter n (read))\n(defparameter a (mapcar #'parse-integer (split \" \" (read-line))))\n(defparameter members '())\n\n(dotimes (i n)\n\t(push '() members))\n\n(dolist (e a)\n\t(push e (nth (1- e) members)))\n\n(dolist (m members)\n\t(princ (length m))\n\t(terpri))\n", "language": "Lisp", "metadata": {"date": 1587347395, "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/s632342440.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s632342440", "user_id": "u684901760"}, "prompt_components": {"gold_output": "2\n2\n0\n0\n0\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 &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\t (reverse (cons str acc)))))\n\n(defparameter n (read))\n(defparameter a (mapcar #'parse-integer (split \" \" (read-line))))\n(defparameter members '())\n\n(dotimes (i n)\n\t(push '() members))\n\n(dolist (e a)\n\t(push e (nth (1- e) members)))\n\n(dolist (m members)\n\t(princ (length m))\n\t(terpri))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 912, "cpu_time_ms": 2206, "memory_kb": 123728}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s161961166", "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 (sort\n (loop for i in line\n for j from 0\n collect (cons i j))\n #'>\n :key #'car)))\n (dphash func (l r lst)\n (if lst\n (let ((point (caar lst))\n (pos (cdar lst)))\n (max (+ (* (abs (- l pos)) point)\n (func (1+ l) r (cdr lst)))\n (+ (* (abs (- r pos)) point)\n (func l (1- r) (cdr lst)))))\n 0))\n (func 0 (1- (length line)) points)))\n\n(princ (main (read-times (read))))\n\n", "language": "Lisp", "metadata": {"date": 1591189909, "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/s161961166.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s161961166", "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 (sort\n (loop for i in line\n for j from 0\n collect (cons i j))\n #'>\n :key #'car)))\n (dphash func (l r lst)\n (if lst\n (let ((point (caar lst))\n (pos (cdar lst)))\n (max (+ (* (abs (- l pos)) point)\n (func (1+ l) r (cdr lst)))\n (+ (* (abs (- r pos)) point)\n (func l (1- r) (cdr lst)))))\n 0))\n (func 0 (1- (length line)) points)))\n\n(princ (main (read-times (read))))\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6368, "cpu_time_ms": 1363, "memory_kb": 266156}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s321036922", "group_id": "codeNet:p02712", "input_text": "(let ((n (read))\n (ans 0))\n (loop :for i :from 1 :to n\n :if (< 0 (* (mod i 5) (mod i 3)))\n :do (incf ans i))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1593573447, "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/s321036922.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s321036922", "user_id": "u608227593"}, "prompt_components": {"gold_output": "60\n", "input_to_evaluate": "(let ((n (read))\n (ans 0))\n (loop :for i :from 1 :to n\n :if (< 0 (* (mod i 5) (mod i 3)))\n :do (incf ans i))\n (format t \"~A~%\" ans))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 55, "memory_kb": 24436}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s117707616", "group_id": "codeNet:p02712", "input_text": "(let ((n (read)))\n (princ (loop :as i\n :below (+ n 1)\n :when (not (or (zerop (mod i 3))\n (zerop (mod i 5))))\n :sum i)))", "language": "Lisp", "metadata": {"date": 1586904387, "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/s117707616.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s117707616", "user_id": "u606976120"}, "prompt_components": {"gold_output": "60\n", "input_to_evaluate": "(let ((n (read)))\n (princ (loop :as i\n :below (+ n 1)\n :when (not (or (zerop (mod i 3))\n (zerop (mod i 5))))\n :sum i)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 44, "memory_kb": 24356}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s954010706", "group_id": "codeNet:p02712", "input_text": "(defvar N (read))\n\n(princ\n (loop\n for x from 1 to N\n if (not (or (zerop (mod x 3))\n\t (zerop (mod x 5))))\n sum x))", "language": "Lisp", "metadata": {"date": 1586741166, "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/s954010706.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s954010706", "user_id": "u334552723"}, "prompt_components": {"gold_output": "60\n", "input_to_evaluate": "(defvar N (read))\n\n(princ\n (loop\n for x from 1 to N\n if (not (or (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 39, "memory_kb": 24432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s037458524", "group_id": "codeNet:p02719", "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 (k (read)))\n (println\n (min (mod n k)\n (- k (mod 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 \"7 4\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1000000000000000000 1\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1586065022, "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/s037458524.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s037458524", "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 ;; 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 (k (read)))\n (println\n (min (mod n k)\n (- k (mod 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 \"7 4\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1000000000000000000 1\n\"\n \"0\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3719, "cpu_time_ms": 34, "memory_kb": 7144}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s989642260", "group_id": "codeNet:p02719", "input_text": "(let ((n (read))\n (k (read)))\n (format t \"~A\"\n (min (mod n k)\n (abs (- (mod n k) k)))))", "language": "Lisp", "metadata": {"date": 1586049775, "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/s989642260.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s989642260", "user_id": "u425317134"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((n (read))\n (k (read)))\n (format t \"~A\"\n (min (mod n k)\n (abs (- (mod n k) k)))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 284, "memory_kb": 13028}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s102380100", "group_id": "codeNet:p02720", "input_text": "(defun q-emptyp (queue)\n (and (null (car queue))\n (null (cdr queue))))\n\n(defun q-singlep (queue)\n (and\n (not (q-emptyp queue))\n (eq (car queue) (cdr queue))))\n\n(defun enqueue (queue obj)\n (if (q-emptyp queue)\n (progn\n (setf (car queue) (list obj))\n (setf (cdr queue) (car queue)))\n (progn\n (setf (cddr queue) (cons obj nil))\n (setf (cdr queue) (cddr queue)))))\n\n(defun dequeue (queue)\n (let ((tmp nil))\n (cond \n ((q-emptyp queue) nil)\n ((q-singlep queue)\n (setf tmp (caar queue))\n (setf (car queue) nil)\n (setf (cdr queue) nil))\n (t\n (setf tmp (caar queue))\n (setf (car queue) (cdar queue))))\n tmp))\n\n(defun add-lunlun (queue n)\n (if (not (= (mod n 10) 0)) \n (enqueue queue (+ (* 10 n) (- (mod n 10) 1))))\n (enqueue queue (+ (* 10 n) (mod n 10)))\n (if (not (= (mod n 10) 9))\n (enqueue queue (+ (* 10 n) (mod n 10) 1))))\n \n(let ((n (read))\n (queue '(nil))\n (next 0))\n (loop :as i \n :below 9\n :do (enqueue queue (+ i 1)))\n (loop :repeat n\n :do (setf next (dequeue queue))\n (add-lunlun queue next))\n (princ next))", "language": "Lisp", "metadata": {"date": 1586121601, "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/s102380100.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s102380100", "user_id": "u606976120"}, "prompt_components": {"gold_output": "23\n", "input_to_evaluate": "(defun q-emptyp (queue)\n (and (null (car queue))\n (null (cdr queue))))\n\n(defun q-singlep (queue)\n (and\n (not (q-emptyp queue))\n (eq (car queue) (cdr queue))))\n\n(defun enqueue (queue obj)\n (if (q-emptyp queue)\n (progn\n (setf (car queue) (list obj))\n (setf (cdr queue) (car queue)))\n (progn\n (setf (cddr queue) (cons obj nil))\n (setf (cdr queue) (cddr queue)))))\n\n(defun dequeue (queue)\n (let ((tmp nil))\n (cond \n ((q-emptyp queue) nil)\n ((q-singlep queue)\n (setf tmp (caar queue))\n (setf (car queue) nil)\n (setf (cdr queue) nil))\n (t\n (setf tmp (caar queue))\n (setf (car queue) (cdar queue))))\n tmp))\n\n(defun add-lunlun (queue n)\n (if (not (= (mod n 10) 0)) \n (enqueue queue (+ (* 10 n) (- (mod n 10) 1))))\n (enqueue queue (+ (* 10 n) (mod n 10)))\n (if (not (= (mod n 10) 9))\n (enqueue queue (+ (* 10 n) (mod n 10) 1))))\n \n(let ((n (read))\n (queue '(nil))\n (next 0))\n (loop :as i \n :below 9\n :do (enqueue queue (+ i 1)))\n (loop :repeat n\n :do (setf next (dequeue queue))\n (add-lunlun queue next))\n (princ next))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1177, "cpu_time_ms": 235, "memory_kb": 17764}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s259240932", "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 (let* ((n (read))\n (k (read))\n (c (read))\n (s (read-line))\n (dp1 (make-array (+ n 1) :element-type 'uint32 :initial-element #xffffffff))\n (dp2 (make-array (+ n 1) :element-type 'uint32 :initial-element #xffffffff)))\n (let ((prev #x-80000000)\n (count 0))\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 (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 (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*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\"))\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": 1586075433, "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/s259240932.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s259240932", "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 (let* ((n (read))\n (k (read))\n (c (read))\n (s (read-line))\n (dp1 (make-array (+ n 1) :element-type 'uint32 :initial-element #xffffffff))\n (dp2 (make-array (+ n 1) :element-type 'uint32 :initial-element #xffffffff)))\n (let ((prev #x-80000000)\n (count 0))\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 (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 (eql (uiop:last-char s) #\\Linefeed)\n s\n (uiop:strcat s uiop:+lf+))))\n (funcall test\n (ensure-last-lf out-string)\n (with-output-to-string (out)\n (let ((*standard-output* out))\n (with-input-from-string (*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\"))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 190, "memory_kb": 30432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s670793349", "group_id": "codeNet:p02723", "input_text": "(let ((count 0)\n (pre nil)\n (result (cons nil nil)))\n (dolist (x (coerce (read-line) 'list))\n (incf count)\n (cond ((and (= count 4) (eql x pre))\n (setf (car result) t))\n ((and (= count 6) (eql x pre))\n (setf (cdr result) t)))\n (setq pre x))\n (princ (if (and (null (car result)) (null (cdr result))) \"No\" \"Yes\")))\n", "language": "Lisp", "metadata": {"date": 1585710333, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s670793349.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s670793349", "user_id": "u631655863"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((count 0)\n (pre nil)\n (result (cons nil nil)))\n (dolist (x (coerce (read-line) 'list))\n (incf count)\n (cond ((and (= count 4) (eql x pre))\n (setf (car result) t))\n ((and (= count 6) (eql x pre))\n (setf (cdr result) t)))\n (setq pre x))\n (princ (if (and (null (car result)) (null (cdr result))) \"No\" \"Yes\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 363, "cpu_time_ms": 121, "memory_kb": 11108}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s633266964", "group_id": "codeNet:p02724", "input_text": "(defun solve (n)\n (if (= n 0)\n 0\n (multiple-value-bind (quotient remainder)\n (floor n 500)\n (if (> remainder 5)\n (+ (* quotient 1000) (* 5 (floor remainder 5)))\n (* quotient 1000)))))\n\n(princ (solve (read)))\n", "language": "Lisp", "metadata": {"date": 1585711998, "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/s633266964.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s633266964", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2020\n", "input_to_evaluate": "(defun solve (n)\n (if (= n 0)\n 0\n (multiple-value-bind (quotient remainder)\n (floor n 500)\n (if (> remainder 5)\n (+ (* quotient 1000) (* 5 (floor remainder 5)))\n (* quotient 1000)))))\n\n(princ (solve (read)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 257, "cpu_time_ms": 119, "memory_kb": 13412}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s860632425", "group_id": "codeNet:p02725", "input_text": "import java.util.Arrays;\nimport java.util.Scanner;\npublic class Main {\npublic static void main(String[] args){\n  int count=1,k=0,max=0,i=0;\n  int[] sum=new int[100];\n  Scanner scan=new Scanner(System.in);\n  char[] s=scan.next().toCharArray();\n  for(i=0;ii;j--){\n      if(s[i]==s[j]){\n      count++;\n      }\n   }\n     for(i=0;i2){\n     System.out.print(s.length-1+\"\");\n    }\n    else if(sum[s.length-1]!=s.length&&sum[s.length-1]>=2){\n    System.out.print(sum[s.length-1]+\"\");\n    }\n    else{\n     System.out.print(\"0\");\n    }\n } \n}", "language": "Lisp", "metadata": {"date": 1585448303, "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/s860632425.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s860632425", "user_id": "u979473360"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "import java.util.Arrays;\nimport java.util.Scanner;\npublic class Main {\npublic static void main(String[] args){\n  int count=1,k=0,max=0,i=0;\n  int[] sum=new int[100];\n  Scanner scan=new Scanner(System.in);\n  char[] s=scan.next().toCharArray();\n  for(i=0;ii;j--){\n      if(s[i]==s[j]){\n      count++;\n      }\n   }\n     for(i=0;i2){\n     System.out.print(s.length-1+\"\");\n    }\n    else if(sum[s.length-1]!=s.length&&sum[s.length-1]>=2){\n    System.out.print(sum[s.length-1]+\"\");\n    }\n    else{\n     System.out.print(\"0\");\n    }\n } \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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 788, "cpu_time_ms": 9, "memory_kb": 3176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s583644528", "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 sublst (lst)\n (labels ((inner (lst reslst)\n (if (cdr lst)\n (inner (cdr lst) (cons (- (car lst) (cadr lst)) reslst))\n reslst)))\n (inner lst '())))\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 (submax a))\n", "language": "Lisp", "metadata": {"date": 1585447900, "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/s583644528.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s583644528", "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 sublst (lst)\n (labels ((inner (lst reslst)\n (if (cdr lst)\n (inner (cdr lst) (cons (- (car lst) (cadr lst)) reslst))\n reslst)))\n (inner lst '())))\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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1439, "cpu_time_ms": 2106, "memory_kb": 98628}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s586167165", "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\" \"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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 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 (declare (uint31 n))\n (with-caches ((:hash-table :size (* 3 n)\n :test #'eq\n :key (lambda (x y) (declare (uint31 x y)) (dpb x (byte 31 31) y)))\n (:hash-table :size (* 3 n)\n :test #'eq\n :key (lambda (x y) (declare (uint31 x y)) (dpb x (byte 31 31) y))))\n (labels ((subtree-size (parent top)\n (declare (uint32 parent top)\n (values uint31 &optional))\n (+ 1\n (loop for child of-type uint32 in (aref graph top)\n unless (= child parent)\n sum (subtree-size top child) of-type uint32)))\n (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 (subtree-size top neighbor)))\n (setq res (mod* res (aref *fact-inv* size)))\n (incf sum size))))\n (mod* res (aref *fact* sum)))))\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 (with-buffered-stdout\n (loop for top from 0 below n\n do (println (subtree-number n top))))))))\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": 1585448163, "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/s586167165.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s586167165", "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\" \"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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-int:defconstant-eqx OPT\n #+swank '(optimize (speed 3) (safety 2))\n #-swank '(optimize (speed 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 (declare (uint31 n))\n (with-caches ((:hash-table :size (* 3 n)\n :test #'eq\n :key (lambda (x y) (declare (uint31 x y)) (dpb x (byte 31 31) y)))\n (:hash-table :size (* 3 n)\n :test #'eq\n :key (lambda (x y) (declare (uint31 x y)) (dpb x (byte 31 31) y))))\n (labels ((subtree-size (parent top)\n (declare (uint32 parent top)\n (values uint31 &optional))\n (+ 1\n (loop for child of-type uint32 in (aref graph top)\n unless (= child parent)\n sum (subtree-size top child) of-type uint32)))\n (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 (subtree-size top neighbor)))\n (setq res (mod* res (aref *fact-inv* size)))\n (incf sum size))))\n (mod* res (aref *fact* sum)))))\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 (with-buffered-stdout\n (loop for top from 0 below n\n do (println (subtree-number n top))))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 23314, "cpu_time_ms": 3164, "memory_kb": 87224}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s274355027", "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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\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 (as (make-array (- n 1) :element-type 'uint32))\n (bs (make-array (- n 1) :element-type 'uint32)))\n (declare (uint31 n))\n (with-caches ((:hash-table :size (* 3 n)\n :test #'eq\n :key (lambda (x y) (declare (uint31 x y)) (dpb x (byte 31 31) y)))\n (:hash-table :size (* 3 n)\n :test #'eq\n :key (lambda (x y) (declare (uint31 x y)) (dpb x (byte 31 31) y))))\n (labels ((subtree-size (parent top)\n (declare (uint32 parent top)\n (values uint32))\n (+ 1\n (loop for child of-type uint32 in (aref graph top)\n unless (= child parent)\n sum (subtree-size top child) of-type uint32)))\n (subtree-number (parent top)\n (declare (int32 parent top)\n (values uint32))\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 (subtree-size top neighbor)))\n (setq res (mod* res (aref *fact-inv* size)))\n (incf sum size))))\n (mod* res (aref *fact* sum)))))\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 (setf (aref as i) a)\n (setf (aref bs i) b)))\n (with-buffered-stdout\n (loop for top from 0 below n\n do (println (subtree-number -1 top))))))))\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": 1585447703, "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/s274355027.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s274355027", "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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\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 (as (make-array (- n 1) :element-type 'uint32))\n (bs (make-array (- n 1) :element-type 'uint32)))\n (declare (uint31 n))\n (with-caches ((:hash-table :size (* 3 n)\n :test #'eq\n :key (lambda (x y) (declare (uint31 x y)) (dpb x (byte 31 31) y)))\n (:hash-table :size (* 3 n)\n :test #'eq\n :key (lambda (x y) (declare (uint31 x y)) (dpb x (byte 31 31) y))))\n (labels ((subtree-size (parent top)\n (declare (uint32 parent top)\n (values uint32))\n (+ 1\n (loop for child of-type uint32 in (aref graph top)\n unless (= child parent)\n sum (subtree-size top child) of-type uint32)))\n (subtree-number (parent top)\n (declare (int32 parent top)\n (values uint32))\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 (subtree-size top neighbor)))\n (setq res (mod* res (aref *fact-inv* size)))\n (incf sum size))))\n (mod* res (aref *fact* sum)))))\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 (setf (aref as i) a)\n (setf (aref bs i) b)))\n (with-buffered-stdout\n (loop for top from 0 below n\n do (println (subtree-number -1 top))))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 23422, "cpu_time_ms": 3168, "memory_kb": 95292}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s635792616", "group_id": "codeNet:p02729", "input_text": "(defun count-pattern (n)\n (/ (* n (- n 1)) 2))\n\n(let ((even-count (read))\n (odd-count (read)))\n (princ (+ (count-pattern even-count) (count-pattern odd-count))))", "language": "Lisp", "metadata": {"date": 1584925584, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02729.html", "problem_id": "p02729", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02729/input.txt", "sample_output_relpath": "derived/input_output/data/p02729/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02729/Lisp/s635792616.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s635792616", "user_id": "u606976120"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun count-pattern (n)\n (/ (* n (- n 1)) 2))\n\n(let ((even-count (read))\n (odd-count (read)))\n (princ (+ (count-pattern even-count) (count-pattern odd-count))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe have N+M balls, each of which has an integer written on it.\n\nIt is known that:\n\nThe numbers written on N of the balls are even.\n\nThe numbers written on M of the balls are odd.\n\nFind the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.\n\nIt can be shown that this count does not depend on the actual values written on the balls.\n\nConstraints\n\n0 \\leq N,M \\leq 100\n\n2 \\leq N+M\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2 1\n\nSample Output 1\n\n1\n\nFor example, let us assume that the numbers written on the three balls are 1,2,4.\n\nIf we choose the two balls with 1 and 2, the sum is odd;\n\nIf we choose the two balls with 1 and 4, the sum is odd;\n\nIf we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\nSample Input 2\n\n4 3\n\nSample Output 2\n\n9\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\n0\n\nSample Input 4\n\n13 3\n\nSample Output 4\n\n81\n\nSample Input 5\n\n0 3\n\nSample Output 5\n\n3", "sample_input": "2 1\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02729", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe have N+M balls, each of which has an integer written on it.\n\nIt is known that:\n\nThe numbers written on N of the balls are even.\n\nThe numbers written on M of the balls are odd.\n\nFind the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.\n\nIt can be shown that this count does not depend on the actual values written on the balls.\n\nConstraints\n\n0 \\leq N,M \\leq 100\n\n2 \\leq N+M\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2 1\n\nSample Output 1\n\n1\n\nFor example, let us assume that the numbers written on the three balls are 1,2,4.\n\nIf we choose the two balls with 1 and 2, the sum is odd;\n\nIf we choose the two balls with 1 and 4, the sum is odd;\n\nIf we choose the two balls with 2 and 4, the sum is even.\n\nThus, the answer is 1.\n\nSample Input 2\n\n4 3\n\nSample Output 2\n\n9\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\n0\n\nSample Input 4\n\n13 3\n\nSample Output 4\n\n81\n\nSample Input 5\n\n0 3\n\nSample Output 5\n\n3", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 83, "memory_kb": 9568}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s073532393", "group_id": "codeNet:p02730", "input_text": "(let* ((s (read-line))\n (n (length s))\n (x (subseq s 0 (/ (1- n) 2)))\n (y (subseq s (/ (+ n 1) 2))))\n (if (and (string= s (reverse s))\n (string= x (reverse x))\n (string= y (reverse y)))\n (format t \"Yes~%\")\n (format t \"No~%\")))\n", "language": "Lisp", "metadata": {"date": 1593570080, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02730.html", "problem_id": "p02730", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02730/input.txt", "sample_output_relpath": "derived/input_output/data/p02730/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02730/Lisp/s073532393.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s073532393", "user_id": "u608227593"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((s (read-line))\n (n (length s))\n (x (subseq s 0 (/ (1- n) 2)))\n (y (subseq s (/ (+ n 1) 2))))\n (if (and (string= s (reverse s))\n (string= x (reverse x))\n (string= y (reverse y)))\n (format t \"Yes~%\")\n (format t \"No~%\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nA string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:\n\nS is a palindrome.\n\nLet N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.\n\nThe string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.\n\nDetermine whether S is a strong palindrome.\n\nConstraints\n\nS consists of lowercase English letters.\n\nThe length of S is an odd number between 3 and 99 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is a strong palindrome, print Yes;\notherwise, print No.\n\nSample Input 1\n\nakasaka\n\nSample Output 1\n\nYes\n\nS is akasaka.\n\nThe string formed by the 1-st through the 3-rd characters is aka.\n\nThe string formed by the 5-th through the 7-th characters is aka.\nAll of these are palindromes, so S is a strong palindrome.\n\nSample Input 2\n\nlevel\n\nSample Output 2\n\nNo\n\nSample Input 3\n\natcoder\n\nSample Output 3\n\nNo", "sample_input": "akasaka\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02730", "source_text": "Score : 200 points\n\nProblem Statement\n\nA string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:\n\nS is a palindrome.\n\nLet N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.\n\nThe string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.\n\nDetermine whether S is a strong palindrome.\n\nConstraints\n\nS consists of lowercase English letters.\n\nThe length of S is an odd number between 3 and 99 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is a strong palindrome, print Yes;\notherwise, print No.\n\nSample Input 1\n\nakasaka\n\nSample Output 1\n\nYes\n\nS is akasaka.\n\nThe string formed by the 1-st through the 3-rd characters is aka.\n\nThe string formed by the 5-th through the 7-th characters is aka.\nAll of these are palindromes, so S is a strong palindrome.\n\nSample Input 2\n\nlevel\n\nSample Output 2\n\nNo\n\nSample Input 3\n\natcoder\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 20, "memory_kb": 23240}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s738864959", "group_id": "codeNet:p02730", "input_text": "(defun app ()\n (let* ((s (read-line))\n (n (length s))\n (ans \"Yes\"))\n (dotimes (i (floor (/ n 2)))\n (if (not (equal (subseq s i (+ i 1)) (subseq s (- n i 1) (- n i))))\n (setq ans \"No\")\n )\n )\n (if (equal ans \"Yes\")\n (dotimes (i (floor (/ (- n 1) 2)))\n (if (not (equal (subseq s i (+ i 1)) (subseq s (- (floor (/ (- n 1) 2)) i 1) (- (floor (/ (- n 1) 2)) i))))\n (setq ans \"No\")\n )\n )\n )\n (if (equal ans \"Yes\")\n (let ((num (floor (/ (+ n 3) 2))))\n (loop for i from 0 to (floor (/ (- n num) 2)) do\n (if (not (equal (subseq s (- (+ num i) 1) (+ num i)) (subseq s (- n i 1) (- n i))))\n (setq ans \"No\")\n )\n )\n )\n )\n\n (format t \"~A~%\" ans)\n )\n)\n(app)", "language": "Lisp", "metadata": {"date": 1592600683, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02730.html", "problem_id": "p02730", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02730/input.txt", "sample_output_relpath": "derived/input_output/data/p02730/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02730/Lisp/s738864959.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s738864959", "user_id": "u136500538"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun app ()\n (let* ((s (read-line))\n (n (length s))\n (ans \"Yes\"))\n (dotimes (i (floor (/ n 2)))\n (if (not (equal (subseq s i (+ i 1)) (subseq s (- n i 1) (- n i))))\n (setq ans \"No\")\n )\n )\n (if (equal ans \"Yes\")\n (dotimes (i (floor (/ (- n 1) 2)))\n (if (not (equal (subseq s i (+ i 1)) (subseq s (- (floor (/ (- n 1) 2)) i 1) (- (floor (/ (- n 1) 2)) i))))\n (setq ans \"No\")\n )\n )\n )\n (if (equal ans \"Yes\")\n (let ((num (floor (/ (+ n 3) 2))))\n (loop for i from 0 to (floor (/ (- n num) 2)) do\n (if (not (equal (subseq s (- (+ num i) 1) (+ num i)) (subseq s (- n i 1) (- n i))))\n (setq ans \"No\")\n )\n )\n )\n )\n\n (format t \"~A~%\" ans)\n )\n)\n(app)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nA string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:\n\nS is a palindrome.\n\nLet N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.\n\nThe string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.\n\nDetermine whether S is a strong palindrome.\n\nConstraints\n\nS consists of lowercase English letters.\n\nThe length of S is an odd number between 3 and 99 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is a strong palindrome, print Yes;\notherwise, print No.\n\nSample Input 1\n\nakasaka\n\nSample Output 1\n\nYes\n\nS is akasaka.\n\nThe string formed by the 1-st through the 3-rd characters is aka.\n\nThe string formed by the 5-th through the 7-th characters is aka.\nAll of these are palindromes, so S is a strong palindrome.\n\nSample Input 2\n\nlevel\n\nSample Output 2\n\nNo\n\nSample Input 3\n\natcoder\n\nSample Output 3\n\nNo", "sample_input": "akasaka\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02730", "source_text": "Score : 200 points\n\nProblem Statement\n\nA string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:\n\nS is a palindrome.\n\nLet N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.\n\nThe string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.\n\nDetermine whether S is a strong palindrome.\n\nConstraints\n\nS consists of lowercase English letters.\n\nThe length of S is an odd number between 3 and 99 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is a strong palindrome, print Yes;\notherwise, print No.\n\nSample Input 1\n\nakasaka\n\nSample Output 1\n\nYes\n\nS is akasaka.\n\nThe string formed by the 1-st through the 3-rd characters is aka.\n\nThe string formed by the 5-th through the 7-th characters is aka.\nAll of these are palindromes, so S is a strong palindrome.\n\nSample Input 2\n\nlevel\n\nSample Output 2\n\nNo\n\nSample Input 3\n\natcoder\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 903, "cpu_time_ms": 19, "memory_kb": 23696}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s159580794", "group_id": "codeNet:p02730", "input_text": "(defun string-palindrome ()\n (let* ((s (read-line))\n (n (length s))\n (sr (reverse s))\n (ans \"No\"))\n (if (and (<= 7 n) (string= s sr))\n (if (and (oddp (/ (1- n) 2)) (string= (subseq s 0 (/ (1- n) 2)) (subseq sr 0 (/ (1- n) 2))))\n (if (and (oddp (/ (+ n 3) 2)) (string= (subseq s (/ (+ n 3) 2) n) (subseq sr (/ (+ n 3) 2) n)))\n (setf ans \"Yes\"))))\n ans))\n\n(format t \"~A~%\" (string-palindrome))\n", "language": "Lisp", "metadata": {"date": 1584928731, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02730.html", "problem_id": "p02730", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02730/input.txt", "sample_output_relpath": "derived/input_output/data/p02730/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02730/Lisp/s159580794.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s159580794", "user_id": "u091381267"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun string-palindrome ()\n (let* ((s (read-line))\n (n (length s))\n (sr (reverse s))\n (ans \"No\"))\n (if (and (<= 7 n) (string= s sr))\n (if (and (oddp (/ (1- n) 2)) (string= (subseq s 0 (/ (1- n) 2)) (subseq sr 0 (/ (1- n) 2))))\n (if (and (oddp (/ (+ n 3) 2)) (string= (subseq s (/ (+ n 3) 2) n) (subseq sr (/ (+ n 3) 2) n)))\n (setf ans \"Yes\"))))\n ans))\n\n(format t \"~A~%\" (string-palindrome))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nA string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:\n\nS is a palindrome.\n\nLet N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.\n\nThe string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.\n\nDetermine whether S is a strong palindrome.\n\nConstraints\n\nS consists of lowercase English letters.\n\nThe length of S is an odd number between 3 and 99 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is a strong palindrome, print Yes;\notherwise, print No.\n\nSample Input 1\n\nakasaka\n\nSample Output 1\n\nYes\n\nS is akasaka.\n\nThe string formed by the 1-st through the 3-rd characters is aka.\n\nThe string formed by the 5-th through the 7-th characters is aka.\nAll of these are palindromes, so S is a strong palindrome.\n\nSample Input 2\n\nlevel\n\nSample Output 2\n\nNo\n\nSample Input 3\n\natcoder\n\nSample Output 3\n\nNo", "sample_input": "akasaka\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02730", "source_text": "Score : 200 points\n\nProblem Statement\n\nA string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:\n\nS is a palindrome.\n\nLet N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.\n\nThe string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.\n\nDetermine whether S is a strong palindrome.\n\nConstraints\n\nS consists of lowercase English letters.\n\nThe length of S is an odd number between 3 and 99 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is a strong palindrome, print Yes;\notherwise, print No.\n\nSample Input 1\n\nakasaka\n\nSample Output 1\n\nYes\n\nS is akasaka.\n\nThe string formed by the 1-st through the 3-rd characters is aka.\n\nThe string formed by the 5-th through the 7-th characters is aka.\nAll of these are palindromes, so S is a strong palindrome.\n\nSample Input 2\n\nlevel\n\nSample Output 2\n\nNo\n\nSample Input 3\n\natcoder\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 170, "memory_kb": 15204}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s158157735", "group_id": "codeNet:p02730", "input_text": "(defun string-palindrome ()\n (let* ((s (read-line))\n (n (length s))\n (sr (reverse s))\n (ans \"No\"))\n (if (string= s sr)\n (if (and (oddp (/ (1- n) 2)) (string= (subseq s 0 (/ (1- n) 2)) (subseq sr 0 (/ (1- n) 2))))\n (if (and (oddp (/ (+ n 3) 2)) (string= (subseq s (/ (+ n 3) 2) n) (subseq sr (/ (+ n 3) 2) n)))\n (setf ans \"Yes\"))))\n ans))\n\n(format t \"~A~%\" (string-palindrome))\n", "language": "Lisp", "metadata": {"date": 1584928546, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02730.html", "problem_id": "p02730", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02730/input.txt", "sample_output_relpath": "derived/input_output/data/p02730/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02730/Lisp/s158157735.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s158157735", "user_id": "u091381267"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun string-palindrome ()\n (let* ((s (read-line))\n (n (length s))\n (sr (reverse s))\n (ans \"No\"))\n (if (string= s sr)\n (if (and (oddp (/ (1- n) 2)) (string= (subseq s 0 (/ (1- n) 2)) (subseq sr 0 (/ (1- n) 2))))\n (if (and (oddp (/ (+ n 3) 2)) (string= (subseq s (/ (+ n 3) 2) n) (subseq sr (/ (+ n 3) 2) n)))\n (setf ans \"Yes\"))))\n ans))\n\n(format t \"~A~%\" (string-palindrome))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nA string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:\n\nS is a palindrome.\n\nLet N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.\n\nThe string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.\n\nDetermine whether S is a strong palindrome.\n\nConstraints\n\nS consists of lowercase English letters.\n\nThe length of S is an odd number between 3 and 99 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is a strong palindrome, print Yes;\notherwise, print No.\n\nSample Input 1\n\nakasaka\n\nSample Output 1\n\nYes\n\nS is akasaka.\n\nThe string formed by the 1-st through the 3-rd characters is aka.\n\nThe string formed by the 5-th through the 7-th characters is aka.\nAll of these are palindromes, so S is a strong palindrome.\n\nSample Input 2\n\nlevel\n\nSample Output 2\n\nNo\n\nSample Input 3\n\natcoder\n\nSample Output 3\n\nNo", "sample_input": "akasaka\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02730", "source_text": "Score : 200 points\n\nProblem Statement\n\nA string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:\n\nS is a palindrome.\n\nLet N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.\n\nThe string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.\n\nDetermine whether S is a strong palindrome.\n\nConstraints\n\nS consists of lowercase English letters.\n\nThe length of S is an odd number between 3 and 99 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S is a strong palindrome, print Yes;\notherwise, print No.\n\nSample Input 1\n\nakasaka\n\nSample Output 1\n\nYes\n\nS is akasaka.\n\nThe string formed by the 1-st through the 3-rd characters is aka.\n\nThe string formed by the 5-th through the 7-th characters is aka.\nAll of these are palindromes, so S is a strong palindrome.\n\nSample Input 2\n\nlevel\n\nSample Output 2\n\nNo\n\nSample Input 3\n\natcoder\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 23, "memory_kb": 4836}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s096959319", "group_id": "codeNet:p02731", "input_text": "(let* ((l (read)))\n (format t \"~A~%\" (expt (/ l 3) 3)))\n", "language": "Lisp", "metadata": {"date": 1593571687, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s096959319.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s096959319", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1.000000000000\n", "input_to_evaluate": "(let* ((l (read)))\n (format t \"~A~%\" (expt (/ l 3) 3)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 23964}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s249443995", "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(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 (dp (make-array (+ n 1) :element-type 'uint32 :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 (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": 1584925838, "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/s249443995.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s249443995", "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(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 (dp (make-array (+ n 1) :element-type 'uint32 :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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5478, "cpu_time_ms": 1250, "memory_kb": 29536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s058962923", "group_id": "codeNet:p02736", "input_text": "(declaim (inline diff))\n\n(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 (declare (optimize (speed 3))\n (type fixnum n)\n (type simple-vector vec))\n (if (<= n -1)\n (progn\n (dotimes (i n)\n (setf (svref vec i) (diff (svref vec i) (svref vec (1+ i)))))\n (f (1- n) vec))\n (svref vec 0)))\n\n(defun diff (m n)\n (abs (- m n)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1584847798, "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/s058962923.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s058962923", "user_id": "u956039157"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(declaim (inline diff))\n\n(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 (declare (optimize (speed 3))\n (type fixnum n)\n (type simple-vector vec))\n (if (<= n -1)\n (progn\n (dotimes (i n)\n (setf (svref vec i) (diff (svref vec i) (svref vec (1+ i)))))\n (f (1- n) vec))\n (svref vec 0)))\n\n(defun diff (m n)\n (abs (- m n)))\n\n(main)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 474, "memory_kb": 15968}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s056157929", "group_id": "codeNet:p02736", "input_text": "(declaim (inline diff))\n\n(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 (declare (optimize (speed 3))\n (type fixnum n)\n (type simple-vector vec))\n (if (<= n 0)\n (progn\n (dotimes (i n)\n (setf (svref vec i) (diff (svref vec i) (svref vec (1+ i)))))\n (f (1- n) vec))\n (svref vec 0)))\n\n(defun diff (m n)\n (abs (- m n)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1584847733, "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/s056157929.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s056157929", "user_id": "u956039157"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(declaim (inline diff))\n\n(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 (declare (optimize (speed 3))\n (type fixnum n)\n (type simple-vector vec))\n (if (<= n 0)\n (progn\n (dotimes (i n)\n (setf (svref vec i) (diff (svref vec i) (svref vec (1+ i)))))\n (f (1- n) vec))\n (svref vec 0)))\n\n(defun diff (m n)\n (abs (- m n)))\n\n(main)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 551, "cpu_time_ms": 136, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s625882895", "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-array (list n n) :initial-element nil)))\n (labels ((x (i j)\n (declare (optimize (speed 3))\n (type fixnum i j))\n (or (aref cache i j)\n (setf (aref cache i j)\n (if (<= i 0)\n (svref vec j)\n (abs (- (x (1- i) j) (x (1- i) (1+ j)))))))))\n (x (1- n) 0))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1584845129, "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/s625882895.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s625882895", "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-array (list n n) :initial-element nil)))\n (labels ((x (i j)\n (declare (optimize (speed 3))\n (type fixnum i j))\n (or (aref cache i j)\n (setf (aref cache i j)\n (if (<= i 0)\n (svref vec j)\n (abs (- (x (1- i) j) (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 1195, "memory_kb": 17120}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s303309611", "group_id": "codeNet:p02741", "input_text": "(princ (nth (read) `(0 1 1 1 2 1 2 1 5 2 2 1 5 1 2 1 14 1 5 1 5 2 2 1 15 2 2 5 4 1 4 1 51)) )\n", "language": "Lisp", "metadata": {"date": 1593387599, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02741.html", "problem_id": "p02741", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02741/input.txt", "sample_output_relpath": "derived/input_output/data/p02741/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02741/Lisp/s303309611.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s303309611", "user_id": "u526532903"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ (nth (read) `(0 1 1 1 2 1 2 1 5 2 2 1 5 1 2 1 14 1 5 1 5 2 2 1 15 2 2 5 4 1 4 1 51)) )\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nPrint the K-th element of the following sequence of length 32:\n\n1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51\n\nConstraints\n\n1 \\leq K \\leq 32\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 K-th element.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n2\n\nThe 6-th element is 2.\n\nSample Input 2\n\n27\n\nSample Output 2\n\n5\n\nThe 27-th element is 5.", "sample_input": "6\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02741", "source_text": "Score : 100 points\n\nProblem Statement\n\nPrint the K-th element of the following sequence of length 32:\n\n1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51\n\nConstraints\n\n1 \\leq K \\leq 32\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 K-th element.\n\nSample Input 1\n\n6\n\nSample Output 1\n\n2\n\nThe 6-th element is 2.\n\nSample Input 2\n\n27\n\nSample Output 2\n\n5\n\nThe 27-th element is 5.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 15, "memory_kb": 24012}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s708212703", "group_id": "codeNet:p02742", "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(h w)\n (let ((wodd (if (oddp w) (ceiling w 2) (ceiling w 2)))\n (weven (if (oddp w) (ceiling (1- w) 2) (ceiling w 2)))\n (hodd (if (oddp h) (ceiling h 2) (ceiling h 2)))\n (heven (if (oddp h) (ceiling (1- h) 2) (ceiling h 2))))\n (+ (* wodd hodd) (* weven heven))))\n(let ((line (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (f (car line) (cadr line))))\n", "language": "Lisp", "metadata": {"date": 1584235187, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02742.html", "problem_id": "p02742", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02742/input.txt", "sample_output_relpath": "derived/input_output/data/p02742/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02742/Lisp/s708212703.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s708212703", "user_id": "u254205055"}, "prompt_components": {"gold_output": "10\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(h w)\n (let ((wodd (if (oddp w) (ceiling w 2) (ceiling w 2)))\n (weven (if (oddp w) (ceiling (1- w) 2) (ceiling w 2)))\n (hodd (if (oddp h) (ceiling h 2) (ceiling h 2)))\n (heven (if (oddp h) (ceiling (1- h) 2) (ceiling h 2))))\n (+ (* wodd hodd) (* weven heven))))\n(let ((line (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (f (car line) (cadr line))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a board with H horizontal rows and W vertical columns of squares.\nThere is a bishop at the top-left square on this board.\nHow many squares can this bishop reach by zero or more movements?\n\nHere the bishop can only move diagonally.\nMore formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds:\n\nr_1 + c_1 = r_2 + c_2\n\nr_1 - c_1 = r_2 - c_2\n\nFor example, in the following figure, the bishop can move to any of the red squares in one move:\n\nConstraints\n\n1 \\leq H, W \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH \\ W\n\nOutput\n\nPrint the number of squares the bishop can reach.\n\nSample Input 1\n\n4 5\n\nSample Output 1\n\n10\n\nThe bishop can reach the cyan squares in the following figure:\n\nSample Input 2\n\n7 3\n\nSample Output 2\n\n11\n\nThe bishop can reach the cyan squares in the following figure:\n\nSample Input 3\n\n1000000000 1000000000\n\nSample Output 3\n\n500000000000000000", "sample_input": "4 5\n"}, "reference_outputs": ["10\n"], "source_document_id": "p02742", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a board with H horizontal rows and W vertical columns of squares.\nThere is a bishop at the top-left square on this board.\nHow many squares can this bishop reach by zero or more movements?\n\nHere the bishop can only move diagonally.\nMore formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds:\n\nr_1 + c_1 = r_2 + c_2\n\nr_1 - c_1 = r_2 - c_2\n\nFor example, in the following figure, the bishop can move to any of the red squares in one move:\n\nConstraints\n\n1 \\leq H, W \\leq 10^9\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH \\ W\n\nOutput\n\nPrint the number of squares the bishop can reach.\n\nSample Input 1\n\n4 5\n\nSample Output 1\n\n10\n\nThe bishop can reach the cyan squares in the following figure:\n\nSample Input 2\n\n7 3\n\nSample Output 2\n\n11\n\nThe bishop can reach the cyan squares in the following figure:\n\nSample Input 3\n\n1000000000 1000000000\n\nSample Output 3\n\n500000000000000000", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 666, "cpu_time_ms": 379, "memory_kb": 21344}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s163618257", "group_id": "codeNet:p02744", "input_text": "(defun tr-s (n)\n (let ((tr-str \"abcdefghij\"))\n (subseq tr-str n (+ n 1))))\n\n\n(defun print-word (str n str_len c)\n (if (= n str_len)\n (format t \"~A~%\" str)\n (loop as i\n below (+ c 1)\n do (print-word (concatenate 'string str (tr-s i)) n (+ str_len 1) (if (= c i) (+ i 1) c)))))\n\n(print-word \"a\" (read) 1 1)", "language": "Lisp", "metadata": {"date": 1584254573, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02744.html", "problem_id": "p02744", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02744/input.txt", "sample_output_relpath": "derived/input_output/data/p02744/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02744/Lisp/s163618257.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s163618257", "user_id": "u606976120"}, "prompt_components": {"gold_output": "a\n", "input_to_evaluate": "(defun tr-s (n)\n (let ((tr-str \"abcdefghij\"))\n (subseq tr-str n (+ n 1))))\n\n\n(defun print-word (str n str_len c)\n (if (= n str_len)\n (format t \"~A~%\" str)\n (loop as i\n below (+ c 1)\n do (print-word (concatenate 'string str (tr-s i)) n (+ str_len 1) (if (= c i) (+ i 1) c)))))\n\n(print-word \"a\" (read) 1 1)", "problem_context": "Score : 400 points\n\nProblem Statement\n\nIn this problem, we only consider strings consisting of lowercase English letters.\n\nStrings s and t are said to be isomorphic when the following conditions are satisfied:\n\n|s| = |t| holds.\n\nFor every pair i, j, one of the following holds:\n\ns_i = s_j and t_i = t_j.\n\ns_i \\neq s_j and t_i \\neq t_j.\n\nFor example, abcac and zyxzx are isomorphic, while abcac and ppppp are not.\n\nA string s is said to be in normal form when the following condition is satisfied:\n\nFor every string t that is isomorphic to s, s \\leq t holds. Here \\leq denotes lexicographic comparison.\n\nFor example, abcac is in normal form, but zyxzx is not since it is isomorphic to abcac, which is lexicographically smaller than zyxzx.\n\nYou are given an integer N.\nPrint all strings of length N that are in normal form, in lexicographically ascending order.\n\nConstraints\n\n1 \\leq N \\leq 10\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\nAssume that there are K strings of length N that are in normal form: w_1, \\ldots, w_K in lexicographical order.\nOutput should be in the following format:\n\nw_1\n:\nw_K\n\nSample Input 1\n\n1\n\nSample Output 1\n\na\n\nSample Input 2\n\n2\n\nSample Output 2\n\naa\nab", "sample_input": "1\n"}, "reference_outputs": ["a\n"], "source_document_id": "p02744", "source_text": "Score : 400 points\n\nProblem Statement\n\nIn this problem, we only consider strings consisting of lowercase English letters.\n\nStrings s and t are said to be isomorphic when the following conditions are satisfied:\n\n|s| = |t| holds.\n\nFor every pair i, j, one of the following holds:\n\ns_i = s_j and t_i = t_j.\n\ns_i \\neq s_j and t_i \\neq t_j.\n\nFor example, abcac and zyxzx are isomorphic, while abcac and ppppp are not.\n\nA string s is said to be in normal form when the following condition is satisfied:\n\nFor every string t that is isomorphic to s, s \\leq t holds. Here \\leq denotes lexicographic comparison.\n\nFor example, abcac is in normal form, but zyxzx is not since it is isomorphic to abcac, which is lexicographically smaller than zyxzx.\n\nYou are given an integer N.\nPrint all strings of length N that are in normal form, in lexicographically ascending order.\n\nConstraints\n\n1 \\leq N \\leq 10\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\nAssume that there are K strings of length N that are in normal form: w_1, \\ldots, w_K in lexicographical order.\nOutput should be in the following format:\n\nw_1\n:\nw_K\n\nSample Input 1\n\n1\n\nSample Output 1\n\na\n\nSample Input 2\n\n2\n\nSample Output 2\n\naa\nab", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 341, "cpu_time_ms": 360, "memory_kb": 26212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s954883518", "group_id": "codeNet:p02744", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (with-buffered-stdout\n (labels ((dfs (pos high res)\n (if (= pos n)\n (dolist (c (reverse res) (terpri))\n (write-char c))\n (dotimes (delta (+ high 1))\n (let ((c (code-char (+ 97 delta))))\n (dfs (+ pos 1)\n (if (= high delta) (+ high 1) high)\n (cons c res)))))))\n (dfs 0 0 nil)))))\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\n\"\n \"a\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n\"\n \"aa\nab\n\")))\n", "language": "Lisp", "metadata": {"date": 1584234945, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02744.html", "problem_id": "p02744", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02744/input.txt", "sample_output_relpath": "derived/input_output/data/p02744/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02744/Lisp/s954883518.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s954883518", "user_id": "u352600849"}, "prompt_components": {"gold_output": "a\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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (with-buffered-stdout\n (labels ((dfs (pos high res)\n (if (= pos n)\n (dolist (c (reverse res) (terpri))\n (write-char c))\n (dotimes (delta (+ high 1))\n (let ((c (code-char (+ 97 delta))))\n (dfs (+ pos 1)\n (if (= high delta) (+ high 1) high)\n (cons c res)))))))\n (dfs 0 0 nil)))))\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\n\"\n \"a\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n\"\n \"aa\nab\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nIn this problem, we only consider strings consisting of lowercase English letters.\n\nStrings s and t are said to be isomorphic when the following conditions are satisfied:\n\n|s| = |t| holds.\n\nFor every pair i, j, one of the following holds:\n\ns_i = s_j and t_i = t_j.\n\ns_i \\neq s_j and t_i \\neq t_j.\n\nFor example, abcac and zyxzx are isomorphic, while abcac and ppppp are not.\n\nA string s is said to be in normal form when the following condition is satisfied:\n\nFor every string t that is isomorphic to s, s \\leq t holds. Here \\leq denotes lexicographic comparison.\n\nFor example, abcac is in normal form, but zyxzx is not since it is isomorphic to abcac, which is lexicographically smaller than zyxzx.\n\nYou are given an integer N.\nPrint all strings of length N that are in normal form, in lexicographically ascending order.\n\nConstraints\n\n1 \\leq N \\leq 10\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\nAssume that there are K strings of length N that are in normal form: w_1, \\ldots, w_K in lexicographical order.\nOutput should be in the following format:\n\nw_1\n:\nw_K\n\nSample Input 1\n\n1\n\nSample Output 1\n\na\n\nSample Input 2\n\n2\n\nSample Output 2\n\naa\nab", "sample_input": "1\n"}, "reference_outputs": ["a\n"], "source_document_id": "p02744", "source_text": "Score : 400 points\n\nProblem Statement\n\nIn this problem, we only consider strings consisting of lowercase English letters.\n\nStrings s and t are said to be isomorphic when the following conditions are satisfied:\n\n|s| = |t| holds.\n\nFor every pair i, j, one of the following holds:\n\ns_i = s_j and t_i = t_j.\n\ns_i \\neq s_j and t_i \\neq t_j.\n\nFor example, abcac and zyxzx are isomorphic, while abcac and ppppp are not.\n\nA string s is said to be in normal form when the following condition is satisfied:\n\nFor every string t that is isomorphic to s, s \\leq t holds. Here \\leq denotes lexicographic comparison.\n\nFor example, abcac is in normal form, but zyxzx is not since it is isomorphic to abcac, which is lexicographically smaller than zyxzx.\n\nYou are given an integer N.\nPrint all strings of length N that are in normal form, in lexicographically ascending order.\n\nConstraints\n\n1 \\leq N \\leq 10\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\nAssume that there are K strings of length N that are in normal form: w_1, \\ldots, w_K in lexicographical order.\nOutput should be in the following format:\n\nw_1\n:\nw_K\n\nSample Input 1\n\n1\n\nSample Output 1\n\na\n\nSample Input 2\n\n2\n\nSample Output 2\n\naa\nab", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4448, "cpu_time_ms": 149, "memory_kb": 36456}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s939362282", "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 (max len-a (+ init1 len-b))\n :element-type 'base-char)))\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 (assert (char= (aref a i) (aref b j)))\n (setf (aref ab i) (aref b j)))))\n (dbg init1 ab)\n (let ((len-ab (length ab)))\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": 1584237217, "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/s939362282.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s939362282", "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 (max len-a (+ init1 len-b))\n :element-type 'base-char)))\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 (assert (char= (aref a i) (aref b j)))\n (setf (aref ab i) (aref b j)))))\n (dbg init1 ab)\n (let ((len-ab (length ab)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6216, "cpu_time_ms": 1609, "memory_kb": 31204}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s829632948", "group_id": "codeNet:p02747", "input_text": "(format t \"~:[No~;Yes~]~%\"\n\t(let* ((s (read-line))\n\t (l (length s)))\n\t (if (oddp l)\n\t nil\n\t (loop for i upto (- l 2) by 2\n\t\t always (equal \"hi\" (subseq s i (+ i 2)))))))", "language": "Lisp", "metadata": {"date": 1583724378, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02747.html", "problem_id": "p02747", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02747/input.txt", "sample_output_relpath": "derived/input_output/data/p02747/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02747/Lisp/s829632948.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s829632948", "user_id": "u320993798"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(format t \"~:[No~;Yes~]~%\"\n\t(let* ((s (read-line))\n\t (l (length s)))\n\t (if (oddp l)\n\t nil\n\t (loop for i upto (- l 2) by 2\n\t\t always (equal \"hi\" (subseq s i (+ i 2)))))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nA Hitachi string is a concatenation of one or more copies of the string hi.\n\nFor example, hi and hihi are Hitachi strings, while ha and hii are not.\n\nGiven a string S, determine whether S is a Hitachi string.\n\nConstraints\n\nThe length of S is between 1 and 10 (inclusive).\n\nS is a string 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 a Hitachi string, print Yes; otherwise, print No.\n\nSample Input 1\n\nhihi\n\nSample Output 1\n\nYes\n\nhihi is the concatenation of two copies of hi, so it is a Hitachi string.\n\nSample Input 2\n\nhi\n\nSample Output 2\n\nYes\n\nSample Input 3\n\nha\n\nSample Output 3\n\nNo", "sample_input": "hihi\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02747", "source_text": "Score : 100 points\n\nProblem Statement\n\nA Hitachi string is a concatenation of one or more copies of the string hi.\n\nFor example, hi and hihi are Hitachi strings, while ha and hii are not.\n\nGiven a string S, determine whether S is a Hitachi string.\n\nConstraints\n\nThe length of S is between 1 and 10 (inclusive).\n\nS is a string 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 a Hitachi string, print Yes; otherwise, print No.\n\nSample Input 1\n\nhihi\n\nSample Output 1\n\nYes\n\nhihi is the concatenation of two copies of hi, so it is a Hitachi string.\n\nSample Input 2\n\nhi\n\nSample Output 2\n\nYes\n\nSample Input 3\n\nha\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 107, "memory_kb": 11112}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s698147686", "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-fixnum))\n\t (b-num (read-fixnum))\n\t (m-num (read-fixnum))\n\t (a-price (make-array a-num))\n\t (b-price (make-array b-num))\n\t (price 200000))\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": 1583722221, "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/s698147686.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s698147686", "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-fixnum))\n\t (b-num (read-fixnum))\n\t (m-num (read-fixnum))\n\t (a-price (make-array a-num))\n\t (b-price (make-array b-num))\n\t (price 200000))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1894, "cpu_time_ms": 346, "memory_kb": 22500}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s780535917", "group_id": "codeNet:p02748", "input_text": "(let* ((a (read))\n (b (read))\n (m (read))\n (a-l (map 'vector (lambda (x) x) (loop :repeat a :collect (read))))\n (b-l (map 'vector (lambda (x) x) (loop :repeat b :collect (read))))\n (ll (loop :repeat m :collect (list (read) (read) (read)))))\n (princ (min (+ (loop :for k :across a-l :minimize k)\n (loop :for k :across b-l :minimize k))\n (loop :for n-ll :in ll\n :minimize (+ (aref a-l (1- (first n-ll)))\n (aref b-l (1- (second n-ll)))\n (* -1 (third n-ll)))))))", "language": "Lisp", "metadata": {"date": 1583716682, "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/s780535917.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s780535917", "user_id": "u610490393"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let* ((a (read))\n (b (read))\n (m (read))\n (a-l (map 'vector (lambda (x) x) (loop :repeat a :collect (read))))\n (b-l (map 'vector (lambda (x) x) (loop :repeat b :collect (read))))\n (ll (loop :repeat m :collect (list (read) (read) (read)))))\n (princ (min (+ (loop :for k :across a-l :minimize k)\n (loop :for k :across b-l :minimize k))\n (loop :for n-ll :in ll\n :minimize (+ (aref a-l (1- (first n-ll)))\n (aref b-l (1- (second n-ll)))\n (* -1 (third n-ll)))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 601, "cpu_time_ms": 958, "memory_kb": 68008}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s698235774", "group_id": "codeNet:p02749", "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 (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(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 (graph (make-array n :element-type 'list :initial-element nil))\n (colors (make-array n :element-type 'bit)))\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 (multiple-value-bind (quot rem) (floor n 3)\n (let* ((num1 (+ quot (if (>= rem 1) 1 0)))\n (num2 (+ quot (if (>= rem 2) 1 0)))\n (num3 quot)\n (nums1 (loop for i from 1 to num1 collect (- (* i 3) 2)))\n (nums2 (loop for i from 1 to num2 collect (- (* i 3) 1)))\n (nums3 (loop for i from 1 to num3 collect (* i 3))))\n (dbg num1 num2 num3)\n (labels ((dfs (v parent color)\n (setf (aref colors v) color)\n (dolist (child (aref graph v))\n (unless (= child parent)\n (dfs child v (logxor color 1))))))\n (dfs 0 -1 0)\n (let* ((vs0 (loop for v below n\n when (zerop (aref colors v))\n collect v))\n (vs1 (loop for v below n\n when (= 1 (aref colors v))\n collect v))\n (vs0-size (length vs0))\n (vs1-size (length vs1))\n (res (make-array n :element-type 'uint32)))\n (when (> vs0-size vs1-size)\n (rotatef vs0 vs1)\n (rotatef vs0-size vs1-size))\n (dbg vs0 vs1 vs0-size vs1-size)\n (dbg nums1 nums2 nums3)\n (if (<= vs0-size num3)\n (progn\n (dolist (v0 vs0)\n (if nums3\n (setf (aref res v0) (pop nums3))\n (error \"Huh?\")))\n (dolist (v1 vs1)\n (cond (nums3 (setf (aref res v1) (pop nums3)))\n (nums2 (setf (aref res v1) (pop nums2)))\n (nums1 (setf (aref res v1) (pop nums1)))\n (t (error \"Huh?\")))))\n (progn\n (dolist (v0 vs0)\n (cond (nums2 (setf (aref res v0) (pop nums2)))\n (nums3 (setf (aref res v0) (pop nums3)))\n (t (error \"Huh?\"))))\n (dolist (v1 vs1)\n (cond (nums1 (setf (aref res v1) (pop nums1)))\n (nums3 (setf (aref res v1) (pop nums3)))\n (t (error \"Huh?\"))))))\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 \"5\n1 2\n1 3\n3 4\n3 5\n\"\n \"1 2 5 4 3\n\")))\n", "language": "Lisp", "metadata": {"date": 1583718775, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02749.html", "problem_id": "p02749", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02749/input.txt", "sample_output_relpath": "derived/input_output/data/p02749/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02749/Lisp/s698235774.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s698235774", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 2 5 4 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(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(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 (graph (make-array n :element-type 'list :initial-element nil))\n (colors (make-array n :element-type 'bit)))\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 (multiple-value-bind (quot rem) (floor n 3)\n (let* ((num1 (+ quot (if (>= rem 1) 1 0)))\n (num2 (+ quot (if (>= rem 2) 1 0)))\n (num3 quot)\n (nums1 (loop for i from 1 to num1 collect (- (* i 3) 2)))\n (nums2 (loop for i from 1 to num2 collect (- (* i 3) 1)))\n (nums3 (loop for i from 1 to num3 collect (* i 3))))\n (dbg num1 num2 num3)\n (labels ((dfs (v parent color)\n (setf (aref colors v) color)\n (dolist (child (aref graph v))\n (unless (= child parent)\n (dfs child v (logxor color 1))))))\n (dfs 0 -1 0)\n (let* ((vs0 (loop for v below n\n when (zerop (aref colors v))\n collect v))\n (vs1 (loop for v below n\n when (= 1 (aref colors v))\n collect v))\n (vs0-size (length vs0))\n (vs1-size (length vs1))\n (res (make-array n :element-type 'uint32)))\n (when (> vs0-size vs1-size)\n (rotatef vs0 vs1)\n (rotatef vs0-size vs1-size))\n (dbg vs0 vs1 vs0-size vs1-size)\n (dbg nums1 nums2 nums3)\n (if (<= vs0-size num3)\n (progn\n (dolist (v0 vs0)\n (if nums3\n (setf (aref res v0) (pop nums3))\n (error \"Huh?\")))\n (dolist (v1 vs1)\n (cond (nums3 (setf (aref res v1) (pop nums3)))\n (nums2 (setf (aref res v1) (pop nums2)))\n (nums1 (setf (aref res v1) (pop nums1)))\n (t (error \"Huh?\")))))\n (progn\n (dolist (v0 vs0)\n (cond (nums2 (setf (aref res v0) (pop nums2)))\n (nums3 (setf (aref res v0) (pop nums3)))\n (t (error \"Huh?\"))))\n (dolist (v1 vs1)\n (cond (nums1 (setf (aref res v1) (pop nums1)))\n (nums3 (setf (aref res v1) (pop nums3)))\n (t (error \"Huh?\"))))))\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 \"5\n1 2\n1 3\n3 4\n3 5\n\"\n \"1 2 5 4 3\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices. The vertices are numbered 1 to N, and the i-th edge connects Vertex a_i and Vertex b_i.\n\nTakahashi loves the number 3. He is seeking a permutation p_1, p_2, \\ldots , p_N of integers from 1 to N satisfying the following condition:\n\nFor every pair of vertices (i, j), if the distance between Vertex i and Vertex j is 3, the sum or product of p_i and p_j is a multiple of 3.\n\nHere the distance between Vertex i and Vertex j is the number of edges contained in the shortest path from Vertex i to Vertex j.\n\nHelp Takahashi by finding a permutation that satisfies the condition.\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\na_2 b_2\n\\vdots\na_{N-1} b_{N-1}\n\nOutput\n\nIf no permutation satisfies the condition, print -1.\n\nOtherwise, print a permutation satisfying the condition, with space in between.\nIf there are multiple solutions, you can print any of them.\n\nSample Input 1\n\n5\n1 2\n1 3\n3 4\n3 5\n\nSample Output 1\n\n1 2 5 4 3\n\nThe distance between two vertices is 3 for the two pairs (2, 4) and (2, 5).\n\np_2 + p_4 = 6\n\np_2\\times p_5 = 6\n\nThus, this permutation satisfies the condition.", "sample_input": "5\n1 2\n1 3\n3 4\n3 5\n"}, "reference_outputs": ["1 2 5 4 3\n"], "source_document_id": "p02749", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have a tree with N vertices. The vertices are numbered 1 to N, and the i-th edge connects Vertex a_i and Vertex b_i.\n\nTakahashi loves the number 3. He is seeking a permutation p_1, p_2, \\ldots , p_N of integers from 1 to N satisfying the following condition:\n\nFor every pair of vertices (i, j), if the distance between Vertex i and Vertex j is 3, the sum or product of p_i and p_j is a multiple of 3.\n\nHere the distance between Vertex i and Vertex j is the number of edges contained in the shortest path from Vertex i to Vertex j.\n\nHelp Takahashi by finding a permutation that satisfies the condition.\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\na_2 b_2\n\\vdots\na_{N-1} b_{N-1}\n\nOutput\n\nIf no permutation satisfies the condition, print -1.\n\nOtherwise, print a permutation satisfying the condition, with space in between.\nIf there are multiple solutions, you can print any of them.\n\nSample Input 1\n\n5\n1 2\n1 3\n3 4\n3 5\n\nSample Output 1\n\n1 2 5 4 3\n\nThe distance between two vertices is 3 for the two pairs (2, 4) and (2, 5).\n\np_2 + p_4 = 6\n\np_2\\times p_5 = 6\n\nThus, this permutation satisfies the condition.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7997, "cpu_time_ms": 331, "memory_kb": 53176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s511575150", "group_id": "codeNet:p02753", "input_text": "(format t \"~A\"\n\t(let ((str (read))) (if (or (string= str \"AAA\") (string= str \"BBB\")) \"No\" \"Yes\")))", "language": "Lisp", "metadata": {"date": 1584242392, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02753.html", "problem_id": "p02753", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02753/input.txt", "sample_output_relpath": "derived/input_output/data/p02753/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02753/Lisp/s511575150.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s511575150", "user_id": "u334552723"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(format t \"~A\"\n\t(let ((str (read))) (if (or (string= str \"AAA\") (string= str \"BBB\")) \"No\" \"Yes\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn AtCoder City, there are three stations numbered 1, 2, and 3.\n\nEach of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A, Company A operates Station i; if S_i is B, Company B operates Station i.\n\nTo improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.\n\nDetermine if there is a pair of stations that will be connected by a bus service.\n\nConstraints\n\nEach character of S is A or B.\n\n|S| = 3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf there is a pair of stations that will be connected by a bus service, print Yes; otherwise, print No.\n\nSample Input 1\n\nABA\n\nSample Output 1\n\nYes\n\nCompany A operates Station 1 and 3, while Company B operates Station 2.\n\nThere will be a bus service between Station 1 and 2, and between Station 2 and 3, so print Yes.\n\nSample Input 2\n\nBBA\n\nSample Output 2\n\nYes\n\nCompany B operates Station 1 and 2, while Company A operates Station 3.\n\nThere will be a bus service between Station 1 and 3, and between Station 2 and 3, so print Yes.\n\nSample Input 3\n\nBBB\n\nSample Output 3\n\nNo\n\nCompany B operates all the stations. Thus, there will be no bus service, so print No.", "sample_input": "ABA\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02753", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn AtCoder City, there are three stations numbered 1, 2, and 3.\n\nEach of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A, Company A operates Station i; if S_i is B, Company B operates Station i.\n\nTo improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.\n\nDetermine if there is a pair of stations that will be connected by a bus service.\n\nConstraints\n\nEach character of S is A or B.\n\n|S| = 3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf there is a pair of stations that will be connected by a bus service, print Yes; otherwise, print No.\n\nSample Input 1\n\nABA\n\nSample Output 1\n\nYes\n\nCompany A operates Station 1 and 3, while Company B operates Station 2.\n\nThere will be a bus service between Station 1 and 2, and between Station 2 and 3, so print Yes.\n\nSample Input 2\n\nBBA\n\nSample Output 2\n\nYes\n\nCompany B operates Station 1 and 2, while Company A operates Station 3.\n\nThere will be a bus service between Station 1 and 3, and between Station 2 and 3, so print Yes.\n\nSample Input 3\n\nBBB\n\nSample Output 3\n\nNo\n\nCompany B operates all the stations. Thus, there will be no bus service, so print No.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 79, "memory_kb": 8676}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s303605331", "group_id": "codeNet:p02753", "input_text": "(let ((s (read-line)))\n (format t \"~a~%\"\n (if (or (every #'(lambda (c) (char= c #\\A)) s)\n (every #'(lambda (c) (char= c #\\B)) s))\n \"No\"\n \"Yes\")))\n", "language": "Lisp", "metadata": {"date": 1583633002, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02753.html", "problem_id": "p02753", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02753/input.txt", "sample_output_relpath": "derived/input_output/data/p02753/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02753/Lisp/s303605331.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s303605331", "user_id": "u690263481"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((s (read-line)))\n (format t \"~a~%\"\n (if (or (every #'(lambda (c) (char= c #\\A)) s)\n (every #'(lambda (c) (char= c #\\B)) s))\n \"No\"\n \"Yes\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn AtCoder City, there are three stations numbered 1, 2, and 3.\n\nEach of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A, Company A operates Station i; if S_i is B, Company B operates Station i.\n\nTo improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.\n\nDetermine if there is a pair of stations that will be connected by a bus service.\n\nConstraints\n\nEach character of S is A or B.\n\n|S| = 3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf there is a pair of stations that will be connected by a bus service, print Yes; otherwise, print No.\n\nSample Input 1\n\nABA\n\nSample Output 1\n\nYes\n\nCompany A operates Station 1 and 3, while Company B operates Station 2.\n\nThere will be a bus service between Station 1 and 2, and between Station 2 and 3, so print Yes.\n\nSample Input 2\n\nBBA\n\nSample Output 2\n\nYes\n\nCompany B operates Station 1 and 2, while Company A operates Station 3.\n\nThere will be a bus service between Station 1 and 3, and between Station 2 and 3, so print Yes.\n\nSample Input 3\n\nBBB\n\nSample Output 3\n\nNo\n\nCompany B operates all the stations. Thus, there will be no bus service, so print No.", "sample_input": "ABA\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02753", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn AtCoder City, there are three stations numbered 1, 2, and 3.\n\nEach of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A, Company A operates Station i; if S_i is B, Company B operates Station i.\n\nTo improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.\n\nDetermine if there is a pair of stations that will be connected by a bus service.\n\nConstraints\n\nEach character of S is A or B.\n\n|S| = 3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf there is a pair of stations that will be connected by a bus service, print Yes; otherwise, print No.\n\nSample Input 1\n\nABA\n\nSample Output 1\n\nYes\n\nCompany A operates Station 1 and 3, while Company B operates Station 2.\n\nThere will be a bus service between Station 1 and 2, and between Station 2 and 3, so print Yes.\n\nSample Input 2\n\nBBA\n\nSample Output 2\n\nYes\n\nCompany B operates Station 1 and 2, while Company A operates Station 3.\n\nThere will be a bus service between Station 1 and 3, and between Station 2 and 3, so print Yes.\n\nSample Input 3\n\nBBB\n\nSample Output 3\n\nNo\n\nCompany B operates all the stations. Thus, there will be no bus service, so print No.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 235, "memory_kb": 10724}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s609739732", "group_id": "codeNet:p02753", "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* ((s (read-line)))\n (write-line\n (if (or (equal \"AAA\" s)\n (equal \"BBB\" s))\n \"No\"\n \"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 \"ABA\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"BBA\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"BBB\n\"\n \"No\n\")))\n", "language": "Lisp", "metadata": {"date": 1583632881, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02753.html", "problem_id": "p02753", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02753/input.txt", "sample_output_relpath": "derived/input_output/data/p02753/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02753/Lisp/s609739732.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s609739732", "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 ;; 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* ((s (read-line)))\n (write-line\n (if (or (equal \"AAA\" s)\n (equal \"BBB\" s))\n \"No\"\n \"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 \"ABA\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"BBA\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"BBB\n\"\n \"No\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn AtCoder City, there are three stations numbered 1, 2, and 3.\n\nEach of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A, Company A operates Station i; if S_i is B, Company B operates Station i.\n\nTo improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.\n\nDetermine if there is a pair of stations that will be connected by a bus service.\n\nConstraints\n\nEach character of S is A or B.\n\n|S| = 3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf there is a pair of stations that will be connected by a bus service, print Yes; otherwise, print No.\n\nSample Input 1\n\nABA\n\nSample Output 1\n\nYes\n\nCompany A operates Station 1 and 3, while Company B operates Station 2.\n\nThere will be a bus service between Station 1 and 2, and between Station 2 and 3, so print Yes.\n\nSample Input 2\n\nBBA\n\nSample Output 2\n\nYes\n\nCompany B operates Station 1 and 2, while Company A operates Station 3.\n\nThere will be a bus service between Station 1 and 3, and between Station 2 and 3, so print Yes.\n\nSample Input 3\n\nBBB\n\nSample Output 3\n\nNo\n\nCompany B operates all the stations. Thus, there will be no bus service, so print No.", "sample_input": "ABA\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02753", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn AtCoder City, there are three stations numbered 1, 2, and 3.\n\nEach of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A, Company A operates Station i; if S_i is B, Company B operates Station i.\n\nTo improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.\n\nDetermine if there is a pair of stations that will be connected by a bus service.\n\nConstraints\n\nEach character of S is A or B.\n\n|S| = 3\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf there is a pair of stations that will be connected by a bus service, print Yes; otherwise, print No.\n\nSample Input 1\n\nABA\n\nSample Output 1\n\nYes\n\nCompany A operates Station 1 and 3, while Company B operates Station 2.\n\nThere will be a bus service between Station 1 and 2, and between Station 2 and 3, so print Yes.\n\nSample Input 2\n\nBBA\n\nSample Output 2\n\nYes\n\nCompany B operates Station 1 and 2, while Company A operates Station 3.\n\nThere will be a bus service between Station 1 and 3, and between Station 2 and 3, so print Yes.\n\nSample Input 3\n\nBBB\n\nSample Output 3\n\nNo\n\nCompany B operates all the stations. Thus, there will be no bus service, so print No.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 404, "memory_kb": 14056}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s347192946", "group_id": "codeNet:p02754", "input_text": "(defun app ()\n (let* ((n (read))\n (a (read))\n (b (read))\n (c (floor (/ n (+ a b))))\n (d (rem n (+ a b)))\n (ans (* a c)))\n (if (>= d a)\n (incf ans a)\n (incf ans d))\n (format t \"~D~%\" ans)\n )\n)\n(app)", "language": "Lisp", "metadata": {"date": 1592669719, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s347192946.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s347192946", "user_id": "u136500538"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun app ()\n (let* ((n (read))\n (a (read))\n (b (read))\n (c (floor (/ n (+ a b))))\n (d (rem n (+ a b)))\n (ans (* a c)))\n (if (>= d a)\n (incf ans a)\n (incf ans d))\n (format t \"~D~%\" ans)\n )\n)\n(app)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 266, "cpu_time_ms": 17, "memory_kb": 24384}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s567820388", "group_id": "codeNet:p02755", "input_text": ";; C - Tax Increase\n\n(defun solve (a b)\n \"floor(x * 0.08) == a, floor(x * 0.1) == b である x.\n 1 <= a <= b <= 100\"\n (or (cdr (assoc (cons a b)\n (loop for x from 1 to (/ 100 8/100)\n collect (cons (cons (floor (* x 8/100))\n (floor (* x 1/10))) x))\n :test #'equal))\n -1))\n\n(let ((a (read))\n (b (read)))\n (princ (solve a b)))\n", "language": "Lisp", "metadata": {"date": 1584202752, "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/s567820388.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s567820388", "user_id": "u227020436"}, "prompt_components": {"gold_output": "25\n", "input_to_evaluate": ";; C - Tax Increase\n\n(defun solve (a b)\n \"floor(x * 0.08) == a, floor(x * 0.1) == b である x.\n 1 <= a <= b <= 100\"\n (or (cdr (assoc (cons a b)\n (loop for x from 1 to (/ 100 8/100)\n collect (cons (cons (floor (* x 8/100))\n (floor (* x 1/10))) x))\n :test #'equal))\n -1))\n\n(let ((a (read))\n (b (read)))\n (princ (solve a b)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 420, "cpu_time_ms": 27, "memory_kb": 6884}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s459424620", "group_id": "codeNet:p02755", "input_text": "(format t \"~:[-1~;~d~]~%\"\n\t(let ((a (read))\n\t (b (read))\n\t (c (find-if (lambda (x) (find x (loop for i upfrom (floor b 0.1) repeat 9 collect i)))\n\t\t\t (loop for i upfrom (floor a 0.08) repeat 12 collect i))))\n\t (list (and (= a (c * 0.08)) (= b (c * 0.1))) c)))", "language": "Lisp", "metadata": {"date": 1583691184, "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/s459424620.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s459424620", "user_id": "u320993798"}, "prompt_components": {"gold_output": "25\n", "input_to_evaluate": "(format t \"~:[-1~;~d~]~%\"\n\t(let ((a (read))\n\t (b (read))\n\t (c (find-if (lambda (x) (find x (loop for i upfrom (floor b 0.1) repeat 9 collect i)))\n\t\t\t (loop for i upfrom (floor a 0.08) repeat 12 collect i))))\n\t (list (and (= a (c * 0.08)) (= b (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 28, "memory_kb": 7140}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s818363170", "group_id": "codeNet:p02755", "input_text": "(let* ((a (read))\n (a-val (/ a 0.08))\n (a-val-limit (/ (+ a 1) 0.08))\n (b (read))\n (b-val (/ b 0.10))\n (b-val-limit (/ (+ b 1) 0.10))\n (ans -1))\n (loop for val from (ceiling (max a-val b-val)) below (min a-val-limit b-val-limit)\n do (progn\n (setf ans val)\n (loop-finish)))\n (format t \"~a~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1583634181, "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/s818363170.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s818363170", "user_id": "u690263481"}, "prompt_components": {"gold_output": "25\n", "input_to_evaluate": "(let* ((a (read))\n (a-val (/ a 0.08))\n (a-val-limit (/ (+ a 1) 0.08))\n (b (read))\n (b-val (/ b 0.10))\n (b-val-limit (/ (+ b 1) 0.10))\n (ans -1))\n (loop for val from (ceiling (max a-val b-val)) below (min a-val-limit b-val-limit)\n do (progn\n (setf ans val)\n (loop-finish)))\n (format t \"~a~%\" ans))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 144, "memory_kb": 16352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s108990033", "group_id": "codeNet:p02756", "input_text": "(defvar tl (list \"\"))\n(defvar hd (nconc (concatenate 'list (read-line)) tl))\n(defvar rev nil)\n\n(loop repeat (read)\n do\n (if (= (read) 1)\n (setf rev (not rev))\n (if (eq (= (read) 1) rev) \n (progn \n (rplacd tl (list (read-char)))\n (setf tl (cdr tl)))\n (push (read-char) hd) )))\n\n(if rev \n (mapc #'princ (nreverse hd))\n (mapc #'princ hd))", "language": "Lisp", "metadata": {"date": 1586263510, "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/s108990033.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s108990033", "user_id": "u334552723"}, "prompt_components": {"gold_output": "cpa\n", "input_to_evaluate": "(defvar tl (list \"\"))\n(defvar hd (nconc (concatenate 'list (read-line)) tl))\n(defvar rev nil)\n\n(loop repeat (read)\n do\n (if (= (read) 1)\n (setf rev (not rev))\n (if (eq (= (read) 1) rev) \n (progn \n (rplacd tl (list (read-char)))\n (setf tl (cdr tl)))\n (push (read-char) hd) )))\n\n(if rev \n (mapc #'princ (nreverse hd))\n (mapc #'princ hd))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 598, "memory_kb": 62148}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s936902171", "group_id": "codeNet:p02759", "input_text": ";; A - Duplex Printing\n\n(let ((n (read)))\n (princ (ceiling (/ n 2))))", "language": "Lisp", "metadata": {"date": 1584282421, "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/s936902171.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s936902171", "user_id": "u227020436"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": ";; A - Duplex Printing\n\n(let ((n (read)))\n (princ (ceiling (/ n 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 124, "memory_kb": 12644}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s867544717", "group_id": "codeNet:p02759", "input_text": "(format t \"~A~%\" (ceiling (read) 2))\n", "language": "Lisp", "metadata": {"date": 1583114441, "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/s867544717.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s867544717", "user_id": "u202886318"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(format t \"~A~%\" (ceiling (read) 2))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s935058885", "group_id": "codeNet:p02760", "input_text": ";; B - Bingo\n\n(defun bingo (a b)\n (labels ((subset-of-b (lst)\n (subsetp lst b))\n (columns (rows)\n (loop for i below 3 collect\n (mapcar #'(lambda (row) (nth i row)) rows)))\n (diagonals (rows)\n (list (mapcar #'nth '(0 1 2) rows)\n (mapcar #'nth '(2 1 0) rows))))\n (some #'subset-of-b\n (append a (columns a) (diagonals a)))))\n\n(let* ((a (loop repeat 3 collect (loop repeat 3 collect (read))))\n (n (read))\n (b (loop repeat n collect (read))))\n (princ (if (bingo a b) \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1584283651, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02760.html", "problem_id": "p02760", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02760/input.txt", "sample_output_relpath": "derived/input_output/data/p02760/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02760/Lisp/s935058885.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s935058885", "user_id": "u227020436"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";; B - Bingo\n\n(defun bingo (a b)\n (labels ((subset-of-b (lst)\n (subsetp lst b))\n (columns (rows)\n (loop for i below 3 collect\n (mapcar #'(lambda (row) (nth i row)) rows)))\n (diagonals (rows)\n (list (mapcar #'nth '(0 1 2) rows)\n (mapcar #'nth '(2 1 0) rows))))\n (some #'subset-of-b\n (append a (columns a) (diagonals a)))))\n\n(let* ((a (loop repeat 3 collect (loop repeat 3 collect (read))))\n (n (read))\n (b (loop repeat n collect (read))))\n (princ (if (bingo a b) \"Yes\" \"No\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a bingo card with a 3\\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.\n\nThe MC will choose N numbers, b_1, b_2, \\cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.\n\nDetermine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A_{i, j} \\leq 100\n\nA_{i_1, j_1} \\neq A_{i_2, j_2} ((i_1, j_1) \\neq (i_2, j_2))\n\n1 \\leq N \\leq 10\n\n1 \\leq b_i \\leq 100\n\nb_i \\neq b_j (i \\neq j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_{1, 1} A_{1, 2} A_{1, 3}\nA_{2, 1} A_{2, 2} A_{2, 3}\nA_{3, 1} A_{3, 2} A_{3, 3}\nN\nb_1\n\\vdots\nb_N\n\nOutput\n\nIf we will have a bingo, print Yes; otherwise, print No.\n\nSample Input 1\n\n84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n\nSample Output 1\n\nYes\n\nWe will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.\n\nSample Input 2\n\n41 7 46\n26 89 2\n78 92 8\n5\n6\n45\n16\n57\n17\n\nSample Output 2\n\nNo\n\nWe will mark nothing.\n\nSample Input 3\n\n60 88 34\n92 41 43\n65 73 48\n10\n60\n43\n88\n11\n48\n73\n65\n41\n92\n34\n\nSample Output 3\n\nYes\n\nWe will mark all the squares.", "sample_input": "84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02760", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a bingo card with a 3\\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.\n\nThe MC will choose N numbers, b_1, b_2, \\cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.\n\nDetermine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A_{i, j} \\leq 100\n\nA_{i_1, j_1} \\neq A_{i_2, j_2} ((i_1, j_1) \\neq (i_2, j_2))\n\n1 \\leq N \\leq 10\n\n1 \\leq b_i \\leq 100\n\nb_i \\neq b_j (i \\neq j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_{1, 1} A_{1, 2} A_{1, 3}\nA_{2, 1} A_{2, 2} A_{2, 3}\nA_{3, 1} A_{3, 2} A_{3, 3}\nN\nb_1\n\\vdots\nb_N\n\nOutput\n\nIf we will have a bingo, print Yes; otherwise, print No.\n\nSample Input 1\n\n84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n\nSample Output 1\n\nYes\n\nWe will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.\n\nSample Input 2\n\n41 7 46\n26 89 2\n78 92 8\n5\n6\n45\n16\n57\n17\n\nSample Output 2\n\nNo\n\nWe will mark nothing.\n\nSample Input 3\n\n60 88 34\n92 41 43\n65 73 48\n10\n60\n43\n88\n11\n48\n73\n65\n41\n92\n34\n\nSample Output 3\n\nYes\n\nWe will mark all the squares.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 137, "memory_kb": 15976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s652281475", "group_id": "codeNet:p02760", "input_text": "(defun split (x str)\n (let (\n (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 get-bingo-card ()\n (let ((string-bingo-card (loop \n as i \n below 3\n collect (split \" \" (read-line)))))\n (loop\n as line\n in string-bingo-card\n collect (mapcar #'parse-integer line))))\n\n(defun get-bingo-lines (bingo-card)\n (list\n (nth 0 bingo-card)\n (nth 1 bingo-card)\n (nth 2 bingo-card)\n (map 'list 'first bingo-card)\n (map 'list 'second bingo-card)\n (map 'list 'third bingo-card)\n (loop\n as i\n below 3\n collect (nth i (nth i bingo-card)))\n (loop\n as i\n below 3\n collect (nth (- 2 i) (nth i bingo-card)))\n ))\n\n(defun get-open-numbers ()\n (let (\n (n (read)))\n (loop\n as i\n below n\n collect (read))))\n\n(defun opened-bingo-card (bingo-card numbers)\n (loop\n for line\n in bingo-card\n collect (loop\n for bingo-number\n in line\n\t collect (if (position bingo-number numbers) 0 bingo-number))))\n\n(defun exist-bingo-line (lines)\n (if\n (not (zerop \n (count \n 3\n (loop\n as line\n in lines\n collect (count 0 line)))))\n \"Yes\"\n \"No\"))\n \n\n(princ (exist-bingo-line (get-bingo-lines (opened-bingo-card (get-bingo-card) (get-open-numbers)))))", "language": "Lisp", "metadata": {"date": 1583690364, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02760.html", "problem_id": "p02760", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02760/input.txt", "sample_output_relpath": "derived/input_output/data/p02760/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02760/Lisp/s652281475.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s652281475", "user_id": "u606976120"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun split (x str)\n (let (\n (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 get-bingo-card ()\n (let ((string-bingo-card (loop \n as i \n below 3\n collect (split \" \" (read-line)))))\n (loop\n as line\n in string-bingo-card\n collect (mapcar #'parse-integer line))))\n\n(defun get-bingo-lines (bingo-card)\n (list\n (nth 0 bingo-card)\n (nth 1 bingo-card)\n (nth 2 bingo-card)\n (map 'list 'first bingo-card)\n (map 'list 'second bingo-card)\n (map 'list 'third bingo-card)\n (loop\n as i\n below 3\n collect (nth i (nth i bingo-card)))\n (loop\n as i\n below 3\n collect (nth (- 2 i) (nth i bingo-card)))\n ))\n\n(defun get-open-numbers ()\n (let (\n (n (read)))\n (loop\n as i\n below n\n collect (read))))\n\n(defun opened-bingo-card (bingo-card numbers)\n (loop\n for line\n in bingo-card\n collect (loop\n for bingo-number\n in line\n\t collect (if (position bingo-number numbers) 0 bingo-number))))\n\n(defun exist-bingo-line (lines)\n (if\n (not (zerop \n (count \n 3\n (loop\n as line\n in lines\n collect (count 0 line)))))\n \"Yes\"\n \"No\"))\n \n\n(princ (exist-bingo-line (get-bingo-lines (opened-bingo-card (get-bingo-card) (get-open-numbers)))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a bingo card with a 3\\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.\n\nThe MC will choose N numbers, b_1, b_2, \\cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.\n\nDetermine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A_{i, j} \\leq 100\n\nA_{i_1, j_1} \\neq A_{i_2, j_2} ((i_1, j_1) \\neq (i_2, j_2))\n\n1 \\leq N \\leq 10\n\n1 \\leq b_i \\leq 100\n\nb_i \\neq b_j (i \\neq j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_{1, 1} A_{1, 2} A_{1, 3}\nA_{2, 1} A_{2, 2} A_{2, 3}\nA_{3, 1} A_{3, 2} A_{3, 3}\nN\nb_1\n\\vdots\nb_N\n\nOutput\n\nIf we will have a bingo, print Yes; otherwise, print No.\n\nSample Input 1\n\n84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n\nSample Output 1\n\nYes\n\nWe will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.\n\nSample Input 2\n\n41 7 46\n26 89 2\n78 92 8\n5\n6\n45\n16\n57\n17\n\nSample Output 2\n\nNo\n\nWe will mark nothing.\n\nSample Input 3\n\n60 88 34\n92 41 43\n65 73 48\n10\n60\n43\n88\n11\n48\n73\n65\n41\n92\n34\n\nSample Output 3\n\nYes\n\nWe will mark all the squares.", "sample_input": "84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02760", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a bingo card with a 3\\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.\n\nThe MC will choose N numbers, b_1, b_2, \\cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.\n\nDetermine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A_{i, j} \\leq 100\n\nA_{i_1, j_1} \\neq A_{i_2, j_2} ((i_1, j_1) \\neq (i_2, j_2))\n\n1 \\leq N \\leq 10\n\n1 \\leq b_i \\leq 100\n\nb_i \\neq b_j (i \\neq j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_{1, 1} A_{1, 2} A_{1, 3}\nA_{2, 1} A_{2, 2} A_{2, 3}\nA_{3, 1} A_{3, 2} A_{3, 3}\nN\nb_1\n\\vdots\nb_N\n\nOutput\n\nIf we will have a bingo, print Yes; otherwise, print No.\n\nSample Input 1\n\n84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n\nSample Output 1\n\nYes\n\nWe will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.\n\nSample Input 2\n\n41 7 46\n26 89 2\n78 92 8\n5\n6\n45\n16\n57\n17\n\nSample Output 2\n\nNo\n\nWe will mark nothing.\n\nSample Input 3\n\n60 88 34\n92 41 43\n65 73 48\n10\n60\n43\n88\n11\n48\n73\n65\n41\n92\n34\n\nSample Output 3\n\nYes\n\nWe will mark all the squares.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1405, "cpu_time_ms": 24, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s095808573", "group_id": "codeNet:p02760", "input_text": "(defun lref (list i j)\n (nth j (nth i list)))\n\n(defun check-bingo (list)\n (or (loop for i from 0 below 3\n thereis (loop for j from 0 below 3\n always (zerop (lref list i j))))\n (loop for i from 0 below 3\n thereis (loop for j from 0 below 3\n always (zerop (lref list j i))))\n (loop for i from 0 below 3\n always (zerop (lref list i i)))\n (loop for i from 0 below 3\n always (zerop (lref list (- 2 i) i)))))\n\n(let ((bingo\n (loop for i from 0 below 3\n collect (loop for j from 0 below 3\n collect (read))))\n (n (read)))\n (loop repeat n\n do (setf bingo (subst 0 (read) bingo)))\n (format t \"~a~%\" (if (check-bingo bingo)\n \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1583115593, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02760.html", "problem_id": "p02760", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02760/input.txt", "sample_output_relpath": "derived/input_output/data/p02760/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02760/Lisp/s095808573.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s095808573", "user_id": "u690263481"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun lref (list i j)\n (nth j (nth i list)))\n\n(defun check-bingo (list)\n (or (loop for i from 0 below 3\n thereis (loop for j from 0 below 3\n always (zerop (lref list i j))))\n (loop for i from 0 below 3\n thereis (loop for j from 0 below 3\n always (zerop (lref list j i))))\n (loop for i from 0 below 3\n always (zerop (lref list i i)))\n (loop for i from 0 below 3\n always (zerop (lref list (- 2 i) i)))))\n\n(let ((bingo\n (loop for i from 0 below 3\n collect (loop for j from 0 below 3\n collect (read))))\n (n (read)))\n (loop repeat n\n do (setf bingo (subst 0 (read) bingo)))\n (format t \"~a~%\" (if (check-bingo bingo)\n \"Yes\" \"No\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a bingo card with a 3\\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.\n\nThe MC will choose N numbers, b_1, b_2, \\cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.\n\nDetermine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A_{i, j} \\leq 100\n\nA_{i_1, j_1} \\neq A_{i_2, j_2} ((i_1, j_1) \\neq (i_2, j_2))\n\n1 \\leq N \\leq 10\n\n1 \\leq b_i \\leq 100\n\nb_i \\neq b_j (i \\neq j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_{1, 1} A_{1, 2} A_{1, 3}\nA_{2, 1} A_{2, 2} A_{2, 3}\nA_{3, 1} A_{3, 2} A_{3, 3}\nN\nb_1\n\\vdots\nb_N\n\nOutput\n\nIf we will have a bingo, print Yes; otherwise, print No.\n\nSample Input 1\n\n84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n\nSample Output 1\n\nYes\n\nWe will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.\n\nSample Input 2\n\n41 7 46\n26 89 2\n78 92 8\n5\n6\n45\n16\n57\n17\n\nSample Output 2\n\nNo\n\nWe will mark nothing.\n\nSample Input 3\n\n60 88 34\n92 41 43\n65 73 48\n10\n60\n43\n88\n11\n48\n73\n65\n41\n92\n34\n\nSample Output 3\n\nYes\n\nWe will mark all the squares.", "sample_input": "84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02760", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a bingo card with a 3\\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.\n\nThe MC will choose N numbers, b_1, b_2, \\cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.\n\nDetermine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A_{i, j} \\leq 100\n\nA_{i_1, j_1} \\neq A_{i_2, j_2} ((i_1, j_1) \\neq (i_2, j_2))\n\n1 \\leq N \\leq 10\n\n1 \\leq b_i \\leq 100\n\nb_i \\neq b_j (i \\neq j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA_{1, 1} A_{1, 2} A_{1, 3}\nA_{2, 1} A_{2, 2} A_{2, 3}\nA_{3, 1} A_{3, 2} A_{3, 3}\nN\nb_1\n\\vdots\nb_N\n\nOutput\n\nIf we will have a bingo, print Yes; otherwise, print No.\n\nSample Input 1\n\n84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n\nSample Output 1\n\nYes\n\nWe will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.\n\nSample Input 2\n\n41 7 46\n26 89 2\n78 92 8\n5\n6\n45\n16\n57\n17\n\nSample Output 2\n\nNo\n\nWe will mark nothing.\n\nSample Input 3\n\n60 88 34\n92 41 43\n65 73 48\n10\n60\n43\n88\n11\n48\n73\n65\n41\n92\n34\n\nSample Output 3\n\nYes\n\nWe will mark all the squares.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 821, "cpu_time_ms": 191, "memory_kb": 15848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s814765315", "group_id": "codeNet:p02762", "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(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(defun main ()\n (let* ((n (read))\n (m (read))\n (k (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (sizes (make-array n :element-type 'int32 :initial-element 0))\n (roots (make-array n :element-type 'int32 :initial-element -1))\n (as (make-array m :element-type 'int32))\n (bs (make-array m :element-type 'int32)))\n (declare (uint32 n m k))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (setf (aref as i) a\n (aref bs i) b)\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v root) ;; compute the size of each component and set root\n (setf (aref roots v) root)\n (+ 1 (loop for next in (aref graph v)\n when (= -1 (aref roots next))\n sum (dfs next root)))))\n (dotimes (v n)\n (when (= -1 (aref roots v))\n (setf (aref sizes v) (- (dfs v v) 1)))))\n (dotimes (v n)\n (setf (aref sizes v) (aref sizes (aref roots v))))\n (loop for i below k\n for c = (- (read-fixnum) 1)\n for d = (- (read-fixnum) 1)\n when (= (aref roots c) (aref roots d))\n do (decf (aref sizes c))\n (decf (aref sizes d)))\n (loop for a across as\n for b across bs\n when (= (aref roots a) (aref roots b))\n do (decf (aref sizes a))\n (decf (aref sizes b)))\n (println-sequence sizes)))\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 1\n2 1\n1 3\n3 2\n3 4\n4 1\n\"\n \"0 1 0 1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5\n\"\n \"0 0 0 0 0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1\n\"\n \"1 3 5 4 3 3 3 3 1 0\n\")))\n", "language": "Lisp", "metadata": {"date": 1583136268, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02762.html", "problem_id": "p02762", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02762/input.txt", "sample_output_relpath": "derived/input_output/data/p02762/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02762/Lisp/s814765315.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s814765315", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0 1 0 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 ;; 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(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(defun main ()\n (let* ((n (read))\n (m (read))\n (k (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (sizes (make-array n :element-type 'int32 :initial-element 0))\n (roots (make-array n :element-type 'int32 :initial-element -1))\n (as (make-array m :element-type 'int32))\n (bs (make-array m :element-type 'int32)))\n (declare (uint32 n m k))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (setf (aref as i) a\n (aref bs i) b)\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v root) ;; compute the size of each component and set root\n (setf (aref roots v) root)\n (+ 1 (loop for next in (aref graph v)\n when (= -1 (aref roots next))\n sum (dfs next root)))))\n (dotimes (v n)\n (when (= -1 (aref roots v))\n (setf (aref sizes v) (- (dfs v v) 1)))))\n (dotimes (v n)\n (setf (aref sizes v) (aref sizes (aref roots v))))\n (loop for i below k\n for c = (- (read-fixnum) 1)\n for d = (- (read-fixnum) 1)\n when (= (aref roots c) (aref roots d))\n do (decf (aref sizes c))\n (decf (aref sizes d)))\n (loop for a across as\n for b across bs\n when (= (aref roots a) (aref roots b))\n do (decf (aref sizes a))\n (decf (aref sizes b)))\n (println-sequence sizes)))\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 1\n2 1\n1 3\n3 2\n3 4\n4 1\n\"\n \"0 1 0 1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5\n\"\n \"0 0 0 0 0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1\n\"\n \"1 3 5 4 3 3 3 3 1 0\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nAn SNS has N users - User 1, User 2, \\cdots, User N.\n\nBetween these N users, there are some relationships - M friendships and K blockships.\n\nFor each i = 1, 2, \\cdots, M, there is a bidirectional friendship between User A_i and User B_i.\n\nFor each i = 1, 2, \\cdots, K, there is a bidirectional blockship between User C_i and User D_i.\n\nWe define User a to be a friend candidate for User b when all of the following four conditions are satisfied:\n\na \\neq b.\n\nThere is not a friendship between User a and User b.\n\nThere is not a blockship between User a and User b.\n\nThere exists a sequence c_0, c_1, c_2, \\cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \\cdots, L - 1.\n\nFor each user i = 1, 2, ... N, how many friend candidates does it have?\n\nConstraints\n\nAll values in input are integers.\n\n2 ≤ N ≤ 10^5\n\n0 \\leq M \\leq 10^5\n\n0 \\leq K \\leq 10^5\n\n1 \\leq A_i, B_i \\leq N\n\nA_i \\neq B_i\n\n1 \\leq C_i, D_i \\leq N\n\nC_i \\neq D_i\n\n(A_i, B_i) \\neq (A_j, B_j) (i \\neq j)\n\n(A_i, B_i) \\neq (B_j, A_j)\n\n(C_i, D_i) \\neq (C_j, D_j) (i \\neq j)\n\n(C_i, D_i) \\neq (D_j, C_j)\n\n(A_i, B_i) \\neq (C_j, D_j)\n\n(A_i, B_i) \\neq (D_j, C_j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M K\nA_1 B_1\n\\vdots\nA_M B_M\nC_1 D_1\n\\vdots\nC_K D_K\n\nOutput\n\nPrint the answers in order, with space in between.\n\nSample Input 1\n\n4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n\nSample Output 1\n\n0 1 0 1\n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there is no friendship or blockship between User 2 and 4. Thus, User 4 is a friend candidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has one friend candidate.\n\nSample Input 2\n\n5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5\n\nSample Output 2\n\n0 0 0 0 0\n\nEveryone is a friend of everyone else and has no friend candidate.\n\nSample Input 3\n\n10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1\n\nSample Output 3\n\n1 3 5 4 3 3 3 3 1 0", "sample_input": "4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n"}, "reference_outputs": ["0 1 0 1\n"], "source_document_id": "p02762", "source_text": "Score : 400 points\n\nProblem Statement\n\nAn SNS has N users - User 1, User 2, \\cdots, User N.\n\nBetween these N users, there are some relationships - M friendships and K blockships.\n\nFor each i = 1, 2, \\cdots, M, there is a bidirectional friendship between User A_i and User B_i.\n\nFor each i = 1, 2, \\cdots, K, there is a bidirectional blockship between User C_i and User D_i.\n\nWe define User a to be a friend candidate for User b when all of the following four conditions are satisfied:\n\na \\neq b.\n\nThere is not a friendship between User a and User b.\n\nThere is not a blockship between User a and User b.\n\nThere exists a sequence c_0, c_1, c_2, \\cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \\cdots, L - 1.\n\nFor each user i = 1, 2, ... N, how many friend candidates does it have?\n\nConstraints\n\nAll values in input are integers.\n\n2 ≤ N ≤ 10^5\n\n0 \\leq M \\leq 10^5\n\n0 \\leq K \\leq 10^5\n\n1 \\leq A_i, B_i \\leq N\n\nA_i \\neq B_i\n\n1 \\leq C_i, D_i \\leq N\n\nC_i \\neq D_i\n\n(A_i, B_i) \\neq (A_j, B_j) (i \\neq j)\n\n(A_i, B_i) \\neq (B_j, A_j)\n\n(C_i, D_i) \\neq (C_j, D_j) (i \\neq j)\n\n(C_i, D_i) \\neq (D_j, C_j)\n\n(A_i, B_i) \\neq (C_j, D_j)\n\n(A_i, B_i) \\neq (D_j, C_j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M K\nA_1 B_1\n\\vdots\nA_M B_M\nC_1 D_1\n\\vdots\nC_K D_K\n\nOutput\n\nPrint the answers in order, with space in between.\n\nSample Input 1\n\n4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n\nSample Output 1\n\n0 1 0 1\n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there is no friendship or blockship between User 2 and 4. Thus, User 4 is a friend candidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has one friend candidate.\n\nSample Input 2\n\n5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5\n\nSample Output 2\n\n0 0 0 0 0\n\nEveryone is a friend of everyone else and has no friend candidate.\n\nSample Input 3\n\n10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1\n\nSample Output 3\n\n1 3 5 4 3 3 3 3 1 0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6748, "cpu_time_ms": 241, "memory_kb": 46816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s271262069", "group_id": "codeNet:p02762", "input_text": "(defvar *already-looked*)\n\n(defun solve (n m k friends blocks)\n (declare (ignore m k))\n (let ((friends-maps\n (make-array n\n :element-type 'hash-table\n :initial-contents (loop repeat n collect (make-hash-table))))\n (blocks-maps\n (make-array n\n :element-type 'hash-table\n :initial-contents (loop repeat n collect (make-hash-table)))))\n (loop for (a . b) in friends\n do (setf (gethash b (aref friends-maps (1- a))) t\n (gethash a (aref friends-maps (1- b))) t))\n (loop for (a . b) in blocks\n do (setf (gethash b (aref blocks-maps (1- a))) t\n (gethash a (aref blocks-maps (1- b))) t))\n (flet ((friends-p (a b)\n (gethash b (aref friends-maps (1- a))))\n (blocks-p (a b)\n (gethash b (aref blocks-maps (1- a))))\n (friends-of (a)\n (loop for b being the hash-keys of (aref friends-maps (1- a))\n collect b))\n (blocks-of (a)\n (loop for b being the hash-keys of (aref blocks-maps (1- a))\n collect b)))\n (let ((counts (make-array n :element-type 'fixnum)))\n (labels ((main (a from)\n (setf (gethash a *already-looked*) t)\n (loop for b in (friends-of a)\n unless (gethash b *already-looked*)\n do\n (setf (gethash b *already-looked*) t)\n (when (and (not (= a from))\n (not (friends-p from b))\n (not (blocks-p from b)))\n (incf (aref counts (1- from))))\n (loop for c in (friends-of b)\n if (and (not (gethash c *already-looked*))\n (not (friends-p from c)))\n do (unless (blocks-p from c)\n (incf (aref counts (1- from))))\n (main c from)))))\n (loop for a from 1 to n\n do (let ((*already-looked* (make-hash-table)))\n (main a a))))\n (coerce counts 'list)))))\n\n#-swank\n(let* ((n (read))\n (m (read))\n (k (read))\n (friends (loop repeat m collect (cons (read) (read))))\n (blocks (loop repeat k collect (cons (read) (read)))))\n (format t \"~{~A~^ ~}~%\" (solve n m k friends blocks)))\n", "language": "Lisp", "metadata": {"date": 1583119563, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02762.html", "problem_id": "p02762", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02762/input.txt", "sample_output_relpath": "derived/input_output/data/p02762/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02762/Lisp/s271262069.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s271262069", "user_id": "u202886318"}, "prompt_components": {"gold_output": "0 1 0 1\n", "input_to_evaluate": "(defvar *already-looked*)\n\n(defun solve (n m k friends blocks)\n (declare (ignore m k))\n (let ((friends-maps\n (make-array n\n :element-type 'hash-table\n :initial-contents (loop repeat n collect (make-hash-table))))\n (blocks-maps\n (make-array n\n :element-type 'hash-table\n :initial-contents (loop repeat n collect (make-hash-table)))))\n (loop for (a . b) in friends\n do (setf (gethash b (aref friends-maps (1- a))) t\n (gethash a (aref friends-maps (1- b))) t))\n (loop for (a . b) in blocks\n do (setf (gethash b (aref blocks-maps (1- a))) t\n (gethash a (aref blocks-maps (1- b))) t))\n (flet ((friends-p (a b)\n (gethash b (aref friends-maps (1- a))))\n (blocks-p (a b)\n (gethash b (aref blocks-maps (1- a))))\n (friends-of (a)\n (loop for b being the hash-keys of (aref friends-maps (1- a))\n collect b))\n (blocks-of (a)\n (loop for b being the hash-keys of (aref blocks-maps (1- a))\n collect b)))\n (let ((counts (make-array n :element-type 'fixnum)))\n (labels ((main (a from)\n (setf (gethash a *already-looked*) t)\n (loop for b in (friends-of a)\n unless (gethash b *already-looked*)\n do\n (setf (gethash b *already-looked*) t)\n (when (and (not (= a from))\n (not (friends-p from b))\n (not (blocks-p from b)))\n (incf (aref counts (1- from))))\n (loop for c in (friends-of b)\n if (and (not (gethash c *already-looked*))\n (not (friends-p from c)))\n do (unless (blocks-p from c)\n (incf (aref counts (1- from))))\n (main c from)))))\n (loop for a from 1 to n\n do (let ((*already-looked* (make-hash-table)))\n (main a a))))\n (coerce counts 'list)))))\n\n#-swank\n(let* ((n (read))\n (m (read))\n (k (read))\n (friends (loop repeat m collect (cons (read) (read))))\n (blocks (loop repeat k collect (cons (read) (read)))))\n (format t \"~{~A~^ ~}~%\" (solve n m k friends blocks)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nAn SNS has N users - User 1, User 2, \\cdots, User N.\n\nBetween these N users, there are some relationships - M friendships and K blockships.\n\nFor each i = 1, 2, \\cdots, M, there is a bidirectional friendship between User A_i and User B_i.\n\nFor each i = 1, 2, \\cdots, K, there is a bidirectional blockship between User C_i and User D_i.\n\nWe define User a to be a friend candidate for User b when all of the following four conditions are satisfied:\n\na \\neq b.\n\nThere is not a friendship between User a and User b.\n\nThere is not a blockship between User a and User b.\n\nThere exists a sequence c_0, c_1, c_2, \\cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \\cdots, L - 1.\n\nFor each user i = 1, 2, ... N, how many friend candidates does it have?\n\nConstraints\n\nAll values in input are integers.\n\n2 ≤ N ≤ 10^5\n\n0 \\leq M \\leq 10^5\n\n0 \\leq K \\leq 10^5\n\n1 \\leq A_i, B_i \\leq N\n\nA_i \\neq B_i\n\n1 \\leq C_i, D_i \\leq N\n\nC_i \\neq D_i\n\n(A_i, B_i) \\neq (A_j, B_j) (i \\neq j)\n\n(A_i, B_i) \\neq (B_j, A_j)\n\n(C_i, D_i) \\neq (C_j, D_j) (i \\neq j)\n\n(C_i, D_i) \\neq (D_j, C_j)\n\n(A_i, B_i) \\neq (C_j, D_j)\n\n(A_i, B_i) \\neq (D_j, C_j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M K\nA_1 B_1\n\\vdots\nA_M B_M\nC_1 D_1\n\\vdots\nC_K D_K\n\nOutput\n\nPrint the answers in order, with space in between.\n\nSample Input 1\n\n4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n\nSample Output 1\n\n0 1 0 1\n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there is no friendship or blockship between User 2 and 4. Thus, User 4 is a friend candidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has one friend candidate.\n\nSample Input 2\n\n5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5\n\nSample Output 2\n\n0 0 0 0 0\n\nEveryone is a friend of everyone else and has no friend candidate.\n\nSample Input 3\n\n10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1\n\nSample Output 3\n\n1 3 5 4 3 3 3 3 1 0", "sample_input": "4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n"}, "reference_outputs": ["0 1 0 1\n"], "source_document_id": "p02762", "source_text": "Score : 400 points\n\nProblem Statement\n\nAn SNS has N users - User 1, User 2, \\cdots, User N.\n\nBetween these N users, there are some relationships - M friendships and K blockships.\n\nFor each i = 1, 2, \\cdots, M, there is a bidirectional friendship between User A_i and User B_i.\n\nFor each i = 1, 2, \\cdots, K, there is a bidirectional blockship between User C_i and User D_i.\n\nWe define User a to be a friend candidate for User b when all of the following four conditions are satisfied:\n\na \\neq b.\n\nThere is not a friendship between User a and User b.\n\nThere is not a blockship between User a and User b.\n\nThere exists a sequence c_0, c_1, c_2, \\cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \\cdots, L - 1.\n\nFor each user i = 1, 2, ... N, how many friend candidates does it have?\n\nConstraints\n\nAll values in input are integers.\n\n2 ≤ N ≤ 10^5\n\n0 \\leq M \\leq 10^5\n\n0 \\leq K \\leq 10^5\n\n1 \\leq A_i, B_i \\leq N\n\nA_i \\neq B_i\n\n1 \\leq C_i, D_i \\leq N\n\nC_i \\neq D_i\n\n(A_i, B_i) \\neq (A_j, B_j) (i \\neq j)\n\n(A_i, B_i) \\neq (B_j, A_j)\n\n(C_i, D_i) \\neq (C_j, D_j) (i \\neq j)\n\n(C_i, D_i) \\neq (D_j, C_j)\n\n(A_i, B_i) \\neq (C_j, D_j)\n\n(A_i, B_i) \\neq (D_j, C_j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M K\nA_1 B_1\n\\vdots\nA_M B_M\nC_1 D_1\n\\vdots\nC_K D_K\n\nOutput\n\nPrint the answers in order, with space in between.\n\nSample Input 1\n\n4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n\nSample Output 1\n\n0 1 0 1\n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there is no friendship or blockship between User 2 and 4. Thus, User 4 is a friend candidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has one friend candidate.\n\nSample Input 2\n\n5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5\n\nSample Output 2\n\n0 0 0 0 0\n\nEveryone is a friend of everyone else and has no friend candidate.\n\nSample Input 3\n\n10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1\n\nSample Output 3\n\n1 3 5 4 3 3 3 3 1 0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2540, "cpu_time_ms": 2124, "memory_kb": 477764}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s958912026", "group_id": "codeNet:p02762", "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(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;;;\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 dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (k (read))\n (dset (make-disjoint-set n))\n (as (make-array m :element-type 'uint32))\n (bs (make-array m :element-type 'uint32))\n (res (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (ds-unite! dset a b)\n (setf (aref as i) a\n (aref bs i) b)))\n (dotimes (i n)\n (setf (aref res i) (- (ds-size dset i) 1)))\n #>res\n (dotimes (i k)\n (let ((c (- (read-fixnum) 1))\n (d (- (read-fixnum) 1)))\n (when (ds-connected-p dset c d)\n (decf (aref res c))\n (decf (aref res d)))))\n (loop for a across as\n for b across bs\n when (ds-connected-p dset a b)\n do (decf (aref res a))\n (decf (aref res b)))\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 1\n2 1\n1 3\n3 2\n3 4\n4 1\n\"\n \"0 1 0 1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5\n\"\n \"0 0 0 0 0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1\n\"\n \"1 3 5 4 3 3 3 3 1 0\n\")))\n", "language": "Lisp", "metadata": {"date": 1583115533, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02762.html", "problem_id": "p02762", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02762/input.txt", "sample_output_relpath": "derived/input_output/data/p02762/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02762/Lisp/s958912026.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s958912026", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0 1 0 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 ;; 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(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;;;\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 dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (k (read))\n (dset (make-disjoint-set n))\n (as (make-array m :element-type 'uint32))\n (bs (make-array m :element-type 'uint32))\n (res (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i m)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (ds-unite! dset a b)\n (setf (aref as i) a\n (aref bs i) b)))\n (dotimes (i n)\n (setf (aref res i) (- (ds-size dset i) 1)))\n #>res\n (dotimes (i k)\n (let ((c (- (read-fixnum) 1))\n (d (- (read-fixnum) 1)))\n (when (ds-connected-p dset c d)\n (decf (aref res c))\n (decf (aref res d)))))\n (loop for a across as\n for b across bs\n when (ds-connected-p dset a b)\n do (decf (aref res a))\n (decf (aref res b)))\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 1\n2 1\n1 3\n3 2\n3 4\n4 1\n\"\n \"0 1 0 1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5\n\"\n \"0 0 0 0 0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1\n\"\n \"1 3 5 4 3 3 3 3 1 0\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nAn SNS has N users - User 1, User 2, \\cdots, User N.\n\nBetween these N users, there are some relationships - M friendships and K blockships.\n\nFor each i = 1, 2, \\cdots, M, there is a bidirectional friendship between User A_i and User B_i.\n\nFor each i = 1, 2, \\cdots, K, there is a bidirectional blockship between User C_i and User D_i.\n\nWe define User a to be a friend candidate for User b when all of the following four conditions are satisfied:\n\na \\neq b.\n\nThere is not a friendship between User a and User b.\n\nThere is not a blockship between User a and User b.\n\nThere exists a sequence c_0, c_1, c_2, \\cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \\cdots, L - 1.\n\nFor each user i = 1, 2, ... N, how many friend candidates does it have?\n\nConstraints\n\nAll values in input are integers.\n\n2 ≤ N ≤ 10^5\n\n0 \\leq M \\leq 10^5\n\n0 \\leq K \\leq 10^5\n\n1 \\leq A_i, B_i \\leq N\n\nA_i \\neq B_i\n\n1 \\leq C_i, D_i \\leq N\n\nC_i \\neq D_i\n\n(A_i, B_i) \\neq (A_j, B_j) (i \\neq j)\n\n(A_i, B_i) \\neq (B_j, A_j)\n\n(C_i, D_i) \\neq (C_j, D_j) (i \\neq j)\n\n(C_i, D_i) \\neq (D_j, C_j)\n\n(A_i, B_i) \\neq (C_j, D_j)\n\n(A_i, B_i) \\neq (D_j, C_j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M K\nA_1 B_1\n\\vdots\nA_M B_M\nC_1 D_1\n\\vdots\nC_K D_K\n\nOutput\n\nPrint the answers in order, with space in between.\n\nSample Input 1\n\n4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n\nSample Output 1\n\n0 1 0 1\n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there is no friendship or blockship between User 2 and 4. Thus, User 4 is a friend candidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has one friend candidate.\n\nSample Input 2\n\n5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5\n\nSample Output 2\n\n0 0 0 0 0\n\nEveryone is a friend of everyone else and has no friend candidate.\n\nSample Input 3\n\n10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1\n\nSample Output 3\n\n1 3 5 4 3 3 3 3 1 0", "sample_input": "4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n"}, "reference_outputs": ["0 1 0 1\n"], "source_document_id": "p02762", "source_text": "Score : 400 points\n\nProblem Statement\n\nAn SNS has N users - User 1, User 2, \\cdots, User N.\n\nBetween these N users, there are some relationships - M friendships and K blockships.\n\nFor each i = 1, 2, \\cdots, M, there is a bidirectional friendship between User A_i and User B_i.\n\nFor each i = 1, 2, \\cdots, K, there is a bidirectional blockship between User C_i and User D_i.\n\nWe define User a to be a friend candidate for User b when all of the following four conditions are satisfied:\n\na \\neq b.\n\nThere is not a friendship between User a and User b.\n\nThere is not a blockship between User a and User b.\n\nThere exists a sequence c_0, c_1, c_2, \\cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \\cdots, L - 1.\n\nFor each user i = 1, 2, ... N, how many friend candidates does it have?\n\nConstraints\n\nAll values in input are integers.\n\n2 ≤ N ≤ 10^5\n\n0 \\leq M \\leq 10^5\n\n0 \\leq K \\leq 10^5\n\n1 \\leq A_i, B_i \\leq N\n\nA_i \\neq B_i\n\n1 \\leq C_i, D_i \\leq N\n\nC_i \\neq D_i\n\n(A_i, B_i) \\neq (A_j, B_j) (i \\neq j)\n\n(A_i, B_i) \\neq (B_j, A_j)\n\n(C_i, D_i) \\neq (C_j, D_j) (i \\neq j)\n\n(C_i, D_i) \\neq (D_j, C_j)\n\n(A_i, B_i) \\neq (C_j, D_j)\n\n(A_i, B_i) \\neq (D_j, C_j)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M K\nA_1 B_1\n\\vdots\nA_M B_M\nC_1 D_1\n\\vdots\nC_K D_K\n\nOutput\n\nPrint the answers in order, with space in between.\n\nSample Input 1\n\n4 4 1\n2 1\n1 3\n3 2\n3 4\n4 1\n\nSample Output 1\n\n0 1 0 1\n\nThere is a friendship between User 2 and 3, and between 3 and 4. Also, there is no friendship or blockship between User 2 and 4. Thus, User 4 is a friend candidate for User 2.\n\nHowever, neither User 1 or 3 is a friend candidate for User 2, so User 2 has one friend candidate.\n\nSample Input 2\n\n5 10 0\n1 2\n1 3\n1 4\n1 5\n3 2\n2 4\n2 5\n4 3\n5 3\n4 5\n\nSample Output 2\n\n0 0 0 0 0\n\nEveryone is a friend of everyone else and has no friend candidate.\n\nSample Input 3\n\n10 9 3\n10 1\n6 7\n8 2\n2 5\n8 4\n7 3\n10 9\n6 4\n5 8\n2 6\n7 5\n3 1\n\nSample Output 3\n\n1 3 5 4 3 3 3 3 1 0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7770, "cpu_time_ms": 244, "memory_kb": 33892}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s816983816", "group_id": "codeNet:p02764", "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 calc (n k xs ys cs)\n (when ))\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (k (read))\n (xs (make-array n :element-type 'double-float))\n (ys (make-array n :element-type 'double-float))\n (cs (make-array n :element-type 'double-float)))\n (declare (uint8 n k))\n (dotimes (i n)\n (setf (aref xs i) (float (read) 1d0)\n (aref ys i) (float (read) 1d0)\n (aref cs i) (float (read) 1d0)))\n (let ((tmp (make-array n :element-type 'double-float)))\n (declare ((simple-array double-float (*)) tmp))\n (labels ((calc (pivot-x pivot-y)\n (declare (double-float pivot-x pivot-y))\n (dotimes (i n)\n (let ((x (aref xs i))\n (y (aref ys i))\n (c (aref cs i)))\n (setf (aref tmp i)\n (* c (sqrt (+ (expt (- x pivot-x) 2)\n (expt (- y pivot-y) 2)))))))\n (setq tmp (sort tmp #'<))\n (aref tmp (- k 1)))\n (%%minimize (pivot-x pivot-y rad div)\n (declare (double-float pivot-x pivot-y rad)\n (uint32 div))\n (let ((delta (/ rad div))\n (res most-positive-double-float))\n (declare (double-float delta res))\n (loop for x from (- pivot-x rad) to (+ pivot-x rad) by delta\n do (loop for y from (- pivot-y rad) to (+ pivot-y rad) by delta\n do (minf res (calc x y))))\n res))\n (%minimize (x1 y1 x2 y2 rate div)\n (declare (double-float x1 y1 x2 y2 rate))\n (let* ((xmid (* 0.5d0 (+ x1 x2)))\n (ymid (* 0.5d0 (+ y1 y2)))\n (delta (* 0.5d0 (max (abs (* 0.5d0 (- xmid x1)))\n (abs (* 0.5d0 (- ymid y1)))))))\n (let* ((min00 (%%minimize (* 0.5d0 (+ x1 xmid))\n (* 0.5d0 (+ y1 ymid))\n (* 1.5d0 delta) div))\n (min01 (%%minimize (* 0.5d0 (+ xmid x2))\n (* 0.5d0 (+ y1 ymid))\n (* 1.5d0 delta) div))\n (min10 (%%minimize (* 0.5d0 (+ x1 xmid))\n (* 0.5d0 (+ ymid y2))\n (* 1.5d0 delta) div))\n (min11 (%%minimize (* 0.5d0 (+ xmid x2))\n (* 0.5d0 (+ ymid y2))\n (* 1.5d0 delta) div))\n (min (min min00 min01 min10 min11))\n (d (* rate delta)))\n (cond ((< delta 1d-10) min)\n ((= min min00) (%minimize (- x1 d) (- y1 d) (+ xmid d) (+ ymid d) rate div))\n ((= min min01) (%minimize (- xmid d) (- y1 d) (+ x2 d) (+ ymid d) rate div))\n ((= min min10) (%minimize (- x1 d) (- ymid d) (+ xmid d) (+ y2 d) rate div))\n ((= min min11) (%minimize (- xmid d) (- ymid d) (+ x2 d) (+ y2 d) rate div))\n (t (error \"Huh?\")))))))\n (println (min (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.75d0 20)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.5d0 10)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.25d0 10)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.35d0 10)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.1d0 10)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.6d0 10)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.8d0 10)))))))\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\n-1 0 3\n0 0 3\n1 0 2\n1 1 40\n\"\n \"2.4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 5\n-879 981 26\n890 -406 81\n512 859 97\n362 -955 25\n128 553 17\n-885 763 2\n449 310 57\n-656 -204 11\n-270 76 40\n184 170 16\n\"\n \"7411.2252\n\")))\n", "language": "Lisp", "metadata": {"date": 1583121078, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02764.html", "problem_id": "p02764", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02764/input.txt", "sample_output_relpath": "derived/input_output/data/p02764/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02764/Lisp/s816983816.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s816983816", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2.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(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 calc (n k xs ys cs)\n (when ))\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (k (read))\n (xs (make-array n :element-type 'double-float))\n (ys (make-array n :element-type 'double-float))\n (cs (make-array n :element-type 'double-float)))\n (declare (uint8 n k))\n (dotimes (i n)\n (setf (aref xs i) (float (read) 1d0)\n (aref ys i) (float (read) 1d0)\n (aref cs i) (float (read) 1d0)))\n (let ((tmp (make-array n :element-type 'double-float)))\n (declare ((simple-array double-float (*)) tmp))\n (labels ((calc (pivot-x pivot-y)\n (declare (double-float pivot-x pivot-y))\n (dotimes (i n)\n (let ((x (aref xs i))\n (y (aref ys i))\n (c (aref cs i)))\n (setf (aref tmp i)\n (* c (sqrt (+ (expt (- x pivot-x) 2)\n (expt (- y pivot-y) 2)))))))\n (setq tmp (sort tmp #'<))\n (aref tmp (- k 1)))\n (%%minimize (pivot-x pivot-y rad div)\n (declare (double-float pivot-x pivot-y rad)\n (uint32 div))\n (let ((delta (/ rad div))\n (res most-positive-double-float))\n (declare (double-float delta res))\n (loop for x from (- pivot-x rad) to (+ pivot-x rad) by delta\n do (loop for y from (- pivot-y rad) to (+ pivot-y rad) by delta\n do (minf res (calc x y))))\n res))\n (%minimize (x1 y1 x2 y2 rate div)\n (declare (double-float x1 y1 x2 y2 rate))\n (let* ((xmid (* 0.5d0 (+ x1 x2)))\n (ymid (* 0.5d0 (+ y1 y2)))\n (delta (* 0.5d0 (max (abs (* 0.5d0 (- xmid x1)))\n (abs (* 0.5d0 (- ymid y1)))))))\n (let* ((min00 (%%minimize (* 0.5d0 (+ x1 xmid))\n (* 0.5d0 (+ y1 ymid))\n (* 1.5d0 delta) div))\n (min01 (%%minimize (* 0.5d0 (+ xmid x2))\n (* 0.5d0 (+ y1 ymid))\n (* 1.5d0 delta) div))\n (min10 (%%minimize (* 0.5d0 (+ x1 xmid))\n (* 0.5d0 (+ ymid y2))\n (* 1.5d0 delta) div))\n (min11 (%%minimize (* 0.5d0 (+ xmid x2))\n (* 0.5d0 (+ ymid y2))\n (* 1.5d0 delta) div))\n (min (min min00 min01 min10 min11))\n (d (* rate delta)))\n (cond ((< delta 1d-10) min)\n ((= min min00) (%minimize (- x1 d) (- y1 d) (+ xmid d) (+ ymid d) rate div))\n ((= min min01) (%minimize (- xmid d) (- y1 d) (+ x2 d) (+ ymid d) rate div))\n ((= min min10) (%minimize (- x1 d) (- ymid d) (+ xmid d) (+ y2 d) rate div))\n ((= min min11) (%minimize (- xmid d) (- ymid d) (+ x2 d) (+ y2 d) rate div))\n (t (error \"Huh?\")))))))\n (println (min (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.75d0 20)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.5d0 10)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.25d0 10)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.35d0 10)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.1d0 10)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.6d0 10)\n (%minimize -1101.1d0 -1050.9d0 1040.3d0 1031.6d0 0.8d0 10)))))))\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\n-1 0 3\n0 0 3\n1 0 2\n1 1 40\n\"\n \"2.4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 5\n-879 981 26\n890 -406 81\n512 859 97\n362 -955 25\n128 553 17\n-885 763 2\n449 310 57\n-656 -204 11\n-270 76 40\n184 170 16\n\"\n \"7411.2252\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nTakahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \\left(x_i, y_i\\right), and its hardness is c_i.\n\nTakahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \\left(X, Y\\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \\times \\sqrt{\\left(X - x_i\\right)^2 + \\left(Y-y_i\\right)^2} seconds.\n\nTakahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 60\n\n1 \\leq K \\leq N\n\n-1000 \\leq x_i , y_i \\leq 1000\n\n\\left(x_i, y_i\\right) \\neq \\left(x_j, y_j\\right) \\left(i \\neq j \\right)\n\n1 \\leq c_i \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nx_1 y_1 c_1\n\\vdots\nx_N y_N c_N\n\nOutput\n\nPrint the answer.\n\nIt will be considered correct if its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n4 3\n-1 0 3\n0 0 3\n1 0 2\n1 1 40\n\nSample Output 1\n\n2.4\n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd pieces of meat will be ready to eat within 2.4 seconds. This is the optimal place to put the heat source.\n\nSample Input 2\n\n10 5\n-879 981 26\n890 -406 81\n512 859 97\n362 -955 25\n128 553 17\n-885 763 2\n449 310 57\n-656 -204 11\n-270 76 40\n184 170 16\n\nSample Output 2\n\n7411.2252", "sample_input": "4 3\n-1 0 3\n0 0 3\n1 0 2\n1 1 40\n"}, "reference_outputs": ["2.4\n"], "source_document_id": "p02764", "source_text": "Score : 600 points\n\nProblem Statement\n\nTakahashi wants to grill N pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the i-th piece of meat are \\left(x_i, y_i\\right), and its hardness is c_i.\n\nTakahashi can use one heat source to grill the meat. If he puts the heat source at coordinates \\left(X, Y\\right), where X and Y are real numbers, the i-th piece of meat will be ready to eat in c_i \\times \\sqrt{\\left(X - x_i\\right)^2 + \\left(Y-y_i\\right)^2} seconds.\n\nTakahashi wants to eat K pieces of meat. Find the time required to have K or more pieces of meat ready if he put the heat source to minimize this time.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 60\n\n1 \\leq K \\leq N\n\n-1000 \\leq x_i , y_i \\leq 1000\n\n\\left(x_i, y_i\\right) \\neq \\left(x_j, y_j\\right) \\left(i \\neq j \\right)\n\n1 \\leq c_i \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nx_1 y_1 c_1\n\\vdots\nx_N y_N c_N\n\nOutput\n\nPrint the answer.\n\nIt will be considered correct if its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n4 3\n-1 0 3\n0 0 3\n1 0 2\n1 1 40\n\nSample Output 1\n\n2.4\n\nIf we put the heat source at \\left(-0.2, 0\\right), the 1-st, 2-nd, and 3-rd pieces of meat will be ready to eat within 2.4 seconds. This is the optimal place to put the heat source.\n\nSample Input 2\n\n10 5\n-879 981 26\n890 -406 81\n512 859 97\n362 -955 25\n128 553 17\n-885 763 2\n449 310 57\n-656 -204 11\n-270 76 40\n184 170 16\n\nSample Output 2\n\n7411.2252", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7915, "cpu_time_ms": 1837, "memory_kb": 37344}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s912951480", "group_id": "codeNet:p02765", "input_text": "(defun app (n r)\n (if (>= n 10)\n (format t \"~D~%\" r)\n (format t \"~D~%\" (+ r (* 100 (- 10 n))))\n ))\n(app (read) (read))", "language": "Lisp", "metadata": {"date": 1592758584, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02765.html", "problem_id": "p02765", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02765/input.txt", "sample_output_relpath": "derived/input_output/data/p02765/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02765/Lisp/s912951480.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s912951480", "user_id": "u136500538"}, "prompt_components": {"gold_output": "3719\n", "input_to_evaluate": "(defun app (n r)\n (if (>= n 10)\n (format t \"~D~%\" r)\n (format t \"~D~%\" (+ r (* 100 (- 10 n))))\n ))\n(app (read) (read))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi is a member of a programming competition site, ButCoder.\n\nEach member of ButCoder is assigned two values: Inner Rating and Displayed Rating.\n\nThe Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests. Otherwise, the Displayed Rating will be their Inner Rating minus 100 \\times (10 - K) when the member has participated in K contests.\n\nTakahashi has participated in N contests, and his Displayed Rating is R. Find his Inner Rating.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n0 \\leq R \\leq 4111\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN R\n\nOutput\n\nPrint his Inner Rating.\n\nSample Input 1\n\n2 2919\n\nSample Output 1\n\n3719\n\nTakahashi has participated in 2 contests, which is less than 10, so his Displayed Rating is his Inner Rating minus 100 \\times (10 - 2) = 800.\n\nThus, Takahashi's Inner Rating is 2919 + 800 = 3719.\n\nSample Input 2\n\n22 3051\n\nSample Output 2\n\n3051", "sample_input": "2 2919\n"}, "reference_outputs": ["3719\n"], "source_document_id": "p02765", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi is a member of a programming competition site, ButCoder.\n\nEach member of ButCoder is assigned two values: Inner Rating and Displayed Rating.\n\nThe Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests. Otherwise, the Displayed Rating will be their Inner Rating minus 100 \\times (10 - K) when the member has participated in K contests.\n\nTakahashi has participated in N contests, and his Displayed Rating is R. Find his Inner Rating.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n0 \\leq R \\leq 4111\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN R\n\nOutput\n\nPrint his Inner Rating.\n\nSample Input 1\n\n2 2919\n\nSample Output 1\n\n3719\n\nTakahashi has participated in 2 contests, which is less than 10, so his Displayed Rating is his Inner Rating minus 100 \\times (10 - 2) = 800.\n\nThus, Takahashi's Inner Rating is 2919 + 800 = 3719.\n\nSample Input 2\n\n22 3051\n\nSample Output 2\n\n3051", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 24344}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s304767651", "group_id": "codeNet:p02765", "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": 1588452572, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02765.html", "problem_id": "p02765", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02765/input.txt", "sample_output_relpath": "derived/input_output/data/p02765/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02765/Lisp/s304767651.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s304767651", "user_id": "u425762225"}, "prompt_components": {"gold_output": "3719\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 : 100 points\n\nProblem Statement\n\nTakahashi is a member of a programming competition site, ButCoder.\n\nEach member of ButCoder is assigned two values: Inner Rating and Displayed Rating.\n\nThe Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests. Otherwise, the Displayed Rating will be their Inner Rating minus 100 \\times (10 - K) when the member has participated in K contests.\n\nTakahashi has participated in N contests, and his Displayed Rating is R. Find his Inner Rating.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n0 \\leq R \\leq 4111\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN R\n\nOutput\n\nPrint his Inner Rating.\n\nSample Input 1\n\n2 2919\n\nSample Output 1\n\n3719\n\nTakahashi has participated in 2 contests, which is less than 10, so his Displayed Rating is his Inner Rating minus 100 \\times (10 - 2) = 800.\n\nThus, Takahashi's Inner Rating is 2919 + 800 = 3719.\n\nSample Input 2\n\n22 3051\n\nSample Output 2\n\n3051", "sample_input": "2 2919\n"}, "reference_outputs": ["3719\n"], "source_document_id": "p02765", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi is a member of a programming competition site, ButCoder.\n\nEach member of ButCoder is assigned two values: Inner Rating and Displayed Rating.\n\nThe Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests. Otherwise, the Displayed Rating will be their Inner Rating minus 100 \\times (10 - K) when the member has participated in K contests.\n\nTakahashi has participated in N contests, and his Displayed Rating is R. Find his Inner Rating.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 100\n\n0 \\leq R \\leq 4111\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN R\n\nOutput\n\nPrint his Inner Rating.\n\nSample Input 1\n\n2 2919\n\nSample Output 1\n\n3719\n\nTakahashi has participated in 2 contests, which is less than 10, so his Displayed Rating is his Inner Rating minus 100 \\times (10 - 2) = 800.\n\nThus, Takahashi's Inner Rating is 2919 + 800 = 3719.\n\nSample Input 2\n\n22 3051\n\nSample Output 2\n\n3051", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 116, "memory_kb": 13412}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s075215945", "group_id": "codeNet:p02766", "input_text": "(defun solve(N K &optional (l 1) (K^l K) )\n (if (< N K^l) l\n (solve N K (1+ l) (* K^l K))))\n\n(princ (solve (read) (read)))", "language": "Lisp", "metadata": {"date": 1584311836, "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/s075215945.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s075215945", "user_id": "u289580381"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun solve(N K &optional (l 1) (K^l K) )\n (if (< N K^l) l\n (solve N K (1+ l) (* K^l K))))\n\n(princ (solve (read) (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 126, "cpu_time_ms": 14, "memory_kb": 3684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s827155742", "group_id": "codeNet:p02768", "input_text": ";; D - Bouquet\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n\n(defun solve (n a b)\n \"(n 1) + (n 2) + ... + (n n) (= 2 ** n - 1) - (n a) - (n b)\"\n (mod+ (modulo-expt 2 n) -1\n (- (choose n a))\n (- (choose n b))))\n\n(defun main ()\n (let ((n (read))\n (a (read))\n (b (read)))\n (princ (solve n a b))))\n\n;; modulo addition/product/division\n\n(defun mod+ (&rest rest)\n (mod (apply #'+ rest) *modulus*))\n\n(defun mod* (&rest rest)\n (mod (apply #'* rest) *modulus*))\n\n(defun mod/ (num &rest denom)\n (apply #'mod* (cons num (mapcar #'mod-inverse denom))))\n\n(defun bit-sequence (v)\n \"(bit-sequence 13) => (1 1 0 1)\"\n (nreverse\n (loop for x = v then (ash x -1) while (plusp x)\n collect (logand x 1))))\n\n(let ((modulus-2-bits (bit-sequence (- *modulus* 2))))\n ; Mが素数のとき,a^(M-2) ≡ a^(-1) mod M (フェルマーの小定理より)\n (defun mod-inverse (a) (mod-expt-bit-seq a modulus-2-bits)))\n\n(defun modulo-expt (a n) (mod-expt-bit-seq a (bit-sequence n)))\n\n(defun mod-expt-bit-seq (a bit-seq)\n (loop for b in bit-seq\n for e = a then (mod* e e (if (zerop b) 1 a))\n finally (return e)))\n\n(defun choose (n k)\n (labels ((choose-r (n k acc)\n (if (zerop k) acc\n (choose-r (1- n) (1- k) (mod* acc (mod/ n k))))))\n (if (or (< n k) (minusp k)) 0\n (choose-r n k 1))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1584871475, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02768.html", "problem_id": "p02768", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02768/input.txt", "sample_output_relpath": "derived/input_output/data/p02768/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02768/Lisp/s827155742.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s827155742", "user_id": "u227020436"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": ";; D - Bouquet\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n\n(defun solve (n a b)\n \"(n 1) + (n 2) + ... + (n n) (= 2 ** n - 1) - (n a) - (n b)\"\n (mod+ (modulo-expt 2 n) -1\n (- (choose n a))\n (- (choose n b))))\n\n(defun main ()\n (let ((n (read))\n (a (read))\n (b (read)))\n (princ (solve n a b))))\n\n;; modulo addition/product/division\n\n(defun mod+ (&rest rest)\n (mod (apply #'+ rest) *modulus*))\n\n(defun mod* (&rest rest)\n (mod (apply #'* rest) *modulus*))\n\n(defun mod/ (num &rest denom)\n (apply #'mod* (cons num (mapcar #'mod-inverse denom))))\n\n(defun bit-sequence (v)\n \"(bit-sequence 13) => (1 1 0 1)\"\n (nreverse\n (loop for x = v then (ash x -1) while (plusp x)\n collect (logand x 1))))\n\n(let ((modulus-2-bits (bit-sequence (- *modulus* 2))))\n ; Mが素数のとき,a^(M-2) ≡ a^(-1) mod M (フェルマーの小定理より)\n (defun mod-inverse (a) (mod-expt-bit-seq a modulus-2-bits)))\n\n(defun modulo-expt (a n) (mod-expt-bit-seq a (bit-sequence n)))\n\n(defun mod-expt-bit-seq (a bit-seq)\n (loop for b in bit-seq\n for e = a then (mod* e e (if (zerop b) 1 a))\n finally (return e)))\n\n(defun choose (n k)\n (labels ((choose-r (n k acc)\n (if (zerop k) acc\n (choose-r (1- n) (1- k) (mod* acc (mod/ n k))))))\n (if (or (< n k) (minusp k)) 0\n (choose-r n k 1))))\n\n(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nAkari has n kinds of flowers, one of each kind.\n\nShe is going to choose one or more of these flowers to make a bouquet.\n\nHowever, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.\n\nHow many different bouquets are there that Akari can make?\n\nFind the count modulo (10^9 + 7).\n\nHere, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq n \\leq 10^9\n\n1 \\leq a < b \\leq \\textrm{min}(n, 2 \\times 10^5)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn a b\n\nOutput\n\nPrint the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)\n\nSample Input 1\n\n4 1 3\n\nSample Output 1\n\n7\n\nIn this case, Akari can choose 2 or 4 flowers to make the bouquet.\n\nThere are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.\n\nSample Input 2\n\n1000000000 141421 173205\n\nSample Output 2\n\n34076506\n\nPrint the count modulo (10^9 + 7).", "sample_input": "4 1 3\n"}, "reference_outputs": ["7\n"], "source_document_id": "p02768", "source_text": "Score : 400 points\n\nProblem Statement\n\nAkari has n kinds of flowers, one of each kind.\n\nShe is going to choose one or more of these flowers to make a bouquet.\n\nHowever, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.\n\nHow many different bouquets are there that Akari can make?\n\nFind the count modulo (10^9 + 7).\n\nHere, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq n \\leq 10^9\n\n1 \\leq a < b \\leq \\textrm{min}(n, 2 \\times 10^5)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn a b\n\nOutput\n\nPrint the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)\n\nSample Input 1\n\n4 1 3\n\nSample Output 1\n\n7\n\nIn this case, Akari can choose 2 or 4 flowers to make the bouquet.\n\nThere are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.\n\nSample Input 2\n\n1000000000 141421 173205\n\nSample Output 2\n\n34076506\n\nPrint the count modulo (10^9 + 7).", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 1090, "memory_kb": 57832}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s436411502", "group_id": "codeNet:p02768", "input_text": "(defun expt-10-9 (base n)\n (let* ((arr (make-array 100 :element-type 'fixnum :initial-element 0))\n (a (format nil \"~b\" n)))\n (labels ((expt-f (k)\n (if (= k 1)\n base\n (setf (aref arr (floor (log k 2)))\n (mod (expt (expt-f (/ k 2)) 2) 1000000007))))\n (10-9-* (x y) (mod (* x y) 1000000007)))\n (setf (aref arr 0) base)\n (expt-f (expt 2 (1+ (length a))))\n (mod (reduce #'10-9-* (map 'list (lambda (x y) (if (char= x #\\0) 1 y)) (reverse a) arr)) 1000000007))))\n\n(defun !-10-9 (n a ans)\n (if (= n (1- a))\n ans\n (!-10-9 (1- n) a (mod (* n ans) 1000000007))))\n\n(defun c (n a)\n (* (!-10-9 n (- n a -1) 1) (expt-10-9 (!-10-9 a 1 1) 1000000005)))\n\n(let* ((n (read))\n (a (read))\n (b (read)))\n (princ (mod (- (expt-10-9 2 n) 1 (c n a) (c n b)) 1000000007)))\n", "language": "Lisp", "metadata": {"date": 1582518623, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02768.html", "problem_id": "p02768", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02768/input.txt", "sample_output_relpath": "derived/input_output/data/p02768/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02768/Lisp/s436411502.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s436411502", "user_id": "u610490393"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(defun expt-10-9 (base n)\n (let* ((arr (make-array 100 :element-type 'fixnum :initial-element 0))\n (a (format nil \"~b\" n)))\n (labels ((expt-f (k)\n (if (= k 1)\n base\n (setf (aref arr (floor (log k 2)))\n (mod (expt (expt-f (/ k 2)) 2) 1000000007))))\n (10-9-* (x y) (mod (* x y) 1000000007)))\n (setf (aref arr 0) base)\n (expt-f (expt 2 (1+ (length a))))\n (mod (reduce #'10-9-* (map 'list (lambda (x y) (if (char= x #\\0) 1 y)) (reverse a) arr)) 1000000007))))\n\n(defun !-10-9 (n a ans)\n (if (= n (1- a))\n ans\n (!-10-9 (1- n) a (mod (* n ans) 1000000007))))\n\n(defun c (n a)\n (* (!-10-9 n (- n a -1) 1) (expt-10-9 (!-10-9 a 1 1) 1000000005)))\n\n(let* ((n (read))\n (a (read))\n (b (read)))\n (princ (mod (- (expt-10-9 2 n) 1 (c n a) (c n b)) 1000000007)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nAkari has n kinds of flowers, one of each kind.\n\nShe is going to choose one or more of these flowers to make a bouquet.\n\nHowever, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.\n\nHow many different bouquets are there that Akari can make?\n\nFind the count modulo (10^9 + 7).\n\nHere, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq n \\leq 10^9\n\n1 \\leq a < b \\leq \\textrm{min}(n, 2 \\times 10^5)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn a b\n\nOutput\n\nPrint the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)\n\nSample Input 1\n\n4 1 3\n\nSample Output 1\n\n7\n\nIn this case, Akari can choose 2 or 4 flowers to make the bouquet.\n\nThere are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.\n\nSample Input 2\n\n1000000000 141421 173205\n\nSample Output 2\n\n34076506\n\nPrint the count modulo (10^9 + 7).", "sample_input": "4 1 3\n"}, "reference_outputs": ["7\n"], "source_document_id": "p02768", "source_text": "Score : 400 points\n\nProblem Statement\n\nAkari has n kinds of flowers, one of each kind.\n\nShe is going to choose one or more of these flowers to make a bouquet.\n\nHowever, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.\n\nHow many different bouquets are there that Akari can make?\n\nFind the count modulo (10^9 + 7).\n\nHere, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq n \\leq 10^9\n\n1 \\leq a < b \\leq \\textrm{min}(n, 2 \\times 10^5)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn a b\n\nOutput\n\nPrint the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)\n\nSample Input 1\n\n4 1 3\n\nSample Output 1\n\n7\n\nIn this case, Akari can choose 2 or 4 flowers to make the bouquet.\n\nThere are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.\n\nSample Input 2\n\n1000000000 141421 173205\n\nSample Output 2\n\n34076506\n\nPrint the count modulo (10^9 + 7).", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 877, "cpu_time_ms": 176, "memory_kb": 20196}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s644320405", "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(defparameter *factorial-inv-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\n(defun factorial-inv (x)\n (let ((res (aref *factorial-inv-dp* x)))\n (if res\n res\n (setf (aref *factorial-inv-dp* x) (modinv (factorial x))))))\n\n\n(defun modinv (x)\n (modpow x (- *mod* 2)))\n\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-inv b) (factorial-inv (- a b))))\n\n\n(factorial-inv 400000)\n(loop for i downfrom 400000 to 1\n do\n (setf (aref *factorial-inv-dp* (1- i))\n (mod* (aref *factorial-inv-dp* i) i)))\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": 1582406698, "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/s644320405.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s644320405", "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(defparameter *factorial-inv-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\n(defun factorial-inv (x)\n (let ((res (aref *factorial-inv-dp* x)))\n (if res\n res\n (setf (aref *factorial-inv-dp* x) (modinv (factorial x))))))\n\n\n(defun modinv (x)\n (modpow x (- *mod* 2)))\n\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-inv b) (factorial-inv (- a b))))\n\n\n(factorial-inv 400000)\n(loop for i downfrom 400000 to 1\n do\n (setf (aref *factorial-inv-dp* (1- i))\n (mod* (aref *factorial-inv-dp* i) i)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2205, "cpu_time_ms": 254, "memory_kb": 72884}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s270397587", "group_id": "codeNet:p02769", "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+ 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (k (read))\n (res 0))\n (setq k (min n k))\n (loop for x from 0 to k\n do (incfmod res (mod* (binom n x) (binom (- n 1) 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 \"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 \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"200000 1000000000\n\"\n \"607923868\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15 6\n\"\n \"22583772\n\")))\n", "language": "Lisp", "metadata": {"date": 1582403218, "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/s270397587.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s270397587", "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 ;; 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+ 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (k (read))\n (res 0))\n (setq k (min n k))\n (loop for x from 0 to k\n do (incfmod res (mod* (binom n x) (binom (- n 1) 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 \"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 \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"200000 1000000000\n\"\n \"607923868\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15 6\n\"\n \"22583772\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7496, "cpu_time_ms": 160, "memory_kb": 29536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s756821448", "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\n(main)\n", "language": "Lisp", "metadata": {"date": 1600651809, "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/s756821448.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s756821448", "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\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 22, "memory_kb": 23528}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s795196048", "group_id": "codeNet:p02771", "input_text": "(defun app ()\n (let ((a (read))\n (b (read))\n (c (read))\n (ans \"No\"))\n (if (equal a b)\n (if (not (equal b c))\n (setq ans \"Yes\"))\n (progn (if (equal b c)\n (setq ans \"Yes\"))\n (if (equal a c)\n (setq ans \"Yes\")))\n )\n (format t \"~A~%\" ans)\n )\n)\n(app)", "language": "Lisp", "metadata": {"date": 1592765353, "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/s795196048.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s795196048", "user_id": "u136500538"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun app ()\n (let ((a (read))\n (b (read))\n (c (read))\n (ans \"No\"))\n (if (equal a b)\n (if (not (equal b c))\n (setq ans \"Yes\"))\n (progn (if (equal b c)\n (setq ans \"Yes\"))\n (if (equal a c)\n (setq ans \"Yes\")))\n )\n (format t \"~A~%\" ans)\n )\n)\n(app)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 23572}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s519534403", "group_id": "codeNet:p02771", "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* ((abc (list (read) (read) (read))))\n (setq abc (sort abc #'<))\n (write-line (if (or (and (= (first abc) (second abc))\n (< (second abc) (third abc)))\n (and (< (first abc) (second abc))\n (= (second abc) (third abc))))\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 \"5 7 5\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4 4\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 9 6\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3 4\n\"\n \"Yes\n\")))\n", "language": "Lisp", "metadata": {"date": 1581883306, "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/s519534403.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s519534403", "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 ;; 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* ((abc (list (read) (read) (read))))\n (setq abc (sort abc #'<))\n (write-line (if (or (and (= (first abc) (second abc))\n (< (second abc) (third abc)))\n (and (< (first abc) (second abc))\n (= (second abc) (third abc))))\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 \"5 7 5\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4 4\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 9 6\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3 4\n\"\n \"Yes\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4045, "cpu_time_ms": 130, "memory_kb": 14436}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s276661776", "group_id": "codeNet:p02772", "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 (dotimes (_ n)\n (let ((a (read)))\n (when (and (evenp a)\n (not (zerop (mod a 3)))\n (not (zerop (mod a 5))))\n (write-line \"DENIED\")\n (return-from main))))\n (write-line \"APPROVED\")))\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\n6 7 9 10 31\n\"\n \"APPROVED\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n28 27 24\n\"\n \"DENIED\n\")))\n", "language": "Lisp", "metadata": {"date": 1581883445, "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/s276661776.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s276661776", "user_id": "u352600849"}, "prompt_components": {"gold_output": "APPROVED\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 (dotimes (_ n)\n (let ((a (read)))\n (when (and (evenp a)\n (not (zerop (mod a 3)))\n (not (zerop (mod a 5))))\n (write-line \"DENIED\")\n (return-from main))))\n (write-line \"APPROVED\")))\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\n6 7 9 10 31\n\"\n \"APPROVED\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n28 27 24\n\"\n \"DENIED\n\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3830, "cpu_time_ms": 181, "memory_kb": 16736}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s119419559", "group_id": "codeNet:p02773", "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 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(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(declaim (inline string16=))\n(defun string16= (s1 s2)\n (declare #.OPT\n ((simple-base-string 16) s1 s2))\n (and (= (sb-kernel:%vector-raw-bits s1 0) (sb-kernel:%vector-raw-bits s2 0))\n (= (sb-kernel:%vector-raw-bits s1 1) (sb-kernel:%vector-raw-bits s2 1))))\n \n(declaim (inline write-line*))\n(defun write-line* (s)\n (declare ((simple-base-string 16) s))\n (loop for i from 7 downto 0\n when (char= (aref s i) #\\Nul)\n do (return)\n do (write-char (aref s i))\n finally (loop for i from 15 downto 8\n until (char= (aref s i) #\\Nul)\n do (write-char (aref s i))))\n (terpri))\n\n(declaim (inline string16<))\n(defun string16< (s1 s2)\n (declare (simple-base-string s1 s2))\n (or (< (sb-kernel:%vector-raw-bits s1 0) (sb-kernel:%vector-raw-bits s2 0))\n (and (= (sb-kernel:%vector-raw-bits s1 0) (sb-kernel:%vector-raw-bits s2 0))\n (< (sb-kernel:%vector-raw-bits s1 1) (sb-kernel:%vector-raw-bits s2 1)))))\n\n(declaim (inline %median3))\n(defun %median3 (x y z)\n (if (string16< x y)\n (if (string16< y z)\n y\n (if (string16< z x)\n x\n z))\n (if (string16< z y)\n y\n (if (string16< x z)\n x\n z))))\n\n(defun quicksort! (vector)\n (declare #.OPT\n ((simple-array t (*)) 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 (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (string16< (aref vector l) pivot)\n do (incf l))\n (loop while (string16< 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 0 (- (length vector) 1))\n vector))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ss (make-array n :element-type 'simple-base-string))\n (dp (make-array n :element-type 'uint31 :initial-element 1))\n (max 1))\n (declare (uint62 n max))\n (dotimes (i n)\n (let ((s (make-string 16 :element-type 'base-char :initial-element #\\Nul)))\n (loop for j from 7 downto 0\n for c = (read-schar)\n when (char= c #\\Newline)\n do (return)\n do (setf (aref s j) c)\n finally (loop for j from 15 downto 8\n for c = (read-schar)\n until (char= c #\\Newline)\n do (setf (aref s j) c)))\n (setf (aref ss i) s)))\n (quicksort! ss)\n (setf (aref dp 0) 1)\n (dotimes (i (- n 1))\n (when (string16= (aref ss i) (aref ss (+ i 1)))\n (setf (aref dp (+ i 1)) (+ 1 (aref dp i))))\n (maxf max (aref dp (+ i 1))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (i n)\n (when (= max (aref dp i))\n (write-line* (aref ss 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 #+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~%\")\n (dotimes (_ 200000)\n (let ((s (make-string 10)))\n (dotimes (i 10)\n (setf (aref s i) (code-char (+ 97 (random 26)))))\n (write-line s out)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; 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\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\"\n \"beet\nvet\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\"\n \"buffalo\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\"\n \"kick\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\nushi\ntapu\nnichia\nkun\n\"\n \"kun\nnichia\ntapu\nushi\n\")))\n", "language": "Lisp", "metadata": {"date": 1595667493, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s119419559.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s119419559", "user_id": "u352600849"}, "prompt_components": {"gold_output": "beet\nvet\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 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(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(declaim (inline string16=))\n(defun string16= (s1 s2)\n (declare #.OPT\n ((simple-base-string 16) s1 s2))\n (and (= (sb-kernel:%vector-raw-bits s1 0) (sb-kernel:%vector-raw-bits s2 0))\n (= (sb-kernel:%vector-raw-bits s1 1) (sb-kernel:%vector-raw-bits s2 1))))\n \n(declaim (inline write-line*))\n(defun write-line* (s)\n (declare ((simple-base-string 16) s))\n (loop for i from 7 downto 0\n when (char= (aref s i) #\\Nul)\n do (return)\n do (write-char (aref s i))\n finally (loop for i from 15 downto 8\n until (char= (aref s i) #\\Nul)\n do (write-char (aref s i))))\n (terpri))\n\n(declaim (inline string16<))\n(defun string16< (s1 s2)\n (declare (simple-base-string s1 s2))\n (or (< (sb-kernel:%vector-raw-bits s1 0) (sb-kernel:%vector-raw-bits s2 0))\n (and (= (sb-kernel:%vector-raw-bits s1 0) (sb-kernel:%vector-raw-bits s2 0))\n (< (sb-kernel:%vector-raw-bits s1 1) (sb-kernel:%vector-raw-bits s2 1)))))\n\n(declaim (inline %median3))\n(defun %median3 (x y z)\n (if (string16< x y)\n (if (string16< y z)\n y\n (if (string16< z x)\n x\n z))\n (if (string16< z y)\n y\n (if (string16< x z)\n x\n z))))\n\n(defun quicksort! (vector)\n (declare #.OPT\n ((simple-array t (*)) 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 (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (string16< (aref vector l) pivot)\n do (incf l))\n (loop while (string16< 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 0 (- (length vector) 1))\n vector))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (ss (make-array n :element-type 'simple-base-string))\n (dp (make-array n :element-type 'uint31 :initial-element 1))\n (max 1))\n (declare (uint62 n max))\n (dotimes (i n)\n (let ((s (make-string 16 :element-type 'base-char :initial-element #\\Nul)))\n (loop for j from 7 downto 0\n for c = (read-schar)\n when (char= c #\\Newline)\n do (return)\n do (setf (aref s j) c)\n finally (loop for j from 15 downto 8\n for c = (read-schar)\n until (char= c #\\Newline)\n do (setf (aref s j) c)))\n (setf (aref ss i) s)))\n (quicksort! ss)\n (setf (aref dp 0) 1)\n (dotimes (i (- n 1))\n (when (string16= (aref ss i) (aref ss (+ i 1)))\n (setf (aref dp (+ i 1)) (+ 1 (aref dp i))))\n (maxf max (aref dp (+ i 1))))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (dotimes (i n)\n (when (= max (aref dp i))\n (write-line* (aref ss 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 #+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~%\")\n (dotimes (_ 200000)\n (let ((s (make-string 10)))\n (dotimes (i 10)\n (setf (aref s i) (code-char (+ 97 (random 26)))))\n (write-line s out)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; 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\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\"\n \"beet\nvet\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\"\n \"buffalo\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\"\n \"kick\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\nushi\ntapu\nnichia\nkun\n\"\n \"kun\nnichia\ntapu\nushi\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7996, "cpu_time_ms": 110, "memory_kb": 39728}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s332417088", "group_id": "codeNet:p02773", "input_text": "(let ((n (read))\n (a 0)\n (ans '()))\n (defparameter *hash* (make-hash-table))\n (loop for i below n do\n (let ((s (read)))\n (if (eq Nil (gethash s *hash*))\n (setf (gethash s *hash*) 1)\n (incf (gethash s *hash*))\n )\n ;;一番多い文字列の個数\n (if (< a (gethash s *hash*))\n (setq a (gethash s *hash*))\n )\n )\n )\n\n (setq ans (loop for key being each hash-key of *hash*\n using (hash-value value) when (= value a) collect key\n ))\n (setf ans (sort ans #'string<))\n\n (dotimes (i (length ans))\n (format t \"~(~A~)~%\" (nth i ans))\n )\n)", "language": "Lisp", "metadata": {"date": 1595448285, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s332417088.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s332417088", "user_id": "u136500538"}, "prompt_components": {"gold_output": "beet\nvet\n", "input_to_evaluate": "(let ((n (read))\n (a 0)\n (ans '()))\n (defparameter *hash* (make-hash-table))\n (loop for i below n do\n (let ((s (read)))\n (if (eq Nil (gethash s *hash*))\n (setf (gethash s *hash*) 1)\n (incf (gethash s *hash*))\n )\n ;;一番多い文字列の個数\n (if (< a (gethash s *hash*))\n (setq a (gethash s *hash*))\n )\n )\n )\n\n (setq ans (loop for key being each hash-key of *hash*\n using (hash-value value) when (= value a) collect key\n ))\n (setf ans (sort ans #'string<))\n\n (dotimes (i (length ans))\n (format t \"~(~A~)~%\" (nth i ans))\n )\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 687, "cpu_time_ms": 2209, "memory_kb": 111976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s646535644", "group_id": "codeNet:p02773", "input_text": "(let* ((n (read))\n (lst (sort (loop :repeat n :collect (read-line)) #'string>))\n (ll (collector #'string= lst))\n (mx (reduce #'max (mapcar #'cdr ll)))\n (lk (remove-if-not (lambda (k) (= mx (cdr k))) ll)))\n (loop :for k :in lk :do(format t \"~A~%\" (car k))))", "language": "Lisp", "metadata": {"date": 1581885244, "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/s646535644.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s646535644", "user_id": "u610490393"}, "prompt_components": {"gold_output": "beet\nvet\n", "input_to_evaluate": "(let* ((n (read))\n (lst (sort (loop :repeat n :collect (read-line)) #'string>))\n (ll (collector #'string= lst))\n (mx (reduce #'max (mapcar #'cdr ll)))\n (lk (remove-if-not (lambda (k) (= mx (cdr k))) ll)))\n (loop :for k :in lk :do(format t \"~A~%\" (car k))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 281, "cpu_time_ms": 532, "memory_kb": 68072}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s143670684", "group_id": "codeNet:p02775", "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* ((input (read-line))\n (len (length input))\n (s (make-array (+ len 1) :element-type 'uint8))\n ;; 0: 繰り上げないで払う 1: 繰り上げて払う\n (dp (make-array (list (+ len 2) 2) :element-type 'uint62\n :initial-element most-positive-fixnum)))\n (declare (simple-string input))\n (loop for i below len\n for c across input\n for d = (- (char-code c) 48)\n do (setf (aref s (- len i 1)) d))\n (setf (aref dp 0 0) 0)\n (dotimes (x (+ len 1))\n (let ((d (aref s x)))\n ;; 繰り上げていない状態 -> 繰り上げていない状態\n (minf (aref dp (+ x 1) 0)\n (+ (aref dp x 0) d))\n ;; 繰り上げていない状態 -> 繰り上げた状態\n (minf (aref dp (+ x 1) 1)\n (+ (aref dp x 0) (- 10 d)))\n ;; 繰り上げた状態 -> 繰り上げていない状態\n (minf (aref dp (+ x 1) 0)\n (+ (aref dp x 1) d 1))\n ;; 繰り上げた状態 -> 繰り上げた状態\n (minf (aref dp (+ x 1) 1)\n (+ (aref dp x 1) (- 10 (+ d 1))))))\n (println (min (aref dp (+ len 1) 0)\n (aref dp (+ len 1) 1)))\n ;; #>s\n ;; (let ((carry nil)\n ;; (res 0))\n ;; (dotimes (i (length s))\n ;; (let ((d (aref s i)))\n ;; #>d\n ;; (when carry\n ;; (incf d)\n ;; (setq carry nil))\n ;; (ecase d\n ;; (0)\n ;; (1 (incf res 1))\n ;; (2 (incf res 2))\n ;; (3 (incf res 3))\n ;; (4 (incf res 4))\n ;; (5 (incf res 5))\n ;; (6 (incf res 4) (setq carry t))\n ;; (7 (incf res 3) (setq carry t))\n ;; (8 (incf res 2) (setq carry t))\n ;; (9 (incf res 1) (setq carry t))\n ;; (10 (setq carry t))))\n ;; #>res)\n ;; (println res))\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 \"36\n\"\n \"8\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"91\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170\n\"\n \"243\n\")))\n", "language": "Lisp", "metadata": {"date": 1581888213, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02775.html", "problem_id": "p02775", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02775/input.txt", "sample_output_relpath": "derived/input_output/data/p02775/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02775/Lisp/s143670684.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s143670684", "user_id": "u352600849"}, "prompt_components": {"gold_output": "8\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* ((input (read-line))\n (len (length input))\n (s (make-array (+ len 1) :element-type 'uint8))\n ;; 0: 繰り上げないで払う 1: 繰り上げて払う\n (dp (make-array (list (+ len 2) 2) :element-type 'uint62\n :initial-element most-positive-fixnum)))\n (declare (simple-string input))\n (loop for i below len\n for c across input\n for d = (- (char-code c) 48)\n do (setf (aref s (- len i 1)) d))\n (setf (aref dp 0 0) 0)\n (dotimes (x (+ len 1))\n (let ((d (aref s x)))\n ;; 繰り上げていない状態 -> 繰り上げていない状態\n (minf (aref dp (+ x 1) 0)\n (+ (aref dp x 0) d))\n ;; 繰り上げていない状態 -> 繰り上げた状態\n (minf (aref dp (+ x 1) 1)\n (+ (aref dp x 0) (- 10 d)))\n ;; 繰り上げた状態 -> 繰り上げていない状態\n (minf (aref dp (+ x 1) 0)\n (+ (aref dp x 1) d 1))\n ;; 繰り上げた状態 -> 繰り上げた状態\n (minf (aref dp (+ x 1) 1)\n (+ (aref dp x 1) (- 10 (+ d 1))))))\n (println (min (aref dp (+ len 1) 0)\n (aref dp (+ len 1) 1)))\n ;; #>s\n ;; (let ((carry nil)\n ;; (res 0))\n ;; (dotimes (i (length s))\n ;; (let ((d (aref s i)))\n ;; #>d\n ;; (when carry\n ;; (incf d)\n ;; (setq carry nil))\n ;; (ecase d\n ;; (0)\n ;; (1 (incf res 1))\n ;; (2 (incf res 2))\n ;; (3 (incf res 3))\n ;; (4 (incf res 4))\n ;; (5 (incf res 5))\n ;; (6 (incf res 4) (setq carry t))\n ;; (7 (incf res 3) (setq carry t))\n ;; (8 (incf res 2) (setq carry t))\n ;; (9 (incf res 1) (setq carry t))\n ;; (10 (setq carry t))))\n ;; #>res)\n ;; (println res))\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 \"36\n\"\n \"8\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"91\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170\n\"\n \"243\n\")))\n", "problem_context": "Score: 500 points\n\nProblem Statement\n\nIn the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \\dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. (Takoyaki is the name of a Japanese snack.)\n\nTo make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.\n\nWhat will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?\n\nAssume that you have sufficient numbers of banknotes, and so does the clerk.\n\nConstraints\n\nN is an integer between 1 and 10^{1,000,000} (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum possible number of total banknotes used by you and the clerk.\n\nSample Input 1\n\n36\n\nSample Output 1\n\n8\n\nIf you give four banknotes of value 10 each, and the clerk gives you back four banknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the answer is 8.\n\nSample Input 2\n\n91\n\nSample Output 2\n\n3\n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one banknote of value 10, a total of three banknotes are used.\n\nSample Input 3\n\n314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170\n\nSample Output 3\n\n243", "sample_input": "36\n"}, "reference_outputs": ["8\n"], "source_document_id": "p02775", "source_text": "Score: 500 points\n\nProblem Statement\n\nIn the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \\dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. (Takoyaki is the name of a Japanese snack.)\n\nTo make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.\n\nWhat will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?\n\nAssume that you have sufficient numbers of banknotes, and so does the clerk.\n\nConstraints\n\nN is an integer between 1 and 10^{1,000,000} (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the minimum possible number of total banknotes used by you and the clerk.\n\nSample Input 1\n\n36\n\nSample Output 1\n\n8\n\nIf you give four banknotes of value 10 each, and the clerk gives you back four banknotes of value 1 each, a total of eight banknotes are used.\n\nThe payment cannot be made with less than eight banknotes in total, so the answer is 8.\n\nSample Input 2\n\n91\n\nSample Output 2\n\n3\n\nIf you give two banknotes of value 100, 1, and the clerk gives you back one banknote of value 10, a total of three banknotes are used.\n\nSample Input 3\n\n314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170\n\nSample Output 3\n\n243", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5850, "cpu_time_ms": 247, "memory_kb": 45544}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s964407371", "group_id": "codeNet:p02776", "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;;; 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(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 `(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 ,@(when declaration (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 (frob aref (declare ((integer 0 #.most-positive-fixnum) left 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 `(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 ,@(when declaration (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 (let ((end (or end (length target))))\n (frob aref (declare ((integer 0 #.most-positive-fixnum) left ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob 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 (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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (as (make-array n :element-type 'uint32))\n (bs (make-array n :element-type 'bit))\n (bits (make-array (+ n 1) :element-type 'bit))\n ;; vertex . edge-index\n (graph (make-array (+ n 1) :element-type 'list :initial-element nil))\n (visited (make-array (+ n 1) :element-type 'bit :initial-element 0))\n (res (make-array m :element-type 'bit :initial-element 0)))\n (dotimes (i n)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (setf (aref as i) a\n (aref bs i) b)))\n (parallel-sort! as #'< bs)\n (dotimes (i (+ n 1))\n (cond ((= i 0)\n (setf (aref bits i) (aref bs i)))\n ((= i n)\n (setf (aref bits i) (aref bs (- n 1))))\n (t (setf (aref bits i)\n (logxor (aref bs i) (aref bs (- i 1)))))))\n (dotimes (i m)\n (let* ((l (read-fixnum))\n (r (read-fixnum))\n (l-comped (bisect-left as l))\n (r-comped (bisect-right as r)))\n (push (cons l-comped i) (aref graph r-comped))\n (push (cons r-comped i) (aref graph l-comped))))\n (labels ((dfs (v)\n (setf (aref visited v) 1)\n (let ((xor (aref bits v)))\n (declare (bit xor))\n (dolist (node (aref graph v))\n (let ((child (car node))\n (edge-index (cdr node)))\n (when (zerop (aref visited child))\n (let ((child-xor (dfs child)))\n (when (= 1 child-xor)\n (setf (aref res edge-index) 1))\n (xorf xor child-xor)))))\n xor)))\n (dotimes (v (+ n 1))\n (when (zerop (aref visited v))\n (unless (zerop (dfs v))\n (println -1)\n (return-from main))))\n (let ((out (make-string-output-stream :element-type 'base-char)))\n (loop with init = t\n with count of-type uint31 = 0\n for i below m\n when (= 1 (aref res i))\n do (if init\n (setq init nil)\n (write-char #\\ out))\n (incf count)\n (write (+ i 1) :stream out)\n finally (println count)\n (write-line (get-output-stream-string out)))))))\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\n5 1\n10 1\n8 0\n1 10\n4 5\n6 7\n8 9\n\"\n \"2\n1 4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n2 0\n3 1\n5 1\n7 0\n1 4\n4 7\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 2\n5 0\n10 0\n8 0\n6 9\n66 99\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"12 20\n536130100 1\n150049660 1\n79245447 1\n132551741 0\n89484841 1\n328129089 0\n623467741 0\n248785745 0\n421631475 0\n498966877 0\n43768791 1\n112237273 0\n21499042 142460201\n58176487 384985131\n88563042 144788076\n120198276 497115965\n134867387 563350571\n211946499 458996604\n233934566 297258009\n335674184 555985828\n414601661 520203502\n101135608 501051309\n90972258 300372385\n255474956 630621190\n436210625 517850028\n145652401 192476406\n377607297 520655694\n244404406 304034433\n112237273 359737255\n392593015 463983307\n150586788 504362212\n54772353 83124235\n\"\n \"5\n1 7 8 9 11\n\")))\n", "language": "Lisp", "metadata": {"date": 1581986544, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02776.html", "problem_id": "p02776", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02776/input.txt", "sample_output_relpath": "derived/input_output/data/p02776/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02776/Lisp/s964407371.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s964407371", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n1 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 ;; 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;;; 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(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 `(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 ,@(when declaration (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 (frob aref (declare ((integer 0 #.most-positive-fixnum) left 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 `(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 ,@(when declaration (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 (let ((end (or end (length target))))\n (frob aref (declare ((integer 0 #.most-positive-fixnum) left ok)))))\n (function\n (assert end () \"Requires END argument if TARGET is a function.\")\n (frob 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 (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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (as (make-array n :element-type 'uint32))\n (bs (make-array n :element-type 'bit))\n (bits (make-array (+ n 1) :element-type 'bit))\n ;; vertex . edge-index\n (graph (make-array (+ n 1) :element-type 'list :initial-element nil))\n (visited (make-array (+ n 1) :element-type 'bit :initial-element 0))\n (res (make-array m :element-type 'bit :initial-element 0)))\n (dotimes (i n)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (setf (aref as i) a\n (aref bs i) b)))\n (parallel-sort! as #'< bs)\n (dotimes (i (+ n 1))\n (cond ((= i 0)\n (setf (aref bits i) (aref bs i)))\n ((= i n)\n (setf (aref bits i) (aref bs (- n 1))))\n (t (setf (aref bits i)\n (logxor (aref bs i) (aref bs (- i 1)))))))\n (dotimes (i m)\n (let* ((l (read-fixnum))\n (r (read-fixnum))\n (l-comped (bisect-left as l))\n (r-comped (bisect-right as r)))\n (push (cons l-comped i) (aref graph r-comped))\n (push (cons r-comped i) (aref graph l-comped))))\n (labels ((dfs (v)\n (setf (aref visited v) 1)\n (let ((xor (aref bits v)))\n (declare (bit xor))\n (dolist (node (aref graph v))\n (let ((child (car node))\n (edge-index (cdr node)))\n (when (zerop (aref visited child))\n (let ((child-xor (dfs child)))\n (when (= 1 child-xor)\n (setf (aref res edge-index) 1))\n (xorf xor child-xor)))))\n xor)))\n (dotimes (v (+ n 1))\n (when (zerop (aref visited v))\n (unless (zerop (dfs v))\n (println -1)\n (return-from main))))\n (let ((out (make-string-output-stream :element-type 'base-char)))\n (loop with init = t\n with count of-type uint31 = 0\n for i below m\n when (= 1 (aref res i))\n do (if init\n (setq init nil)\n (write-char #\\ out))\n (incf count)\n (write (+ i 1) :stream out)\n finally (println count)\n (write-line (get-output-stream-string out)))))))\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\n5 1\n10 1\n8 0\n1 10\n4 5\n6 7\n8 9\n\"\n \"2\n1 4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n2 0\n3 1\n5 1\n7 0\n1 4\n4 7\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 2\n5 0\n10 0\n8 0\n6 9\n66 99\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"12 20\n536130100 1\n150049660 1\n79245447 1\n132551741 0\n89484841 1\n328129089 0\n623467741 0\n248785745 0\n421631475 0\n498966877 0\n43768791 1\n112237273 0\n21499042 142460201\n58176487 384985131\n88563042 144788076\n120198276 497115965\n134867387 563350571\n211946499 458996604\n233934566 297258009\n335674184 555985828\n414601661 520203502\n101135608 501051309\n90972258 300372385\n255474956 630621190\n436210625 517850028\n145652401 192476406\n377607297 520655694\n244404406 304034433\n112237273 359737255\n392593015 463983307\n150586788 504362212\n54772353 83124235\n\"\n \"5\n1 7 8 9 11\n\")))\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nAfter being invaded by the Kingdom of AlDebaran, bombs are planted throughout our country, AtCoder Kingdom.\n\nFortunately, our military team called ABC has managed to obtain a device that is a part of the system controlling the bombs.\n\nThere are N bombs, numbered 1 to N, planted in our country. Bomb i is planted at the coordinate A_i. It is currently activated if B_i=1, and deactivated if B_i=0.\n\nThe device has M cords numbered 1 to M. If we cut Cord j, the states of all the bombs planted between the coordinates L_j and R_j (inclusive) will be switched - from activated to deactivated, and vice versa.\n\nDetermine whether it is possible to deactivate all the bombs at the same time. If the answer is yes, output a set of cords that should be cut.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\\ (1 \\leq i \\leq N)\n\nA_i are pairwise distinct.\n\nB_i is 0 or 1. (1 \\leq i \\leq N)\n\n1 \\leq M \\leq 2 \\times 10^5\n\n1 \\leq L_j \\leq R_j \\leq 10^9\\ (1 \\leq j \\leq M)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_N B_N\nL_1 R_1\n:\nL_M R_M\n\nOutput\n\nIf it is impossible to deactivate all the bombs at the same time, print -1. If it is possible to do so, print a set of cords that should be cut, as follows:\n\nk\nc_1 c_2 \\dots c_k\n\nHere, k is the number of cords (possibly 0), and c_1, c_2, \\dots, c_k represent the cords that should be cut. 1 \\leq c_1 < c_2 < \\dots < c_k \\leq M must hold.\n\nSample Input 1\n\n3 4\n5 1\n10 1\n8 0\n1 10\n4 5\n6 7\n8 9\n\nSample Output 1\n\n2\n1 4\n\nThere are two activated bombs at the coordinates 5, 10, and one deactivated bomb at the coordinate 8.\n\nCutting Cord 1 switches the states of all the bombs planted between the coordinates 1 and 10, that is, all of the three bombs.\n\nCutting Cord 4 switches the states of all the bombs planted between the coordinates 8 and 9, that is, Bomb 3.\n\nThus, we can deactivate all the bombs by cutting Cord 1 and Cord 4.\n\nSample Input 2\n\n4 2\n2 0\n3 1\n5 1\n7 0\n1 4\n4 7\n\nSample Output 2\n\n-1\n\nCutting any set of cords will not deactivate all the bombs at the same time.\n\nSample Input 3\n\n3 2\n5 0\n10 0\n8 0\n6 9\n66 99\n\nSample Output 3\n\n0\n\nAll the bombs are already deactivated, so we do not need to cut any cord.\n\nSample Input 4\n\n12 20\n536130100 1\n150049660 1\n79245447 1\n132551741 0\n89484841 1\n328129089 0\n623467741 0\n248785745 0\n421631475 0\n498966877 0\n43768791 1\n112237273 0\n21499042 142460201\n58176487 384985131\n88563042 144788076\n120198276 497115965\n134867387 563350571\n211946499 458996604\n233934566 297258009\n335674184 555985828\n414601661 520203502\n101135608 501051309\n90972258 300372385\n255474956 630621190\n436210625 517850028\n145652401 192476406\n377607297 520655694\n244404406 304034433\n112237273 359737255\n392593015 463983307\n150586788 504362212\n54772353 83124235\n\nSample Output 4\n\n5\n1 7 8 9 11\n\nIf there are multiple sets of cords that deactivate all the bombs when cut, any of them can be printed.", "sample_input": "3 4\n5 1\n10 1\n8 0\n1 10\n4 5\n6 7\n8 9\n"}, "reference_outputs": ["2\n1 4\n"], "source_document_id": "p02776", "source_text": "Score: 600 points\n\nProblem Statement\n\nAfter being invaded by the Kingdom of AlDebaran, bombs are planted throughout our country, AtCoder Kingdom.\n\nFortunately, our military team called ABC has managed to obtain a device that is a part of the system controlling the bombs.\n\nThere are N bombs, numbered 1 to N, planted in our country. Bomb i is planted at the coordinate A_i. It is currently activated if B_i=1, and deactivated if B_i=0.\n\nThe device has M cords numbered 1 to M. If we cut Cord j, the states of all the bombs planted between the coordinates L_j and R_j (inclusive) will be switched - from activated to deactivated, and vice versa.\n\nDetermine whether it is possible to deactivate all the bombs at the same time. If the answer is yes, output a set of cords that should be cut.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\\ (1 \\leq i \\leq N)\n\nA_i are pairwise distinct.\n\nB_i is 0 or 1. (1 \\leq i \\leq N)\n\n1 \\leq M \\leq 2 \\times 10^5\n\n1 \\leq L_j \\leq R_j \\leq 10^9\\ (1 \\leq j \\leq M)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 B_1\n:\nA_N B_N\nL_1 R_1\n:\nL_M R_M\n\nOutput\n\nIf it is impossible to deactivate all the bombs at the same time, print -1. If it is possible to do so, print a set of cords that should be cut, as follows:\n\nk\nc_1 c_2 \\dots c_k\n\nHere, k is the number of cords (possibly 0), and c_1, c_2, \\dots, c_k represent the cords that should be cut. 1 \\leq c_1 < c_2 < \\dots < c_k \\leq M must hold.\n\nSample Input 1\n\n3 4\n5 1\n10 1\n8 0\n1 10\n4 5\n6 7\n8 9\n\nSample Output 1\n\n2\n1 4\n\nThere are two activated bombs at the coordinates 5, 10, and one deactivated bomb at the coordinate 8.\n\nCutting Cord 1 switches the states of all the bombs planted between the coordinates 1 and 10, that is, all of the three bombs.\n\nCutting Cord 4 switches the states of all the bombs planted between the coordinates 8 and 9, that is, Bomb 3.\n\nThus, we can deactivate all the bombs by cutting Cord 1 and Cord 4.\n\nSample Input 2\n\n4 2\n2 0\n3 1\n5 1\n7 0\n1 4\n4 7\n\nSample Output 2\n\n-1\n\nCutting any set of cords will not deactivate all the bombs at the same time.\n\nSample Input 3\n\n3 2\n5 0\n10 0\n8 0\n6 9\n66 99\n\nSample Output 3\n\n0\n\nAll the bombs are already deactivated, so we do not need to cut any cord.\n\nSample Input 4\n\n12 20\n536130100 1\n150049660 1\n79245447 1\n132551741 0\n89484841 1\n328129089 0\n623467741 0\n248785745 0\n421631475 0\n498966877 0\n43768791 1\n112237273 0\n21499042 142460201\n58176487 384985131\n88563042 144788076\n120198276 497115965\n134867387 563350571\n211946499 458996604\n233934566 297258009\n335674184 555985828\n414601661 520203502\n101135608 501051309\n90972258 300372385\n255474956 630621190\n436210625 517850028\n145652401 192476406\n377607297 520655694\n244404406 304034433\n112237273 359737255\n392593015 463983307\n150586788 504362212\n54772353 83124235\n\nSample Output 4\n\n5\n1 7 8 9 11\n\nIf there are multiple sets of cords that deactivate all the bombs when cut, any of them can be printed.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15781, "cpu_time_ms": 378, "memory_kb": 62908}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s733330684", "group_id": "codeNet:p02777", "input_text": "(defun read-string () ;スペース区切りstring入力\n (let* ((str (read-line)))\n (labels ((instring (instring-str rt)\n (let* ((pos (position #\\Space instring-str :test #'char=)))\n (if pos\n (instring (subseq instring-str (1+ pos))\n (cons (subseq instring-str 0 pos) rt))\n (cons instring-str rt)))))\n (reverse (instring str nil)))))\n(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))))\n", "language": "Lisp", "metadata": {"date": 1581279036, "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/s733330684.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s733330684", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2 4\n", "input_to_evaluate": "(defun read-string () ;スペース区切りstring入力\n (let* ((str (read-line)))\n (labels ((instring (instring-str rt)\n (let* ((pos (position #\\Space instring-str :test #'char=)))\n (if pos\n (instring (subseq instring-str (1+ pos))\n (cons (subseq instring-str 0 pos) rt))\n (cons instring-str rt)))))\n (reverse (instring str nil)))))\n(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))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 692, "cpu_time_ms": 263, "memory_kb": 12644}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s868607384", "group_id": "codeNet:p02777", "input_text": "(let ((a (read))\n (b (read))\n (c (read))\n (d (read))\n (e (read)))\n (if (eq a e)\n (progn\n (princ (1- c))\n (princ #\\space)\n (princ d))\n (progn\n (princ c)\n (princ #\\space)\n (princ (1- d)))))\n", "language": "Lisp", "metadata": {"date": 1581278542, "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/s868607384.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s868607384", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2 4\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read))\n (d (read))\n (e (read)))\n (if (eq a e)\n (progn\n (princ (1- c))\n (princ #\\space)\n (princ d))\n (progn\n (princ c)\n (princ #\\space)\n (princ (1- d)))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 101, "memory_kb": 10212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s193756723", "group_id": "codeNet:p02779", "input_text": "(let* ((n (read))\n (as (make-array n :element-type 'fixnum)))\n (loop for i from 0 below n\n do (setf (aref as i) (read)))\n (setf as (sort as #'>))\n (princ (loop for i from 1 below n\n do (when (= (aref as i) (aref as (- i 1)))\n (return \"NO\"))\n finally (return \"YES\")))\n (terpri))", "language": "Lisp", "metadata": {"date": 1581279616, "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/s193756723.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s193756723", "user_id": "u690263481"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let* ((n (read))\n (as (make-array n :element-type 'fixnum)))\n (loop for i from 0 below n\n do (setf (aref as i) (read)))\n (setf as (sort as #'>))\n (princ (loop for i from 1 below n\n do (when (= (aref as i) (aref as (- i 1)))\n (return \"NO\"))\n finally (return \"YES\")))\n (terpri))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 341, "cpu_time_ms": 704, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s197064599", "group_id": "codeNet:p02780", "input_text": "(let* ((n (read))\n (k (read))\n (p (make-array (list (1+ n))))\n (s (make-array (list (1+ n)) :initial-element 0))\n (ans 0))\n (loop :for i :from 1 :to k\n :do (let ((x (read)))\n (setf (aref p i) x)\n (incf (aref s k) (aref p i))))\n (setf ans (aref s k))\n (loop :for i :from (1+ k) :to n\n :do (let ((x (read)))\n (setf (aref p i) x)\n (setf (aref s i) (+ (aref s (1- i)) (aref p i) (- (aref p (- i k)))))\n (setf ans (max ans (aref s i)))))\n (format t \"~F~%\" (/ (+ ans k) 2)))\n", "language": "Lisp", "metadata": {"date": 1594936492, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02780.html", "problem_id": "p02780", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02780/input.txt", "sample_output_relpath": "derived/input_output/data/p02780/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02780/Lisp/s197064599.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s197064599", "user_id": "u608227593"}, "prompt_components": {"gold_output": "7.000000000000\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (p (make-array (list (1+ n))))\n (s (make-array (list (1+ n)) :initial-element 0))\n (ans 0))\n (loop :for i :from 1 :to k\n :do (let ((x (read)))\n (setf (aref p i) x)\n (incf (aref s k) (aref p i))))\n (setf ans (aref s k))\n (loop :for i :from (1+ k) :to n\n :do (let ((x (read)))\n (setf (aref p i) x)\n (setf (aref s i) (+ (aref s (1- i)) (aref p i) (- (aref p (- i k)))))\n (setf ans (max ans (aref s i)))))\n (format t \"~F~%\" (/ (+ ans k) 2)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.\n\nWe will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.\n\nConstraints\n\n1 ≤ K ≤ N ≤ 200000\n\n1 ≤ p_i ≤ 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_N\n\nOutput\n\nPrint the maximum possible value of the expected value of the sum of the numbers shown.\n\nYour output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n5 3\n1 2 2 4 5\n\nSample Output 1\n\n7.000000000000\n\nWhen we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.\n\nSample Input 2\n\n4 1\n6 6 6 6\n\nSample Output 2\n\n3.500000000000\n\nRegardless of which die we choose, the expected value of the number shown is 3.5.\n\nSample Input 3\n\n10 4\n17 13 13 12 15 20 10 13 17 11\n\nSample Output 3\n\n32.000000000000", "sample_input": "5 3\n1 2 2 4 5\n"}, "reference_outputs": ["7.000000000000\n"], "source_document_id": "p02780", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.\n\nWe will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.\n\nConstraints\n\n1 ≤ K ≤ N ≤ 200000\n\n1 ≤ p_i ≤ 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_N\n\nOutput\n\nPrint the maximum possible value of the expected value of the sum of the numbers shown.\n\nYour output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n5 3\n1 2 2 4 5\n\nSample Output 1\n\n7.000000000000\n\nWhen we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.\n\nSample Input 2\n\n4 1\n6 6 6 6\n\nSample Output 2\n\n3.500000000000\n\nRegardless of which die we choose, the expected value of the number shown is 3.5.\n\nSample Input 3\n\n10 4\n17 13 13 12 15 20 10 13 17 11\n\nSample Output 3\n\n32.000000000000", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 576, "cpu_time_ms": 171, "memory_kb": 79688}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s778292031", "group_id": "codeNet:p02780", "input_text": "(defun solve (n k p)\n (/ (if (= n k)\n (+ (loop for i from 0 below k\n sum (aref p i))\n k)\n (loop with cur = (+ (loop for i from 0 below k\n sum (aref p i))\n k)\n for i from k below n\n maximizing (setf cur (+ (- cur (aref p (- i k)))\n (aref p i)))))\n 2.0d0))\n\n#-swank\n(let* ((n (read))\n (k (read))\n (p (make-array n :element-type 'fixnum))\n (*read-default-float-format* 'double-float))\n (loop for i from 0 below n\n do (setf (aref p i) (read)))\n (format t \"~A~%\" (solve n k p)))\n", "language": "Lisp", "metadata": {"date": 1581280154, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02780.html", "problem_id": "p02780", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02780/input.txt", "sample_output_relpath": "derived/input_output/data/p02780/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02780/Lisp/s778292031.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s778292031", "user_id": "u202886318"}, "prompt_components": {"gold_output": "7.000000000000\n", "input_to_evaluate": "(defun solve (n k p)\n (/ (if (= n k)\n (+ (loop for i from 0 below k\n sum (aref p i))\n k)\n (loop with cur = (+ (loop for i from 0 below k\n sum (aref p i))\n k)\n for i from k below n\n maximizing (setf cur (+ (- cur (aref p (- i k)))\n (aref p i)))))\n 2.0d0))\n\n#-swank\n(let* ((n (read))\n (k (read))\n (p (make-array n :element-type 'fixnum))\n (*read-default-float-format* 'double-float))\n (loop for i from 0 below n\n do (setf (aref p i) (read)))\n (format t \"~A~%\" (solve n k p)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.\n\nWe will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.\n\nConstraints\n\n1 ≤ K ≤ N ≤ 200000\n\n1 ≤ p_i ≤ 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_N\n\nOutput\n\nPrint the maximum possible value of the expected value of the sum of the numbers shown.\n\nYour output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n5 3\n1 2 2 4 5\n\nSample Output 1\n\n7.000000000000\n\nWhen we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.\n\nSample Input 2\n\n4 1\n6 6 6 6\n\nSample Output 2\n\n3.500000000000\n\nRegardless of which die we choose, the expected value of the number shown is 3.5.\n\nSample Input 3\n\n10 4\n17 13 13 12 15 20 10 13 17 11\n\nSample Output 3\n\n32.000000000000", "sample_input": "5 3\n1 2 2 4 5\n"}, "reference_outputs": ["7.000000000000\n"], "source_document_id": "p02780", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.\n\nWe will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.\n\nConstraints\n\n1 ≤ K ≤ N ≤ 200000\n\n1 ≤ p_i ≤ 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_N\n\nOutput\n\nPrint the maximum possible value of the expected value of the sum of the numbers shown.\n\nYour output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.\n\nSample Input 1\n\n5 3\n1 2 2 4 5\n\nSample Output 1\n\n7.000000000000\n\nWhen we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.\n\nSample Input 2\n\n4 1\n6 6 6 6\n\nSample Output 2\n\n3.500000000000\n\nRegardless of which die we choose, the expected value of the number shown is 3.5.\n\nSample Input 3\n\n10 4\n17 13 13 12 15 20 10 13 17 11\n\nSample Output 3\n\n32.000000000000", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 364, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s917504972", "group_id": "codeNet:p02782", "input_text": ";; F - Many Many Paths\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n(defparameter *max-rc* (expt 10 6))\n\n(defun main ()\n (let ((r1 (read))\n (c1 (read))\n (r2 (read))\n (c2 (read)))\n (princ (solve r1 c1 r2 c2))))\n\n(defun solve (r1 c1 r2 c2)\n ; f(r,c) == choose(r+c, r)\n ; sum_{r=0}^{r2} sum_{c=0}^{c2} f(r,c) == f(r+1, c+1) - 1\n (labels ((f (r c) (choose (+ r c) r)))\n (mod+ (f (1+ r2) (1+ c2))\n (- (f (1+ r2) c1))\n (- (f r1 (1+ c2)))\n (f r1 c1))))\n\n;; modulo addition/product/division\n\n(defun mod+ (&rest rest)\n (mod (apply #'+ rest) *modulus*))\n\n(defun mod* (&rest rest)\n (mod (apply #'* rest) *modulus*))\n\n(defun mod/ (num &rest denom)\n (apply #'mod* (cons num (mapcar #'mod-inverse denom))))\n\n(defun bit-sequence (v)\n \"(bit-sequence 13) => (1 1 0 1)\"\n (nreverse\n (loop for x = v then (ash x -1) while (plusp x)\n collect (logand x 1))))\n\n(let ((modulus-2-bits (bit-sequence (- *modulus* 2))))\n ; Mが素数のとき,a^(M-2) ≡ a^(-1) mod M (フェルマーの小定理より)\n (defun mod-inverse (a)\n (loop for b in modulus-2-bits\n for e = a then (mod* e e (if (zerop b) 1 a))\n finally (return e))))\n\n(let* ((max-n (+ *max-rc* *max-rc* 2))\n (fact (make-array (1+ max-n)))) ; 階乗\n (setf (aref fact 0) 1) ; 0! = 1\n (loop for i from 1 to max-n\n do (setf (aref fact i) (mod* (aref fact (1- i)) i)))\n (defun choose (n k)\n (mod/ (aref fact n) (aref fact k) (aref fact (- n k)))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1583183306, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02782.html", "problem_id": "p02782", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02782/input.txt", "sample_output_relpath": "derived/input_output/data/p02782/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02782/Lisp/s917504972.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s917504972", "user_id": "u227020436"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": ";; F - Many Many Paths\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n(defparameter *max-rc* (expt 10 6))\n\n(defun main ()\n (let ((r1 (read))\n (c1 (read))\n (r2 (read))\n (c2 (read)))\n (princ (solve r1 c1 r2 c2))))\n\n(defun solve (r1 c1 r2 c2)\n ; f(r,c) == choose(r+c, r)\n ; sum_{r=0}^{r2} sum_{c=0}^{c2} f(r,c) == f(r+1, c+1) - 1\n (labels ((f (r c) (choose (+ r c) r)))\n (mod+ (f (1+ r2) (1+ c2))\n (- (f (1+ r2) c1))\n (- (f r1 (1+ c2)))\n (f r1 c1))))\n\n;; modulo addition/product/division\n\n(defun mod+ (&rest rest)\n (mod (apply #'+ rest) *modulus*))\n\n(defun mod* (&rest rest)\n (mod (apply #'* rest) *modulus*))\n\n(defun mod/ (num &rest denom)\n (apply #'mod* (cons num (mapcar #'mod-inverse denom))))\n\n(defun bit-sequence (v)\n \"(bit-sequence 13) => (1 1 0 1)\"\n (nreverse\n (loop for x = v then (ash x -1) while (plusp x)\n collect (logand x 1))))\n\n(let ((modulus-2-bits (bit-sequence (- *modulus* 2))))\n ; Mが素数のとき,a^(M-2) ≡ a^(-1) mod M (フェルマーの小定理より)\n (defun mod-inverse (a)\n (loop for b in modulus-2-bits\n for e = a then (mod* e e (if (zerop b) 1 a))\n finally (return e))))\n\n(let* ((max-n (+ *max-rc* *max-rc* 2))\n (fact (make-array (1+ max-n)))) ; 階乗\n (setf (aref fact 0) 1) ; 0! = 1\n (loop for i from 1 to max-n\n do (setf (aref fact i) (mod* (aref fact (1- i)) i)))\n (defun choose (n k)\n (mod/ (aref fact n) (aref fact k) (aref fact (- n k)))))\n\n(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction.\n\nLet us define a function f(r, c) as follows:\n\nf(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)\n\nGiven are integers r_1, r_2, c_1, and c_2.\nFind the sum of f(i, j) over all pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute this value modulo (10^9+7).\n\nConstraints\n\n1 ≤ r_1 ≤ r_2 ≤ 10^6\n\n1 ≤ c_1 ≤ c_2 ≤ 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr_1 c_1 r_2 c_2\n\nOutput\n\nPrint the sum of f(i, j) modulo (10^9+7).\n\nSample Input 1\n\n1 1 2 2\n\nSample Output 1\n\n14\n\nFor example, there are two paths from the point (0, 0) to the point (1, 1): (0,0) → (0,1) → (1,1) and (0,0) → (1,0) → (1,1), so f(1,1)=2.\n\nSimilarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.\n\nSample Input 2\n\n314 159 2653 589\n\nSample Output 2\n\n602215194", "sample_input": "1 1 2 2\n"}, "reference_outputs": ["14\n"], "source_document_id": "p02782", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction.\n\nLet us define a function f(r, c) as follows:\n\nf(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)\n\nGiven are integers r_1, r_2, c_1, and c_2.\nFind the sum of f(i, j) over all pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute this value modulo (10^9+7).\n\nConstraints\n\n1 ≤ r_1 ≤ r_2 ≤ 10^6\n\n1 ≤ c_1 ≤ c_2 ≤ 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr_1 c_1 r_2 c_2\n\nOutput\n\nPrint the sum of f(i, j) modulo (10^9+7).\n\nSample Input 1\n\n1 1 2 2\n\nSample Output 1\n\n14\n\nFor example, there are two paths from the point (0, 0) to the point (1, 1): (0,0) → (0,1) → (1,1) and (0,0) → (1,0) → (1,1), so f(1,1)=2.\n\nSimilarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.\n\nSample Input 2\n\n314 159 2653 589\n\nSample Output 2\n\n602215194", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1501, "cpu_time_ms": 254, "memory_kb": 32992}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s605352051", "group_id": "codeNet:p02782", "input_text": "(defparameter const (+ 7 (expt 10 9)))\n(defparameter r1 (read))\n(defparameter c1 (read))\n(defparameter r2 (read))\n(defparameter c2 (read))\n\n(defun fact (n)\n (if (= n 1)\n 1\n (* n (fact (1- n)))))\n\n(defun comb (r c)\n (/ (fact (+ r c)) (fact r) (fact c)))\n\n(format t \"~A\" (loop with count = 0\n for r from r1 to r2\n do (loop for c from c1 to c2\n do (incf count (mod (comb r c) \n const))\n (setf count (mod count const)))\n (setf count (mod count const))\n finally (return (mod count const))))\n", "language": "Lisp", "metadata": {"date": 1581282436, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02782.html", "problem_id": "p02782", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02782/input.txt", "sample_output_relpath": "derived/input_output/data/p02782/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02782/Lisp/s605352051.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s605352051", "user_id": "u425317134"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": "(defparameter const (+ 7 (expt 10 9)))\n(defparameter r1 (read))\n(defparameter c1 (read))\n(defparameter r2 (read))\n(defparameter c2 (read))\n\n(defun fact (n)\n (if (= n 1)\n 1\n (* n (fact (1- n)))))\n\n(defun comb (r c)\n (/ (fact (+ r c)) (fact r) (fact c)))\n\n(format t \"~A\" (loop with count = 0\n for r from r1 to r2\n do (loop for c from c1 to c2\n do (incf count (mod (comb r c) \n const))\n (setf count (mod count const)))\n (setf count (mod count const))\n finally (return (mod count const))))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction.\n\nLet us define a function f(r, c) as follows:\n\nf(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)\n\nGiven are integers r_1, r_2, c_1, and c_2.\nFind the sum of f(i, j) over all pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute this value modulo (10^9+7).\n\nConstraints\n\n1 ≤ r_1 ≤ r_2 ≤ 10^6\n\n1 ≤ c_1 ≤ c_2 ≤ 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr_1 c_1 r_2 c_2\n\nOutput\n\nPrint the sum of f(i, j) modulo (10^9+7).\n\nSample Input 1\n\n1 1 2 2\n\nSample Output 1\n\n14\n\nFor example, there are two paths from the point (0, 0) to the point (1, 1): (0,0) → (0,1) → (1,1) and (0,0) → (1,0) → (1,1), so f(1,1)=2.\n\nSimilarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.\n\nSample Input 2\n\n314 159 2653 589\n\nSample Output 2\n\n602215194", "sample_input": "1 1 2 2\n"}, "reference_outputs": ["14\n"], "source_document_id": "p02782", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction.\n\nLet us define a function f(r, c) as follows:\n\nf(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)\n\nGiven are integers r_1, r_2, c_1, and c_2.\nFind the sum of f(i, j) over all pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute this value modulo (10^9+7).\n\nConstraints\n\n1 ≤ r_1 ≤ r_2 ≤ 10^6\n\n1 ≤ c_1 ≤ c_2 ≤ 10^6\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nr_1 c_1 r_2 c_2\n\nOutput\n\nPrint the sum of f(i, j) modulo (10^9+7).\n\nSample Input 1\n\n1 1 2 2\n\nSample Output 1\n\n14\n\nFor example, there are two paths from the point (0, 0) to the point (1, 1): (0,0) → (0,1) → (1,1) and (0,0) → (1,0) → (1,1), so f(1,1)=2.\n\nSimilarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.\n\nSample Input 2\n\n314 159 2653 589\n\nSample Output 2\n\n602215194", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 691, "cpu_time_ms": 2105, "memory_kb": 106948}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s045921835", "group_id": "codeNet:p02783", "input_text": "(let ((h (read))\n (a (read)))\n (format t \"~A~%\" (ceiling (/ h a))))\n", "language": "Lisp", "metadata": {"date": 1593677944, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s045921835.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s045921835", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((h (read))\n (a (read)))\n (format t \"~A~%\" (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 24064}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s967817863", "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 (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": 1580069476, "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/s967817863.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s967817863", "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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 162, "memory_kb": 14436}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s593053379", "group_id": "codeNet:p02784", "input_text": "(let* ((h (read))\n (n (read))\n (lst (loop :repeat n :sum (read))))\n (if (<= h lst) (princ \"Yes\") (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1580068959, "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/s593053379.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s593053379", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((h (read))\n (n (read))\n (lst (loop :repeat n :sum (read))))\n (if (<= h lst) (princ \"Yes\") (princ \"No\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 193, "memory_kb": 57700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s220391864", "group_id": "codeNet:p02785", "input_text": "(defvar N (read))\n(defvar K (read))\n\n(princ (reduce #'+ (nthcdr K (sort (loop :repeat N :collect (read)) #'>))))", "language": "Lisp", "metadata": {"date": 1584982145, "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/s220391864.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s220391864", "user_id": "u334552723"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defvar N (read))\n(defvar K (read))\n\n(princ (reduce #'+ (nthcdr K (sort (loop :repeat N :collect (read)) #'>))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 624, "memory_kb": 61792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s126397786", "group_id": "codeNet:p02785", "input_text": "(defun solve (array e-num spa &optional (pos 0) (result 0))\n (cond ((and (= spa 0) (= e-num 0))\n result)\n ((= spa 0)\n (solve array (1- e-num) spa (1+ pos) (+ result (aref array pos))))\n (t\n (solve array (1- e-num) (1- spa) (1+ pos) result))))\n\n(let* ((Enemy-Numbers (read))\n (Special-Atack (read))\n (Enemy-list (make-array Enemy-Numbers :initial-element 0)))\n (dotimes (x Enemy-Numbers)\n (setf (aref Enemy-list x) (read)))\n (sort Enemy-list #'>)\n (print (if (>= Special-Atack Enemy-Numbers)\n 0\n (solve Enemy-list Enemy-Numbers Special-Atack))))\n", "language": "Lisp", "metadata": {"date": 1580071834, "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/s126397786.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s126397786", "user_id": "u631655863"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun solve (array e-num spa &optional (pos 0) (result 0))\n (cond ((and (= spa 0) (= e-num 0))\n result)\n ((= spa 0)\n (solve array (1- e-num) spa (1+ pos) (+ result (aref array pos))))\n (t\n (solve array (1- e-num) (1- spa) (1+ pos) result))))\n\n(let* ((Enemy-Numbers (read))\n (Special-Atack (read))\n (Enemy-list (make-array Enemy-Numbers :initial-element 0)))\n (dotimes (x Enemy-Numbers)\n (setf (aref Enemy-list x) (read)))\n (sort Enemy-list #'>)\n (print (if (>= Special-Atack Enemy-Numbers)\n 0\n (solve Enemy-list Enemy-Numbers Special-Atack))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 626, "cpu_time_ms": 634, "memory_kb": 59876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s810546814", "group_id": "codeNet:p02785", "input_text": "(let* ((n (read))\n (k (read))\n (hs (make-array n :element-type 'integer)))\n (loop for i from 0 below n do (setf (aref hs i) (read)))\n (setf hs (sort hs #'>=))\n (format t \"~a~%\" (loop for i from k below n\n summing (aref hs i))))", "language": "Lisp", "metadata": {"date": 1580069543, "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/s810546814.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s810546814", "user_id": "u690263481"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let* ((n (read))\n (k (read))\n (hs (make-array n :element-type 'integer)))\n (loop for i from 0 below n do (setf (aref hs i) (read)))\n (setf hs (sort hs #'>=))\n (format t \"~a~%\" (loop for i from k below n\n summing (aref hs i))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 266, "cpu_time_ms": 832, "memory_kb": 69988}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s062486910", "group_id": "codeNet:p02786", "input_text": "(let* ((n (read)))\n (princ (loop :for k :from 0 :upto (1- (length (format nil \"~b\" n))) :sum (expt 2 k))))", "language": "Lisp", "metadata": {"date": 1580069552, "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/s062486910.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s062486910", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((n (read)))\n (princ (loop :for k :from 0 :upto (1- (length (format nil \"~b\" n))) :sum (expt 2 k))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 128, "memory_kb": 12392}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s241232675", "group_id": "codeNet:p02787", "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 (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(defconstant +inf+ most-positive-fixnum)\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (dp (make-array 10001 :element-type 'uint62)))\n (declare (uint31 h n))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (dotimes (x (+ n 1))\n (dotimes (y (+ h 1))\n (setf (aref dp y)\n (cond ((zerop y) 0)\n ((zerop x) +inf+)\n (t (let ((a (aref as (- x 1)))\n (b (aref bs (- x 1))))\n (min (+ (aref dp (max 0 (- y a))) b)\n (aref dp y))))))))\n (println (aref dp h))))\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 \"9 3\n8 3\n4 2\n2 1\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100 6\n1 1\n2 3\n3 9\n4 27\n5 81\n6 243\n\"\n \"100\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9999 10\n540 7550\n691 9680\n700 9790\n510 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2461\n\"\n \"139815\n\")))\n", "language": "Lisp", "metadata": {"date": 1580346387, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02787.html", "problem_id": "p02787", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02787/input.txt", "sample_output_relpath": "derived/input_output/data/p02787/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02787/Lisp/s241232675.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s241232675", "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 (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(defconstant +inf+ most-positive-fixnum)\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (dp (make-array 10001 :element-type 'uint62)))\n (declare (uint31 h n))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (dotimes (x (+ n 1))\n (dotimes (y (+ h 1))\n (setf (aref dp y)\n (cond ((zerop y) 0)\n ((zerop x) +inf+)\n (t (let ((a (aref as (- x 1)))\n (b (aref bs (- x 1))))\n (min (+ (aref dp (max 0 (- y a))) b)\n (aref dp y))))))))\n (println (aref dp h))))\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 \"9 3\n8 3\n4 2\n2 1\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100 6\n1 1\n2 3\n3 9\n4 27\n5 81\n6 243\n\"\n \"100\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9999 10\n540 7550\n691 9680\n700 9790\n510 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2461\n\"\n \"139815\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nIbis is fighting with a monster.\n\nThe health of the monster is H.\n\nIbis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points.\n\nThe same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.\n\nIbis wins when the health of the monster becomes 0 or below.\n\nFind the minimum total Magic Points that have to be consumed before winning.\n\nConstraints\n\n1 \\leq H \\leq 10^4\n\n1 \\leq N \\leq 10^3\n\n1 \\leq A_i \\leq 10^4\n\n1 \\leq B_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 B_1\n:\nA_N B_N\n\nOutput\n\nPrint the minimum total Magic Points that have to be consumed before winning.\n\nSample Input 1\n\n9 3\n8 3\n4 2\n2 1\n\nSample Output 1\n\n4\n\nFirst, let us cast the first spell to decrease the monster's health by 8, at the cost of 3 Magic Points. The monster's health is now 1.\n\nThen, cast the third spell to decrease the monster's health by 2, at the cost of 1 Magic Point. The monster's health is now -1.\n\nIn this way, we can win at the total cost of 4 Magic Points.\n\nSample Input 2\n\n100 6\n1 1\n2 3\n3 9\n4 27\n5 81\n6 243\n\nSample Output 2\n\n100\n\nIt is optimal to cast the first spell 100 times.\n\nSample Input 3\n\n9999 10\n540 7550\n691 9680\n700 9790\n510 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2461\n\nSample Output 3\n\n139815", "sample_input": "9 3\n8 3\n4 2\n2 1\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02787", "source_text": "Score : 500 points\n\nProblem Statement\n\nIbis is fighting with a monster.\n\nThe health of the monster is H.\n\nIbis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points.\n\nThe same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.\n\nIbis wins when the health of the monster becomes 0 or below.\n\nFind the minimum total Magic Points that have to be consumed before winning.\n\nConstraints\n\n1 \\leq H \\leq 10^4\n\n1 \\leq N \\leq 10^3\n\n1 \\leq A_i \\leq 10^4\n\n1 \\leq B_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 B_1\n:\nA_N B_N\n\nOutput\n\nPrint the minimum total Magic Points that have to be consumed before winning.\n\nSample Input 1\n\n9 3\n8 3\n4 2\n2 1\n\nSample Output 1\n\n4\n\nFirst, let us cast the first spell to decrease the monster's health by 8, at the cost of 3 Magic Points. The monster's health is now 1.\n\nThen, cast the third spell to decrease the monster's health by 2, at the cost of 1 Magic Point. The monster's health is now -1.\n\nIn this way, we can win at the total cost of 4 Magic Points.\n\nSample Input 2\n\n100 6\n1 1\n2 3\n3 9\n4 27\n5 81\n6 243\n\nSample Output 2\n\n100\n\nIt is optimal to cast the first spell 100 times.\n\nSample Input 3\n\n9999 10\n540 7550\n691 9680\n700 9790\n510 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2461\n\nSample Output 3\n\n139815", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5704, "cpu_time_ms": 84, "memory_kb": 10980}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s743872269", "group_id": "codeNet:p02787", "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 (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(defconstant +inf+ most-positive-fixnum)\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (dp (make-array '(1001 10001) :element-type 'uint62)))\n (declare (uint31 h n))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (dotimes (x (+ n 1))\n (dotimes (y (+ h 1))\n (setf (aref dp x y)\n (cond ((zerop y) 0)\n ((zerop x) +inf+)\n (t (let ((a (aref as (- x 1)))\n (b (aref bs (- x 1))))\n (min (+ (aref dp x (max 0 (- y a))) b)\n (+ (aref dp (- x 1) (max 0 (- y a))) b)\n (aref dp (- x 1) y))))))))\n (println (aref dp n h))))\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 \"9 3\n8 3\n4 2\n2 1\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100 6\n1 1\n2 3\n3 9\n4 27\n5 81\n6 243\n\"\n \"100\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9999 10\n540 7550\n691 9680\n700 9790\n510 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2461\n\"\n \"139815\n\")))\n", "language": "Lisp", "metadata": {"date": 1580073972, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02787.html", "problem_id": "p02787", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02787/input.txt", "sample_output_relpath": "derived/input_output/data/p02787/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02787/Lisp/s743872269.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s743872269", "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 (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(defconstant +inf+ most-positive-fixnum)\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (n (read))\n (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (dp (make-array '(1001 10001) :element-type 'uint62)))\n (declare (uint31 h n))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (dotimes (x (+ n 1))\n (dotimes (y (+ h 1))\n (setf (aref dp x y)\n (cond ((zerop y) 0)\n ((zerop x) +inf+)\n (t (let ((a (aref as (- x 1)))\n (b (aref bs (- x 1))))\n (min (+ (aref dp x (max 0 (- y a))) b)\n (+ (aref dp (- x 1) (max 0 (- y a))) b)\n (aref dp (- x 1) y))))))))\n (println (aref dp n h))))\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 \"9 3\n8 3\n4 2\n2 1\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100 6\n1 1\n2 3\n3 9\n4 27\n5 81\n6 243\n\"\n \"100\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"9999 10\n540 7550\n691 9680\n700 9790\n510 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2461\n\"\n \"139815\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nIbis is fighting with a monster.\n\nThe health of the monster is H.\n\nIbis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points.\n\nThe same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.\n\nIbis wins when the health of the monster becomes 0 or below.\n\nFind the minimum total Magic Points that have to be consumed before winning.\n\nConstraints\n\n1 \\leq H \\leq 10^4\n\n1 \\leq N \\leq 10^3\n\n1 \\leq A_i \\leq 10^4\n\n1 \\leq B_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 B_1\n:\nA_N B_N\n\nOutput\n\nPrint the minimum total Magic Points that have to be consumed before winning.\n\nSample Input 1\n\n9 3\n8 3\n4 2\n2 1\n\nSample Output 1\n\n4\n\nFirst, let us cast the first spell to decrease the monster's health by 8, at the cost of 3 Magic Points. The monster's health is now 1.\n\nThen, cast the third spell to decrease the monster's health by 2, at the cost of 1 Magic Point. The monster's health is now -1.\n\nIn this way, we can win at the total cost of 4 Magic Points.\n\nSample Input 2\n\n100 6\n1 1\n2 3\n3 9\n4 27\n5 81\n6 243\n\nSample Output 2\n\n100\n\nIt is optimal to cast the first spell 100 times.\n\nSample Input 3\n\n9999 10\n540 7550\n691 9680\n700 9790\n510 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2461\n\nSample Output 3\n\n139815", "sample_input": "9 3\n8 3\n4 2\n2 1\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02787", "source_text": "Score : 500 points\n\nProblem Statement\n\nIbis is fighting with a monster.\n\nThe health of the monster is H.\n\nIbis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points.\n\nThe same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.\n\nIbis wins when the health of the monster becomes 0 or below.\n\nFind the minimum total Magic Points that have to be consumed before winning.\n\nConstraints\n\n1 \\leq H \\leq 10^4\n\n1 \\leq N \\leq 10^3\n\n1 \\leq A_i \\leq 10^4\n\n1 \\leq B_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 B_1\n:\nA_N B_N\n\nOutput\n\nPrint the minimum total Magic Points that have to be consumed before winning.\n\nSample Input 1\n\n9 3\n8 3\n4 2\n2 1\n\nSample Output 1\n\n4\n\nFirst, let us cast the first spell to decrease the monster's health by 8, at the cost of 3 Magic Points. The monster's health is now 1.\n\nThen, cast the third spell to decrease the monster's health by 2, at the cost of 1 Magic Point. The monster's health is now -1.\n\nIn this way, we can win at the total cost of 4 Magic Points.\n\nSample Input 2\n\n100 6\n1 1\n2 3\n3 9\n4 27\n5 81\n6 243\n\nSample Output 2\n\n100\n\nIt is optimal to cast the first spell 100 times.\n\nSample Input 3\n\n9999 10\n540 7550\n691 9680\n700 9790\n510 7150\n415 5818\n551 7712\n587 8227\n619 8671\n588 8228\n176 2461\n\nSample Output 3\n\n139815", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 230, "memory_kb": 94696}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s855233254", "group_id": "codeNet:p02789", "input_text": "(defun acorwa (a b)\n (if (= a b)\n \"Yes\"\n \"No\"\n )\n )\n(princ (acorwa (read) (read)))", "language": "Lisp", "metadata": {"date": 1580043122, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02789.html", "problem_id": "p02789", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02789/input.txt", "sample_output_relpath": "derived/input_output/data/p02789/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02789/Lisp/s855233254.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s855233254", "user_id": "u606976120"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun acorwa (a b)\n (if (= a b)\n \"Yes\"\n \"No\"\n )\n )\n(princ (acorwa (read) (read)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi is participating in a programming contest, AXC001. He has just submitted his code to Problem A.\n\nThe problem has N test cases, all of which must be passed to get an AC verdict.\n\nTakahashi's submission has passed M cases out of the N test cases.\n\nDetermine whether Takahashi's submission gets an AC.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n0 \\leq M \\leq N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nIf Takahashi's submission gets an AC, print Yes; otherwise, print No.\n\nSample Input 1\n\n3 3\n\nSample Output 1\n\nYes\n\nAll three test cases have been passed, so his submission gets an AC.\n\nSample Input 2\n\n3 2\n\nSample Output 2\n\nNo\n\nOnly two out of the three test cases have been passed, so his submission does not get an AC.\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\nYes", "sample_input": "3 3\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02789", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi is participating in a programming contest, AXC001. He has just submitted his code to Problem A.\n\nThe problem has N test cases, all of which must be passed to get an AC verdict.\n\nTakahashi's submission has passed M cases out of the N test cases.\n\nDetermine whether Takahashi's submission gets an AC.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n0 \\leq M \\leq N\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\n\nOutput\n\nIf Takahashi's submission gets an AC, print Yes; otherwise, print No.\n\nSample Input 1\n\n3 3\n\nSample Output 1\n\nYes\n\nAll three test cases have been passed, so his submission gets an AC.\n\nSample Input 2\n\n3 2\n\nSample Output 2\n\nNo\n\nOnly two out of the three test cases have been passed, so his submission does not get an AC.\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\nYes", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 99, "cpu_time_ms": 8, "memory_kb": 3176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s665039825", "group_id": "codeNet:p02790", "input_text": ";; B - Comparing Strings\n\n(let ((a (read))\n (b (read)))\n (format t \"~{~a~}~%\" (loop repeat (max a b) collect (min a b))))", "language": "Lisp", "metadata": {"date": 1581873619, "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/s665039825.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s665039825", "user_id": "u227020436"}, "prompt_components": {"gold_output": "3333\n", "input_to_evaluate": ";; B - Comparing Strings\n\n(let ((a (read))\n (b (read)))\n (format t \"~{~a~}~%\" (loop repeat (max a b) collect (min a b))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 120, "memory_kb": 15844}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s453236227", "group_id": "codeNet:p02790", "input_text": "(defmacro put-ans (n v)\n `(princ (coerce (make-array ,n :initial-element ,v) 'string)))\n\n(let* ((a (read))\n (b (read))\n (a-char (char (write-to-string a) 0))\n (b-char (char (write-to-string b) 0)))\n (if (> a b)\n (put-ans a b-char)\n (put-ans b a-char)))\n", "language": "Lisp", "metadata": {"date": 1579638627, "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/s453236227.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s453236227", "user_id": "u631655863"}, "prompt_components": {"gold_output": "3333\n", "input_to_evaluate": "(defmacro put-ans (n v)\n `(princ (coerce (make-array ,n :initial-element ,v) 'string)))\n\n(let* ((a (read))\n (b (read))\n (a-char (char (write-to-string a) 0))\n (b-char (char (write-to-string b) 0)))\n (if (> a b)\n (put-ans a b-char)\n (put-ans b a-char)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 176, "memory_kb": 17508}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s807308421", "group_id": "codeNet:p02791", "input_text": "(defun solve (ps)\n (loop with tmp = -100000\n with count = 0\n for p in ps\n if (<= p current-min)\n do (setf current-min p)\n (incf count)\n finally (return count)))\n\n(defun answer (n lst)\n (if (= n 1)\n 1\n (drop lst)))\n\n(let* ((n (read))\n (ps (loop repeat n collect (read))))\n (format t \"~A~%\" (answer n ps)))\n", "language": "Lisp", "metadata": {"date": 1579469800, "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/s807308421.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s807308421", "user_id": "u425317134"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun solve (ps)\n (loop with tmp = -100000\n with count = 0\n for p in ps\n if (<= p current-min)\n do (setf current-min p)\n (incf count)\n finally (return count)))\n\n(defun answer (n lst)\n (if (= n 1)\n 1\n (drop lst)))\n\n(let* ((n (read))\n (ps (loop repeat n collect (read))))\n (format t \"~A~%\" (answer n ps)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 369, "cpu_time_ms": 440, "memory_kb": 61928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s300796073", "group_id": "codeNet:p02791", "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(lst)\n (labels((rec(i acc)\n (if (= i (length lst))\n acc\n (if (every (lambda (a) (<= (nth i lst) a)) (subseq lst 0 i))\n (rec (1+ i) (1+ acc))\n (rec (1+ i) acc)))))\n (rec 0 0)))\n(compile 'f)\n(let* ((line0 (read-line nil nil))\n (line (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (f line)))\n", "language": "Lisp", "metadata": {"date": 1579465443, "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/s300796073.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s300796073", "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 f(lst)\n (labels((rec(i acc)\n (if (= i (length lst))\n acc\n (if (every (lambda (a) (<= (nth i lst) a)) (subseq lst 0 i))\n (rec (1+ i) (1+ acc))\n (rec (1+ i) acc)))))\n (rec 0 0)))\n(compile 'f)\n(let* ((line0 (read-line nil nil))\n (line (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (f line)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 659, "cpu_time_ms": 2105, "memory_kb": 118640}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s715795856", "group_id": "codeNet:p02792", "input_text": "(let* ((n (read)))\n (princ (loop :for k :from 1 :upto n\n :sum (loop :for j :from 1 :upto n\n :count (and (= (floor k (expt 10 (floor (log k 10))))\n (mod j 10))\n (= (floor j (expt 10 (floor (log j 10))))\n (mod k 10)))))))", "language": "Lisp", "metadata": {"date": 1583811033, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02792.html", "problem_id": "p02792", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02792/input.txt", "sample_output_relpath": "derived/input_output/data/p02792/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02792/Lisp/s715795856.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s715795856", "user_id": "u610490393"}, "prompt_components": {"gold_output": "17\n", "input_to_evaluate": "(let* ((n (read)))\n (princ (loop :for k :from 1 :upto n\n :sum (loop :for j :from 1 :upto n\n :count (and (= (floor k (expt 10 (floor (log k 10))))\n (mod j 10))\n (= (floor j (expt 10 (floor (log j 10))))\n (mod k 10)))))))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven is a positive integer N.\n\nFind the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:\n\nWhen A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.\n\nConstraints\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\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n25\n\nSample Output 1\n\n17\n\nThe following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100\n\nSample Output 3\n\n108\n\nSample Input 4\n\n2020\n\nSample Output 4\n\n40812\n\nSample Input 5\n\n200000\n\nSample Output 5\n\n400000008", "sample_input": "25\n"}, "reference_outputs": ["17\n"], "source_document_id": "p02792", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven is a positive integer N.\n\nFind the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:\n\nWhen A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.\n\nConstraints\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\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n25\n\nSample Output 1\n\n17\n\nThe following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100\n\nSample Output 3\n\n108\n\nSample Input 4\n\n2020\n\nSample Output 4\n\n40812\n\nSample Input 5\n\n200000\n\nSample Output 5\n\n400000008", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 376, "cpu_time_ms": 2105, "memory_kb": 59748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s604162683", "group_id": "codeNet:p02792", "input_text": "(defparameter N (read))\n(defparameter matrix\n (make-array '(9 9)))\n\n(defun convert (num)\n (let* ((s-num (write-to-string num))\n (a (aref s-num 0))\n (b (aref s-num (1- (length s-num)))))\n (cons (digit-char-p a)\n (digit-char-p b))))\n\n(defun calc-matrix (num M)\n (loop for i from 1 to num\n if (not (zerop (mod i 10)))\n do (let ((pair (convert i)))\n (incf (aref M \n (1- (car pair))\n (1- (cdr pair)))))\n finally (return M)))\n\n(defun answer (M)\n (loop with a = 0\n \t\tfor i from 0 below 9\n do (loop for j from 0 below 9\n do (setf a (+ a (* (aref M i j)\n (aref M j i)))))\n finally (return a)))\n\n(format t \"~A\" (answer (calc-matrix N matrix)))\n", "language": "Lisp", "metadata": {"date": 1579476332, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02792.html", "problem_id": "p02792", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02792/input.txt", "sample_output_relpath": "derived/input_output/data/p02792/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02792/Lisp/s604162683.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s604162683", "user_id": "u425317134"}, "prompt_components": {"gold_output": "17\n", "input_to_evaluate": "(defparameter N (read))\n(defparameter matrix\n (make-array '(9 9)))\n\n(defun convert (num)\n (let* ((s-num (write-to-string num))\n (a (aref s-num 0))\n (b (aref s-num (1- (length s-num)))))\n (cons (digit-char-p a)\n (digit-char-p b))))\n\n(defun calc-matrix (num M)\n (loop for i from 1 to num\n if (not (zerop (mod i 10)))\n do (let ((pair (convert i)))\n (incf (aref M \n (1- (car pair))\n (1- (cdr pair)))))\n finally (return M)))\n\n(defun answer (M)\n (loop with a = 0\n \t\tfor i from 0 below 9\n do (loop for j from 0 below 9\n do (setf a (+ a (* (aref M i j)\n (aref M j i)))))\n finally (return a)))\n\n(format t \"~A\" (answer (calc-matrix N matrix)))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven is a positive integer N.\n\nFind the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:\n\nWhen A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.\n\nConstraints\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\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n25\n\nSample Output 1\n\n17\n\nThe following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100\n\nSample Output 3\n\n108\n\nSample Input 4\n\n2020\n\nSample Output 4\n\n40812\n\nSample Input 5\n\n200000\n\nSample Output 5\n\n400000008", "sample_input": "25\n"}, "reference_outputs": ["17\n"], "source_document_id": "p02792", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven is a positive integer N.\n\nFind the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:\n\nWhen A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.\n\nConstraints\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\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n25\n\nSample Output 1\n\n17\n\nThe following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).\n\nSample Input 2\n\n1\n\nSample Output 2\n\n1\n\nSample Input 3\n\n100\n\nSample Output 3\n\n108\n\nSample Input 4\n\n2020\n\nSample Output 4\n\n40812\n\nSample Input 5\n\n200000\n\nSample Output 5\n\n400000008", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 831, "cpu_time_ms": 275, "memory_kb": 67936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s387398775", "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;;; 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\n(defun mod-inverse (a)\n (declare #.OPT\n (uint31 a))\n (let ((a (mod a +mod+))\n (b +mod+)\n (u 1)\n (v 0))\n (declare (int32 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 +mod+))\n (if (< u 0)\n (+ u +mod+)\n u)))\n\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 :size 1000 :test #'eq)))\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 (declare (uint31 prime exp))\n (if (gethash prime lcm-table)\n (maxf (the uint31 (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 (the uint31 (mod-inverse 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": 1579475046, "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/s387398775.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s387398775", "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;;; 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\n(defun mod-inverse (a)\n (declare #.OPT\n (uint31 a))\n (let ((a (mod a +mod+))\n (b +mod+)\n (u 1)\n (v 0))\n (declare (int32 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 +mod+))\n (if (< u 0)\n (+ u +mod+)\n u)))\n\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 :size 1000 :test #'eq)))\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 (declare (uint31 prime exp))\n (if (gethash prime lcm-table)\n (maxf (the uint31 (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 (the uint31 (mod-inverse 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10951, "cpu_time_ms": 414, "memory_kb": 44260}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s690570543", "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)\n (list (- (car x) (cadr x))\n (1- (+ (car x) (cadr x)))))\n\n(defun check (lst)\n (let ((counter 0)\n (tmp -100000000))\n (loop for i from 0 below N\n do (if (< tmp (aref lst i 0))\n (progn \n (incf counter)\n (setf tmp (aref lst i 1))))\n finally (return counter))))\n\n\n(defparameter N (parse-integer (read-line)))\n(defparameter lst\n (make-array (list N 2)\n :initial-contents\n (sort (mapcar #'convert\n (loop for i from 0 below N\n collect (mapcar #'parse-integer\n (split \" \" (read-line)))))\n #'< :key #'cadr)))\n\n(format t \"~A\" (check lst))\n", "language": "Lisp", "metadata": {"date": 1579387293, "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/s690570543.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s690570543", "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)\n (list (- (car x) (cadr x))\n (1- (+ (car x) (cadr x)))))\n\n(defun check (lst)\n (let ((counter 0)\n (tmp -100000000))\n (loop for i from 0 below N\n do (if (< tmp (aref lst i 0))\n (progn \n (incf counter)\n (setf tmp (aref lst i 1))))\n finally (return counter))))\n\n\n(defparameter N (parse-integer (read-line)))\n(defparameter lst\n (make-array (list N 2)\n :initial-contents\n (sort (mapcar #'convert\n (loop for i from 0 below N\n collect (mapcar #'parse-integer\n (split \" \" (read-line)))))\n #'< :key #'cadr)))\n\n(format t \"~A\" (check lst))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1448, "cpu_time_ms": 523, "memory_kb": 74676}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s225971788", "group_id": "codeNet:p02796", "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 convert (x)\n (list (- (car x) (cadr x))\n (+ (car x) (cadr x) 1)))\n\n\n(defparameter N (parse-integer (read-line)))\n(defparameter lst\n (make-array (list N 2)\n :initial-contents\n (sort (mapcar #'convert\n (loop for i from 0 below N\n collect (mapcar #'parse-integer\n (split \" \" (read-line)))))\n #'< :key #'car)))\n\n(defun check (lst count)\n (loop for i from 1 below N\n do (if (> (aref lst (1- i) 1)\n (aref lst i 0))\n (incf count))\n finally (return count)))\n\n(format t \"~A\" (check lst 1))\n", "language": "Lisp", "metadata": {"date": 1579385576, "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/s225971788.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s225971788", "user_id": "u425317134"}, "prompt_components": {"gold_output": "3\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 convert (x)\n (list (- (car x) (cadr x))\n (+ (car x) (cadr x) 1)))\n\n\n(defparameter N (parse-integer (read-line)))\n(defparameter lst\n (make-array (list N 2)\n :initial-contents\n (sort (mapcar #'convert\n (loop for i from 0 below N\n collect (mapcar #'parse-integer\n (split \" \" (read-line)))))\n #'< :key #'car)))\n\n(defun check (lst count)\n (loop for i from 1 below N\n do (if (> (aref lst (1- i) 1)\n (aref lst i 0))\n (incf count))\n finally (return count)))\n\n(format t \"~A\" (check lst 1))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 890, "cpu_time_ms": 493, "memory_kb": 71268}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s368492545", "group_id": "codeNet:p02796", "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 convert (x)\n (list (- (car x) (cadr x))\n (+ (car x) (cadr x) 1)))\n\n\n(defparameter N (parse-integer (read-line)))\n(defparameter lst\n (make-array (list N 1)\n :initial-contents\n (sort (mapcar #'convert\n (loop for i from 0 below N\n collect (mapcar #'parse-integer\n (split \" \" (read-line)))))\n #'< :key #'car)))\n\n(defun check (lst count)\n (loop for i from 1 below N\n do (if (> (aref lst (1- i) 1)\n (aref lst i 0))\n (incf count))\n finally (return count)))\n\n(format t \"~A\" (check lst 1))", "language": "Lisp", "metadata": {"date": 1579385381, "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/s368492545.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s368492545", "user_id": "u425317134"}, "prompt_components": {"gold_output": "3\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 convert (x)\n (list (- (car x) (cadr x))\n (+ (car x) (cadr x) 1)))\n\n\n(defparameter N (parse-integer (read-line)))\n(defparameter lst\n (make-array (list N 1)\n :initial-contents\n (sort (mapcar #'convert\n (loop for i from 0 below N\n collect (mapcar #'parse-integer\n (split \" \" (read-line)))))\n #'< :key #'car)))\n\n(defun check (lst count)\n (loop for i from 1 below N\n do (if (> (aref lst (1- i) 1)\n (aref lst i 0))\n (incf count))\n finally (return count)))\n\n(format t \"~A\" (check lst 1))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 889, "cpu_time_ms": 2106, "memory_kb": 174692}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s204046892", "group_id": "codeNet:p02797", "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 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 (k (read))\n (s (read))\n (res (make-array n :element-type 'uint31)))\n (if (zerop k)\n (if (= s #.(expt 10 9))\n (fill res 1)\n (fill res #.(expt 10 9)))\n (if (= s #.(expt 10 9))\n (dotimes (i n)\n (if (< i k)\n (setf (aref res i) #.(expt 10 9))\n (setf (aref res i) 1)))\n (dotimes (i n)\n (if (< i k)\n (setf (aref res i) s)\n (setf (aref res i) #.(expt 10 9))))))\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 \"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 \"4 2 3\n\"\n \"1 2 3 4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3 100\n\"\n \"50 50 50 30 70\n\")))\n", "language": "Lisp", "metadata": {"date": 1579378578, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02797.html", "problem_id": "p02797", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02797/input.txt", "sample_output_relpath": "derived/input_output/data/p02797/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02797/Lisp/s204046892.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s204046892", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 2 3 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 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 (k (read))\n (s (read))\n (res (make-array n :element-type 'uint31)))\n (if (zerop k)\n (if (= s #.(expt 10 9))\n (fill res 1)\n (fill res #.(expt 10 9)))\n (if (= s #.(expt 10 9))\n (dotimes (i n)\n (if (< i k)\n (setf (aref res i) #.(expt 10 9))\n (setf (aref res i) 1)))\n (dotimes (i n)\n (if (< i k)\n (setf (aref res i) s)\n (setf (aref res i) #.(expt 10 9))))))\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 \"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 \"4 2 3\n\"\n \"1 2 3 4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3 100\n\"\n \"50 50 50 30 70\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven are three integers N, K, and S.\n\nFind a sequence A_1, A_2, ..., A_N of N integers between 1 and 10^9 (inclusive) that satisfies the condition below.\nWe can prove that, under the conditions in Constraints, such a sequence always exists.\n\nThere are exactly K pairs (l, r) of integers such that 1 \\leq l \\leq r \\leq N and A_l + A_{l + 1} + \\cdots + A_r = S.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n0 \\leq K \\leq N\n\n1 \\leq S \\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 S\n\nOutput\n\nPrint a sequence satisfying the condition, in the following format:\n\nA_1 A_2 ... A_N\n\nSample Input 1\n\n4 2 3\n\nSample Output 1\n\n1 2 3 4\n\nTwo pairs (l, r) = (1, 2) and (3, 3) satisfy the condition in the statement.\n\nSample Input 2\n\n5 3 100\n\nSample Output 2\n\n50 50 50 30 70", "sample_input": "4 2 3\n"}, "reference_outputs": ["1 2 3 4\n"], "source_document_id": "p02797", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven are three integers N, K, and S.\n\nFind a sequence A_1, A_2, ..., A_N of N integers between 1 and 10^9 (inclusive) that satisfies the condition below.\nWe can prove that, under the conditions in Constraints, such a sequence always exists.\n\nThere are exactly K pairs (l, r) of integers such that 1 \\leq l \\leq r \\leq N and A_l + A_{l + 1} + \\cdots + A_r = S.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n0 \\leq K \\leq N\n\n1 \\leq S \\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 S\n\nOutput\n\nPrint a sequence satisfying the condition, in the following format:\n\nA_1 A_2 ... A_N\n\nSample Input 1\n\n4 2 3\n\nSample Output 1\n\n1 2 3 4\n\nTwo pairs (l, r) = (1, 2) and (3, 3) satisfy the condition in the statement.\n\nSample Input 2\n\n5 3 100\n\nSample Output 2\n\n50 50 50 30 70", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4573, "cpu_time_ms": 233, "memory_kb": 24416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s151437953", "group_id": "codeNet:p02799", "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 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 (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 (inline sort))\n (let* ((n (read))\n (m (read))\n (ds (make-array n :element-type 'uint31))\n ;; d(u) <= d(v) for (u v . idx)\n (edges (make-array m :element-type 'list))\n (graph (make-array n :element-type 'list :initial-element nil))\n (cols (make-array n :element-type 'int32 :initial-element -1))\n (weights (make-array m :element-type 'int32 :initial-element -1)))\n (dotimes (i n)\n (setf (aref ds i) (read-fixnum)))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (when (> (aref ds u) (aref ds v))\n (rotatef u v))\n (setf (aref edges i) (list u v i))\n (push u (aref graph v))\n (push v (aref graph u))))\n (setq edges\n (sort edges\n (lambda (e1 e2)\n (let ((max-d1 (aref ds (second e1)))\n (max-d2 (aref ds (second e2))))\n (or (< max-d1 max-d2)\n (and (= max-d1 max-d2)\n (< (the uint31 (third e1))\n (the uint31 (third e2)))))))))\n #>graph\n (unless (loop\n for v below n\n always (loop\n for neighbor in (aref graph v)\n thereis (>= (aref ds v) (aref ds neighbor))))\n (println -1)\n (return-from main))\n (dotimes (i m)\n ;; d(u) <= d(v)\n (destructuring-bind (u v idx) (aref edges i)\n (cond ((= -1 (aref cols u) (aref cols v))\n (assert (= (aref ds u) (aref ds v)))\n (setf (aref cols u) 0\n (aref cols v) 1)\n (setf (aref weights idx) (aref ds v)))\n ((= -1 (aref cols u))\n (setf (aref cols u) (logxor 1 (aref cols v)))\n (setf (aref weights idx) (aref ds v)))\n ((= -1 (aref cols v))\n (setf (aref cols v) (logxor 1 (aref cols u)))\n (setf (aref weights idx) (aref ds v)))\n (t\n (setf (aref weights idx) #.(expt 10 9))))))\n (with-buffered-stdout\n (sb-int:dovector (col cols (terpri))\n (write-char (if (zerop col) #\\W #\\B)))\n (dotimes (i m)\n (println (aref weights 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 \"5 5\n3 4 3 5 7\n1 2\n1 3\n3 2\n4 2\n4 5\n\"\n \"BWWBB\n4\n3\n1\n5\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 7\n1 2 3 4 5\n1 2\n1 3\n1 4\n2 3\n2 5\n3 5\n4 5\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 6\n1 1 1 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\"\n \"BBBW\n1\n1\n1\n2\n1\n1\n\")))\n", "language": "Lisp", "metadata": {"date": 1579460239, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02799.html", "problem_id": "p02799", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02799/input.txt", "sample_output_relpath": "derived/input_output/data/p02799/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02799/Lisp/s151437953.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s151437953", "user_id": "u352600849"}, "prompt_components": {"gold_output": "BWWBB\n4\n3\n1\n5\n2\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 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 (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 (inline sort))\n (let* ((n (read))\n (m (read))\n (ds (make-array n :element-type 'uint31))\n ;; d(u) <= d(v) for (u v . idx)\n (edges (make-array m :element-type 'list))\n (graph (make-array n :element-type 'list :initial-element nil))\n (cols (make-array n :element-type 'int32 :initial-element -1))\n (weights (make-array m :element-type 'int32 :initial-element -1)))\n (dotimes (i n)\n (setf (aref ds i) (read-fixnum)))\n (dotimes (i m)\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (when (> (aref ds u) (aref ds v))\n (rotatef u v))\n (setf (aref edges i) (list u v i))\n (push u (aref graph v))\n (push v (aref graph u))))\n (setq edges\n (sort edges\n (lambda (e1 e2)\n (let ((max-d1 (aref ds (second e1)))\n (max-d2 (aref ds (second e2))))\n (or (< max-d1 max-d2)\n (and (= max-d1 max-d2)\n (< (the uint31 (third e1))\n (the uint31 (third e2)))))))))\n #>graph\n (unless (loop\n for v below n\n always (loop\n for neighbor in (aref graph v)\n thereis (>= (aref ds v) (aref ds neighbor))))\n (println -1)\n (return-from main))\n (dotimes (i m)\n ;; d(u) <= d(v)\n (destructuring-bind (u v idx) (aref edges i)\n (cond ((= -1 (aref cols u) (aref cols v))\n (assert (= (aref ds u) (aref ds v)))\n (setf (aref cols u) 0\n (aref cols v) 1)\n (setf (aref weights idx) (aref ds v)))\n ((= -1 (aref cols u))\n (setf (aref cols u) (logxor 1 (aref cols v)))\n (setf (aref weights idx) (aref ds v)))\n ((= -1 (aref cols v))\n (setf (aref cols v) (logxor 1 (aref cols u)))\n (setf (aref weights idx) (aref ds v)))\n (t\n (setf (aref weights idx) #.(expt 10 9))))))\n (with-buffered-stdout\n (sb-int:dovector (col cols (terpri))\n (write-char (if (zerop col) #\\W #\\B)))\n (dotimes (i m)\n (println (aref weights 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 \"5 5\n3 4 3 5 7\n1 2\n1 3\n3 2\n4 2\n4 5\n\"\n \"BWWBB\n4\n3\n1\n5\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 7\n1 2 3 4 5\n1 2\n1 3\n1 4\n2 3\n2 5\n3 5\n4 5\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 6\n1 1 1 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\"\n \"BBBW\n1\n1\n1\n2\n1\n1\n\")))\n", "problem_context": "Score : 900 points\n\nProblem Statement\n\nWe have a connected undirected graph with N vertices and M edges.\nEdge i in this graph (1 \\leq i \\leq M) connects Vertex U_i and Vertex V_i bidirectionally.\nWe are additionally given N integers D_1, D_2, ..., D_N.\n\nDetermine whether the conditions below can be satisfied by assigning a color - white or black - to each vertex and an integer weight between 1 and 10^9 (inclusive) to each edge in this graph.\nIf the answer is yes, find one such assignment of colors and integers, too.\n\nThere is at least one vertex assigned white and at least one vertex assigned black.\n\nFor each vertex v (1 \\leq v \\leq N), the following holds.\n\nThe minimum cost to travel from Vertex v to a vertex whose color assigned is different from that of Vertex v by traversing the edges is equal to D_v.\n\nHere, the cost of traversing the edges is the sum of the weights of the edges traversed.\n\nConstraints\n\n2 \\leq N \\leq 100,000\n\n1 \\leq M \\leq 200,000\n\n1 \\leq D_i \\leq 10^9\n\n1 \\leq U_i, V_i \\leq N\n\nThe given graph is connected and has no self-loops or multiple edges.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nD_1 D_2 ... D_N\nU_1 V_1\nU_2 V_2\n\\vdots\nU_M V_M\n\nOutput\n\nIf there is no assignment satisfying the conditions, print a single line containing -1.\n\nIf such an assignment exists, print one such assignment in the following format:\n\nS\nC_1\nC_2\n\\vdots\nC_M\n\nHere,\n\nthe first line should contain the string S of length N. Its i-th character (1 \\leq i \\leq N) should be W if Vertex i is assigned white and B if it is assigned black.\n\nThe (i + 1)-th line (1 \\leq i \\leq M) should contain the integer weight C_i assigned to Edge i.\n\nSample Input 1\n\n5 5\n3 4 3 5 7\n1 2\n1 3\n3 2\n4 2\n4 5\n\nSample Output 1\n\nBWWBB\n4\n3\n1\n5\n2\n\nAssume that we assign the colors and integers as the sample output, and let us consider Vertex 5, for example. To travel from Vertex 5, which is assigned black, to a vertex that is assigned white with the minimum cost, we should make these moves: Vertex 5 \\to Vertex 4 \\to Vertex 2. The total cost of these moves is 7, which satisfies the condition. We can also verify that the condition is satisfied for other vertices.\n\nSample Input 2\n\n5 7\n1 2 3 4 5\n1 2\n1 3\n1 4\n2 3\n2 5\n3 5\n4 5\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n4 6\n1 1 1 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\nSample Output 3\n\nBBBW\n1\n1\n1\n2\n1\n1", "sample_input": "5 5\n3 4 3 5 7\n1 2\n1 3\n3 2\n4 2\n4 5\n"}, "reference_outputs": ["BWWBB\n4\n3\n1\n5\n2\n"], "source_document_id": "p02799", "source_text": "Score : 900 points\n\nProblem Statement\n\nWe have a connected undirected graph with N vertices and M edges.\nEdge i in this graph (1 \\leq i \\leq M) connects Vertex U_i and Vertex V_i bidirectionally.\nWe are additionally given N integers D_1, D_2, ..., D_N.\n\nDetermine whether the conditions below can be satisfied by assigning a color - white or black - to each vertex and an integer weight between 1 and 10^9 (inclusive) to each edge in this graph.\nIf the answer is yes, find one such assignment of colors and integers, too.\n\nThere is at least one vertex assigned white and at least one vertex assigned black.\n\nFor each vertex v (1 \\leq v \\leq N), the following holds.\n\nThe minimum cost to travel from Vertex v to a vertex whose color assigned is different from that of Vertex v by traversing the edges is equal to D_v.\n\nHere, the cost of traversing the edges is the sum of the weights of the edges traversed.\n\nConstraints\n\n2 \\leq N \\leq 100,000\n\n1 \\leq M \\leq 200,000\n\n1 \\leq D_i \\leq 10^9\n\n1 \\leq U_i, V_i \\leq N\n\nThe given graph is connected and has no self-loops or multiple edges.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nD_1 D_2 ... D_N\nU_1 V_1\nU_2 V_2\n\\vdots\nU_M V_M\n\nOutput\n\nIf there is no assignment satisfying the conditions, print a single line containing -1.\n\nIf such an assignment exists, print one such assignment in the following format:\n\nS\nC_1\nC_2\n\\vdots\nC_M\n\nHere,\n\nthe first line should contain the string S of length N. Its i-th character (1 \\leq i \\leq N) should be W if Vertex i is assigned white and B if it is assigned black.\n\nThe (i + 1)-th line (1 \\leq i \\leq M) should contain the integer weight C_i assigned to Edge i.\n\nSample Input 1\n\n5 5\n3 4 3 5 7\n1 2\n1 3\n3 2\n4 2\n4 5\n\nSample Output 1\n\nBWWBB\n4\n3\n1\n5\n2\n\nAssume that we assign the colors and integers as the sample output, and let us consider Vertex 5, for example. To travel from Vertex 5, which is assigned black, to a vertex that is assigned white with the minimum cost, we should make these moves: Vertex 5 \\to Vertex 4 \\to Vertex 2. The total cost of these moves is 7, which satisfies the condition. We can also verify that the condition is satisfied for other vertices.\n\nSample Input 2\n\n5 7\n1 2 3 4 5\n1 2\n1 3\n1 4\n2 3\n2 5\n3 5\n4 5\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n4 6\n1 1 1 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\nSample Output 3\n\nBBBW\n1\n1\n1\n2\n1\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7756, "cpu_time_ms": 561, "memory_kb": 78568}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s985095712", "group_id": "codeNet:p02802", "input_text": "(let* ((n (read))\n (ac (make-hash-table :size n))\n (wa (make-hash-table :size n))\n (m (read))\n (ac-num 0)\n (wa-num 0))\n (loop :for i :from 1 :to m\n :for p := (read)\n :for s := (read-line)\n :unless (gethash p ac)\n :do (if (string= s \"AC\")\n (setf (gethash p ac) 1)\n (if (gethash p wa)\n (incf (gethash p wa))\n (setf (gethash p wa) 1))))\n (maphash (lambda (key val)\n (incf ac-num val)\n (incf wa-num (if (gethash key wa) (gethash key wa) 0)))\n ac)\n (format t \"~A ~A~%\" ac-num wa-num))\n", "language": "Lisp", "metadata": {"date": 1593715267, "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/s985095712.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s985095712", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(let* ((n (read))\n (ac (make-hash-table :size n))\n (wa (make-hash-table :size n))\n (m (read))\n (ac-num 0)\n (wa-num 0))\n (loop :for i :from 1 :to m\n :for p := (read)\n :for s := (read-line)\n :unless (gethash p ac)\n :do (if (string= s \"AC\")\n (setf (gethash p ac) 1)\n (if (gethash p wa)\n (incf (gethash p wa))\n (setf (gethash p wa) 1))))\n (maphash (lambda (key val)\n (incf ac-num val)\n (incf wa-num (if (gethash key wa) (gethash key wa) 0)))\n ac)\n (format t \"~A ~A~%\" ac-num wa-num))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 643, "cpu_time_ms": 163, "memory_kb": 77044}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s631026260", "group_id": "codeNet:p02802", "input_text": "(let* ((n (read))\n (c (make-hash-table :size n))\n (m (read))\n (ac 0)\n (wa 0))\n (loop :for i :from 1 :to m\n :for p := (read)\n :for s := (read-line)\n :unless (gethash p c)\n :do (cond ((string= s \"AC\")\n (setf (gethash p c) t)\n (incf ac))\n (t\n (incf wa))))\n (format t \"~A ~A~%\" ac wa))\n", "language": "Lisp", "metadata": {"date": 1593714662, "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/s631026260.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s631026260", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(let* ((n (read))\n (c (make-hash-table :size n))\n (m (read))\n (ac 0)\n (wa 0))\n (loop :for i :from 1 :to m\n :for p := (read)\n :for s := (read-line)\n :unless (gethash p c)\n :do (cond ((string= s \"AC\")\n (setf (gethash p c) t)\n (incf ac))\n (t\n (incf wa))))\n (format t \"~A ~A~%\" 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 407, "cpu_time_ms": 144, "memory_kb": 77076}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s324565393", "group_id": "codeNet:p02802", "input_text": "(defvar N (read))\n(defvar M (read))\n\n(defvar ac 0)\n(defvar wa 0)\n\n(defvar ac-array (make-array N :initial-element 0))\n(defvar wa-array (make-array N :initial-element 0))\n\n(defun calc ()\n (let ((No (1- (read)))\n (Ans (read)))\n (cond ((string= Ans \"AC\")\n (when (zerop (aref ac-array No))\n (setq wa (+ wa (aref wa-array No)))\n (incf (aref ac-array No))\n (incf ac)))\n ((string= Ans \"WA\")\n (when (zerop (aref ac-array No))\n (incf (aref wa-array No)))))\n (decf M)\n (if (= M 0)\n (format t \"~D ~D~%\" ac wa)\n (calc))))\n\n(calc)\n", "language": "Lisp", "metadata": {"date": 1578972382, "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/s324565393.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s324565393", "user_id": "u631655863"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(defvar N (read))\n(defvar M (read))\n\n(defvar ac 0)\n(defvar wa 0)\n\n(defvar ac-array (make-array N :initial-element 0))\n(defvar wa-array (make-array N :initial-element 0))\n\n(defun calc ()\n (let ((No (1- (read)))\n (Ans (read)))\n (cond ((string= Ans \"AC\")\n (when (zerop (aref ac-array No))\n (setq wa (+ wa (aref wa-array No)))\n (incf (aref ac-array No))\n (incf ac)))\n ((string= Ans \"WA\")\n (when (zerop (aref ac-array No))\n (incf (aref wa-array No)))))\n (decf M)\n (if (= M 0)\n (format t \"~D ~D~%\" ac wa)\n (calc))))\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 626, "cpu_time_ms": 369, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s541089969", "group_id": "codeNet:p02802", "input_text": "(defun read-string () ;スペース区切りstring入力\n (let* ((str (read-line)))\n (labels ((instring (instring-str rt)\n (let* ((pos (position #\\Space instring-str :test #'char=)))\n (if pos\n (instring (subseq instring-str (1+ pos))\n (cons (subseq instring-str 0 pos) rt))\n (cons instring-str rt)))))\n (reverse (instring str nil)))))\n\n(let* ((n (read))\n (m (read))\n (lst (mapcar (lambda (k) (list (parse-integer (first k))\n (second k)))\n (loop :repeat m :collect (read-string))))\n (arr (make-array (list (1+ n) 2) :initial-element 0 :element-type 'fixnum)))\n (mapcar (lambda (k) (if (string= (second k) \"AC\")\n (setf (aref arr (first k) 1) 1)\n (if (= (aref arr (first k) 1) 0)\n (incf (aref arr (first k) 0))))) lst)\n (format t \"~A ~A\" (loop :for k :from 1 :upto n :count (= (aref arr k 1) 1))\n (loop :for k :from 1 :upto n :sum (if (= (aref arr k 1) 1) (aref arr k 0) 0))))\n", "language": "Lisp", "metadata": {"date": 1578886276, "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/s541089969.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s541089969", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(defun read-string () ;スペース区切りstring入力\n (let* ((str (read-line)))\n (labels ((instring (instring-str rt)\n (let* ((pos (position #\\Space instring-str :test #'char=)))\n (if pos\n (instring (subseq instring-str (1+ pos))\n (cons (subseq instring-str 0 pos) rt))\n (cons instring-str rt)))))\n (reverse (instring str nil)))))\n\n(let* ((n (read))\n (m (read))\n (lst (mapcar (lambda (k) (list (parse-integer (first k))\n (second k)))\n (loop :repeat m :collect (read-string))))\n (arr (make-array (list (1+ n) 2) :initial-element 0 :element-type 'fixnum)))\n (mapcar (lambda (k) (if (string= (second k) \"AC\")\n (setf (aref arr (first k) 1) 1)\n (if (= (aref arr (first k) 1) 0)\n (incf (aref arr (first k) 0))))) lst)\n (format t \"~A ~A\" (loop :for k :from 1 :upto n :count (= (aref arr k 1) 1))\n (loop :for k :from 1 :upto n :sum (if (= (aref arr k 1) 1) (aref arr k 0) 0))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1159, "cpu_time_ms": 228, "memory_kb": 72160}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s139278055", "group_id": "codeNet:p02802", "input_text": "(let* ((n (read))\n (m (read))\n (lst (mapcar (lambda (k) (list (parse-integer (first k))\n (second k)))\n (loop :repeat m :collect (read-string))))\n (arr (make-array (list (1+ n) 2) :initial-element 0 :element-type 'fixnum)))\n (mapcar (lambda (k) (if (string= (second k) \"AC\")\n (setf (aref arr (first k) 1) 1)\n (if (= (aref arr (first k) 1) 0)\n (incf (aref arr (first k) 0))))) lst)\n (format t \"~A ~A\" (loop :for k :from 1 :upto n :count (= (aref arr k 1) 1))\n (loop :for k :from 1 :upto n :sum (aref arr k 0))))", "language": "Lisp", "metadata": {"date": 1578886141, "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/s139278055.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s139278055", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst (mapcar (lambda (k) (list (parse-integer (first k))\n (second k)))\n (loop :repeat m :collect (read-string))))\n (arr (make-array (list (1+ n) 2) :initial-element 0 :element-type 'fixnum)))\n (mapcar (lambda (k) (if (string= (second k) \"AC\")\n (setf (aref arr (first k) 1) 1)\n (if (= (aref arr (first k) 1) 0)\n (incf (aref arr (first k) 0))))) lst)\n (format t \"~A ~A\" (loop :for k :from 1 :upto n :count (= (aref arr k 1) 1))\n (loop :for k :from 1 :upto n :sum (aref arr k 0))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 685, "cpu_time_ms": 167, "memory_kb": 20580}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s378379039", "group_id": "codeNet:p02803", "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\n\n;;; Body\n\n\n(defparameter *default-deque-size* 100)\n\n(defstruct deque\n (data nil)\n (size nil)\n (head 0)\n (tail 0)\n (count 0))\n\n\n(defun deque-create (&optional (size *default-deque-size*))\n (make-deque\n :size size\n :data (make-array size)))\n\n\n\n(defmethod deque-clear ((d deque))\n (fill (deque-data d) 0)\n (setf (deque-size d) 0)\n (setf (deque-head d) 0)\n (setf (deque-tail d) 0)\n (setf (deque-count d) 0))\n\n;; Subcommand\n\n(declaim (inline deque-empty-p\n deque-full-p\n deque-get-prev-index\n deque-get-next-index))\n\n\n(defmethod deque-empty-p ((d deque))\n (zerop (deque-count d)))\n\n\n\n(defmethod deque-full-p ((d deque))\n (= (deque-count d) (deque-size d)))\n\n(defmethod deque-get-prev-index ((d deque) idx)\n (declare (inline deque-get-next-index))\n (if (zerop idx)\n (1- (deque-size d))\n (1- idx)))\n\n(defmethod deque-get-next-index ((d deque) idx)\n (rem (1+ idx) (deque-size d)))\n\n\n\n\n;;; Main command\n\n(defmethod deque-pushfront ((d deque) item)\n (when (deque-full-p d)\n (error \"deque is full\"))\n\n (setf (deque-head d) (deque-get-prev-index d (deque-head d)))\n (setf (aref (deque-data d) (deque-head d)) item)\n (when (deque-empty-p d) ; first insersion\n (setf (deque-tail d) (deque-head d)))\n (incf (deque-count d)))\n\n\n\n(defmethod deque-pushback ((d deque) item)\n (when (deque-full-p d)\n (error \"deque is full\"))\n \n (setf (deque-tail d) (deque-get-next-index d (deque-tail d)))\n (setf (aref (deque-data d) (deque-tail d)) item)\n (when (deque-empty-p d) ; first insersion\n (setf (deque-head d) (deque-tail d)))\n (incf (deque-count d)))\n\n\n(defmethod deque-popfront ((d deque))\n (when (deque-empty-p d)\n (error \"deque is empty,\"))\n \n (let ((value (aref (deque-data d) (deque-head d))))\n (setf (deque-head d) (deque-get-next-index d (deque-head d)))\n (decf (deque-count d))\n value))\n\n\n\n(defmethod deque-popback ((d deque))\n (when (deque-empty-p d)\n (error \"deque is empty,\"))\n \n (let ((value (aref (deque-data d) (deque-tail d))))\n (setf (deque-tail d) (deque-get-prev-index d (deque-tail d)))\n (decf (deque-count d))\n value))\n\n\n(defmethod dref ((d deque) subscripts)\n (let ((arr (deque-data d))\n (size (deque-size d))\n (head (deque-head d)))\n (aref arr (mod (+ subscripts\n head)\n size))))\n\n\n(defparameter *inf* 1000000)\n\n(defparameter *dy-dx* '((1 . 0)\n (-1 . 0)\n (0 . 1)\n (0 . -1)))\n\n(defun bfs (sy sx h w board)\n (declare (fixnum sy sx h w)\n (array board))\n (the fixnum\n (let ((q (deque-create)))\n (deque-pushback q (cons sy sx))\n (setf (aref board sy sx) 0)\n (loop until (deque-empty-p q) do\n (let ((pos (deque-popfront q)))\n (loop for d in *dy-dx* do\n (let ((ny (+ (first pos) (first d)))\n (nx (+ (rest pos) (rest d))))\n (when (and (<= 0 ny (1- h))\n (<= 0 nx (1- w))\n (= (aref board ny nx) *inf*))\n (deque-pushback q (cons ny nx))\n (setf (aref board ny nx)\n (1+ (aref board (first pos) (rest pos))))))))\n finally\n (let ((cand -1))\n (declare (fixnum cand))\n (dotimes (y h)\n (dotimes (x w)\n (when (and (/= (aref board y x) -1)\n (/= (aref board y x) *inf*))\n (setf cand (max cand\n (aref board y x))))))\n (assert (plusp cand))\n (return cand))))))\n\n(defun solve (h w board)\n (let ((res -1))\n (dotimes (i h)\n (dotimes (j w)\n (when (= (aref board i j) *inf*)\n (setf res (max res\n (bfs i j h w board))))))\n res))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((h (read))\n (w (read))\n tmp)\n (let ((board (make-array `(,h ,w) :element-type 'fixnum)))\n (loop for y below h do\n (loop for x below w do\n (setf tmp (read-char))\n (if (char-equal tmp #\\.)\n (setf (aref board y x) *inf*)\n (setf (aref board y x) -1))))\n (format t \"~a~&\" (solve h w board)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1599415393, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s378379039.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s378379039", "user_id": "u425762225"}, "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 :fiveam))\n (shadow :run)\n (use-package :fiveam)))\n#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)\n\n\n\n;;; Body\n\n\n(defparameter *default-deque-size* 100)\n\n(defstruct deque\n (data nil)\n (size nil)\n (head 0)\n (tail 0)\n (count 0))\n\n\n(defun deque-create (&optional (size *default-deque-size*))\n (make-deque\n :size size\n :data (make-array size)))\n\n\n\n(defmethod deque-clear ((d deque))\n (fill (deque-data d) 0)\n (setf (deque-size d) 0)\n (setf (deque-head d) 0)\n (setf (deque-tail d) 0)\n (setf (deque-count d) 0))\n\n;; Subcommand\n\n(declaim (inline deque-empty-p\n deque-full-p\n deque-get-prev-index\n deque-get-next-index))\n\n\n(defmethod deque-empty-p ((d deque))\n (zerop (deque-count d)))\n\n\n\n(defmethod deque-full-p ((d deque))\n (= (deque-count d) (deque-size d)))\n\n(defmethod deque-get-prev-index ((d deque) idx)\n (declare (inline deque-get-next-index))\n (if (zerop idx)\n (1- (deque-size d))\n (1- idx)))\n\n(defmethod deque-get-next-index ((d deque) idx)\n (rem (1+ idx) (deque-size d)))\n\n\n\n\n;;; Main command\n\n(defmethod deque-pushfront ((d deque) item)\n (when (deque-full-p d)\n (error \"deque is full\"))\n\n (setf (deque-head d) (deque-get-prev-index d (deque-head d)))\n (setf (aref (deque-data d) (deque-head d)) item)\n (when (deque-empty-p d) ; first insersion\n (setf (deque-tail d) (deque-head d)))\n (incf (deque-count d)))\n\n\n\n(defmethod deque-pushback ((d deque) item)\n (when (deque-full-p d)\n (error \"deque is full\"))\n \n (setf (deque-tail d) (deque-get-next-index d (deque-tail d)))\n (setf (aref (deque-data d) (deque-tail d)) item)\n (when (deque-empty-p d) ; first insersion\n (setf (deque-head d) (deque-tail d)))\n (incf (deque-count d)))\n\n\n(defmethod deque-popfront ((d deque))\n (when (deque-empty-p d)\n (error \"deque is empty,\"))\n \n (let ((value (aref (deque-data d) (deque-head d))))\n (setf (deque-head d) (deque-get-next-index d (deque-head d)))\n (decf (deque-count d))\n value))\n\n\n\n(defmethod deque-popback ((d deque))\n (when (deque-empty-p d)\n (error \"deque is empty,\"))\n \n (let ((value (aref (deque-data d) (deque-tail d))))\n (setf (deque-tail d) (deque-get-prev-index d (deque-tail d)))\n (decf (deque-count d))\n value))\n\n\n(defmethod dref ((d deque) subscripts)\n (let ((arr (deque-data d))\n (size (deque-size d))\n (head (deque-head d)))\n (aref arr (mod (+ subscripts\n head)\n size))))\n\n\n(defparameter *inf* 1000000)\n\n(defparameter *dy-dx* '((1 . 0)\n (-1 . 0)\n (0 . 1)\n (0 . -1)))\n\n(defun bfs (sy sx h w board)\n (declare (fixnum sy sx h w)\n (array board))\n (the fixnum\n (let ((q (deque-create)))\n (deque-pushback q (cons sy sx))\n (setf (aref board sy sx) 0)\n (loop until (deque-empty-p q) do\n (let ((pos (deque-popfront q)))\n (loop for d in *dy-dx* do\n (let ((ny (+ (first pos) (first d)))\n (nx (+ (rest pos) (rest d))))\n (when (and (<= 0 ny (1- h))\n (<= 0 nx (1- w))\n (= (aref board ny nx) *inf*))\n (deque-pushback q (cons ny nx))\n (setf (aref board ny nx)\n (1+ (aref board (first pos) (rest pos))))))))\n finally\n (let ((cand -1))\n (declare (fixnum cand))\n (dotimes (y h)\n (dotimes (x w)\n (when (and (/= (aref board y x) -1)\n (/= (aref board y x) *inf*))\n (setf cand (max cand\n (aref board y x))))))\n (assert (plusp cand))\n (return cand))))))\n\n(defun solve (h w board)\n (let ((res -1))\n (dotimes (i h)\n (dotimes (j w)\n (when (= (aref board i j) *inf*)\n (setf res (max res\n (bfs i j h w board))))))\n res))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((h (read))\n (w (read))\n tmp)\n (let ((board (make-array `(,h ,w) :element-type 'fixnum)))\n (loop for y below h do\n (loop for x below w do\n (setf tmp (read-char))\n (if (char-equal tmp #\\.)\n (setf (aref board y x) *inf*)\n (setf (aref board y x) -1))))\n (format t \"~a~&\" (solve h w board)))))\n\n#-swank (main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4826, "cpu_time_ms": 35, "memory_kb": 31908}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s458355447", "group_id": "codeNet:p02803", "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(require 'sb-queue)\n\n(defun get-shortest (h w map start-x start-y)\n (let ((q (sb-queue:make-queue :initial-contents (list (list start-x start-y 0)))))\n (loop until (sb-queue:queue-empty-p q)\n for (x y score) = (sb-queue:dequeue q)\n for next-score = (1+ score)\n do (progn\n (setf (aref map y x) score)\n ;; left\n (when (and (<= 0 (1- x))\n (zerop (aref map y (1- x)))\n (or (/= y start-y)\n (/= (1- x) start-x)))\n (sb-queue:enqueue (list (1- x) y next-score) q))\n ;; up\n (when (and (<= 0 (1- y))\n (zerop (aref map (1- y) x))\n (or (/= (1- y) start-y)\n (/= x start-x)))\n (sb-queue:enqueue (list x (1- y) next-score) q))\n ;; right\n (when (and (< (1+ x) w)\n (zerop (aref map y (1+ x)))\n (or (/= y start-y)\n (/= (1+ x) start-x)))\n (sb-queue:enqueue (list (1+ x) y next-score) q))\n ;; down\n (when (and (< (1+ y) h)\n (zerop (aref map (1+ y) x))\n (or (/= (1+ y) start-y)\n (/= x start-x)))\n (sb-queue:enqueue (list x (1+ y) next-score) q)))))\n (prog1\n (loop for y from 0 below h\n maximize (loop for x from 0 below w\n if (or (= x 0)\n (= x (1- w))\n (= y 0)\n (= y (1- h)))\n maximize (aref map y x)))\n (reset-map h w map)))\n\n(defun solve (h w map)\n (loop for y from 0 below h\n maximize (loop for x from 0 below w\n if (and (or (= x 0)\n (= x (1- w))\n (= y 0)\n (= y (1- h)))\n (/= -1 (aref map y x)))\n maximize (get-shortest h w map x y))))\n\n(defun reset-map (h w map)\n (loop for y from 0 below h\n do (loop for x from 0 below w\n if (/= -1 (aref map y x))\n do (setf (aref map y x) 0))))\n\n#-swank\n(let* ((h (read))\n (w (read))\n (map (make-array (list h w) :element-type 'fixnum)))\n (loop for y from 0 below h\n do (loop for x from 0 below w\n for char = (read-char)\n do (setf (aref map y x)\n (if (char= char #\\.)\n 0\n -1)))\n do (read-char))\n (format t \"~A~%\" (solve h w map)))\n", "language": "Lisp", "metadata": {"date": 1578888737, "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/s458355447.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s458355447", "user_id": "u202886318"}, "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(require 'sb-queue)\n\n(defun get-shortest (h w map start-x start-y)\n (let ((q (sb-queue:make-queue :initial-contents (list (list start-x start-y 0)))))\n (loop until (sb-queue:queue-empty-p q)\n for (x y score) = (sb-queue:dequeue q)\n for next-score = (1+ score)\n do (progn\n (setf (aref map y x) score)\n ;; left\n (when (and (<= 0 (1- x))\n (zerop (aref map y (1- x)))\n (or (/= y start-y)\n (/= (1- x) start-x)))\n (sb-queue:enqueue (list (1- x) y next-score) q))\n ;; up\n (when (and (<= 0 (1- y))\n (zerop (aref map (1- y) x))\n (or (/= (1- y) start-y)\n (/= x start-x)))\n (sb-queue:enqueue (list x (1- y) next-score) q))\n ;; right\n (when (and (< (1+ x) w)\n (zerop (aref map y (1+ x)))\n (or (/= y start-y)\n (/= (1+ x) start-x)))\n (sb-queue:enqueue (list (1+ x) y next-score) q))\n ;; down\n (when (and (< (1+ y) h)\n (zerop (aref map (1+ y) x))\n (or (/= (1+ y) start-y)\n (/= x start-x)))\n (sb-queue:enqueue (list x (1+ y) next-score) q)))))\n (prog1\n (loop for y from 0 below h\n maximize (loop for x from 0 below w\n if (or (= x 0)\n (= x (1- w))\n (= y 0)\n (= y (1- h)))\n maximize (aref map y x)))\n (reset-map h w map)))\n\n(defun solve (h w map)\n (loop for y from 0 below h\n maximize (loop for x from 0 below w\n if (and (or (= x 0)\n (= x (1- w))\n (= y 0)\n (= y (1- h)))\n (/= -1 (aref map y x)))\n maximize (get-shortest h w map x y))))\n\n(defun reset-map (h w map)\n (loop for y from 0 below h\n do (loop for x from 0 below w\n if (/= -1 (aref map y x))\n do (setf (aref map y x) 0))))\n\n#-swank\n(let* ((h (read))\n (w (read))\n (map (make-array (list h w) :element-type 'fixnum)))\n (loop for y from 0 below h\n do (loop for x from 0 below w\n for char = (read-char)\n do (setf (aref map y x)\n (if (char= char #\\.)\n 0\n -1)))\n do (read-char))\n (format t \"~A~%\" (solve h w map)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3270, "cpu_time_ms": 2112, "memory_kb": 683508}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s440584317", "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(defun main ()\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)) :element-type 'uint32 :initial-element #xffffffff)))\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 (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 #xffffffff)\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": 1578882133, "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/s440584317.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s440584317", "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(defun main ()\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)) :element-type 'uint32 :initial-element #xffffffff)))\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 (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 #xffffffff)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 736, "memory_kb": 30176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s986687940", "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 (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": 1579339582, "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/s986687940.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s986687940", "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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7896, "cpu_time_ms": 243, "memory_kb": 39396}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s782415812", "group_id": "codeNet:p02806", "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(defun main ()\n (let* ((n (parse-integer (read-line)))\n (st (loop for i from 0 below n\n collect (split (read-line))))\n (x (read-line)))\n (format t \"~d~%\" (loop for s in st\n for remain on st\n do (when (string= x (car s))\n (return (loop for y in (cdr remain)\n summing (parse-integer (cadr y)))))))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1578791379, "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/s782415812.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s782415812", "user_id": "u690263481"}, "prompt_components": {"gold_output": "30\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(defun main ()\n (let* ((n (parse-integer (read-line)))\n (st (loop for i from 0 below n\n collect (split (read-line))))\n (x (read-line)))\n (format t \"~d~%\" (loop for s in st\n for remain on st\n do (when (string= x (car s))\n (return (loop for y in (cdr remain)\n summing (parse-integer (cadr y)))))))))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 811, "cpu_time_ms": 150, "memory_kb": 15976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s986586966", "group_id": "codeNet:p02806", "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 (ss (make-array n))\n (ts (make-array n)))\n (dotimes (i n)\n (setf (aref ss i) (read)\n (aref ts i) (read)))\n (let* ((x (read))\n (pos (position x ss)))\n (println (loop for i from (+ pos 1) below n\n sum (aref ts 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 \"3\ndwango 2\nsixth 5\nprelims 25\ndwango\n\"\n \"30\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\nabcde 1000\nabcde\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\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\"\n \"6348\n\")))\n", "language": "Lisp", "metadata": {"date": 1578791034, "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/s986586966.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s986586966", "user_id": "u352600849"}, "prompt_components": {"gold_output": "30\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 (ss (make-array n))\n (ts (make-array n)))\n (dotimes (i n)\n (setf (aref ss i) (read)\n (aref ts i) (read)))\n (let* ((x (read))\n (pos (position x ss)))\n (println (loop for i from (+ pos 1) below n\n sum (aref ts 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 \"3\ndwango 2\nsixth 5\nprelims 25\ndwango\n\"\n \"30\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\nabcde 1000\nabcde\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15\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\"\n \"6348\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4337, "cpu_time_ms": 157, "memory_kb": 18916}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s732261348", "group_id": "codeNet:p02807", "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(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(defun add-lst (lst1 lst2)\n (if (null lst1)\n 0\n (+ (* (car lst1) (car lst2))\n (add-lst (cdr lst1) (cdr lst2)))))\n\n(format t \"~A\" (mod (* f (add-lst coeff dists)) const))\n\n", "language": "Lisp", "metadata": {"date": 1578805997, "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/s732261348.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s732261348", "user_id": "u425317134"}, "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\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 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(defun add-lst (lst1 lst2)\n (if (null lst1)\n 0\n (+ (* (car lst1) (car lst2))\n (add-lst (cdr lst1) (cdr lst2)))))\n\n(format t \"~A\" (mod (* f (add-lst coeff dists)) const))\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1357, "cpu_time_ms": 2668, "memory_kb": 1010740}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s915469009", "group_id": "codeNet:p02807", "input_text": "(defvar *cache*)\n\n(defun fact (n)\n (loop with result = 1\n for i from 1 to n\n do (setf result\n (* result i))\n finally (return result)))\n\n(defun solve (n xs)\n (labels ((solve% (n xs)\n (or (gethash xs *cache*)\n (setf (gethash xs *cache*)\n (if (= n 1)\n 0\n (loop with past = ()\n for (x y . rest) on xs\n while y\n summing (/ (+ (- y x)\n (solve% (1- n)\n (nconc (reverse past) (cons y rest))))\n (1- n))\n do (setf past\n (cons x past))))))))\n (let ((*cache* (make-hash-table :test 'equal)))\n (rem (* (solve% n xs) (fact (1- n)))\n (+ (expt 10 9) 7)))))\n\n#-swank\n(let* ((n (read))\n (xs (loop repeat n collect (read))))\n (format t \"~A~%\" (solve n xs)))\n", "language": "Lisp", "metadata": {"date": 1578792923, "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/s915469009.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s915469009", "user_id": "u202886318"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defvar *cache*)\n\n(defun fact (n)\n (loop with result = 1\n for i from 1 to n\n do (setf result\n (* result i))\n finally (return result)))\n\n(defun solve (n xs)\n (labels ((solve% (n xs)\n (or (gethash xs *cache*)\n (setf (gethash xs *cache*)\n (if (= n 1)\n 0\n (loop with past = ()\n for (x y . rest) on xs\n while y\n summing (/ (+ (- y x)\n (solve% (1- n)\n (nconc (reverse past) (cons y rest))))\n (1- n))\n do (setf past\n (cons x past))))))))\n (let ((*cache* (make-hash-table :test 'equal)))\n (rem (* (solve% n xs) (fact (1- n)))\n (+ (expt 10 9) 7)))))\n\n#-swank\n(let* ((n (read))\n (xs (loop repeat n collect (read))))\n (format t \"~A~%\" (solve n xs)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1117, "cpu_time_ms": 2659, "memory_kb": 114400}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s926546538", "group_id": "codeNet:p02811", "input_text": "(princ \n (if (>= (* 500 (read)) (read) ) \n \"Yes\" \"No\"))\n", "language": "Lisp", "metadata": {"date": 1593283682, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s926546538.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s926546538", "user_id": "u526532903"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(princ \n (if (>= (* 500 (read)) (read) ) \n \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 24104}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s943881315", "group_id": "codeNet:p02811", "input_text": "(let ((k (read))\n (x (read)))\n (if (>= (* k 500) x)\n (princ \"Yes\")\n (princ \"No\")))\n ", "language": "Lisp", "metadata": {"date": 1588868045, "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/s943881315.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s943881315", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((k (read))\n (x (read)))\n (if (>= (* k 500) x)\n (princ \"Yes\")\n (princ \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 82, "memory_kb": 8292}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s680970673", "group_id": "codeNet:p02811", "input_text": "(let ((k (read)) (x (read)))\n (princ (if (>= (* k 500) x) \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1578708262, "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/s680970673.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s680970673", "user_id": "u493610446"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((k (read)) (x (read)))\n (princ (if (>= (* k 500) x) \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 132, "memory_kb": 11616}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s808625895", "group_id": "codeNet:p02811", "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* ((k (read))\n (x (read)))\n (write-line (if (>= (* 500 k) 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 \"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 900\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 501\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2000\n\"\n \"Yes\n\")))\n", "language": "Lisp", "metadata": {"date": 1578708043, "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/s808625895.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s808625895", "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* ((k (read))\n (x (read)))\n (write-line (if (>= (* 500 k) 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 \"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 900\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 501\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2000\n\"\n \"Yes\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3879, "cpu_time_ms": 268, "memory_kb": 15588}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s825951072", "group_id": "codeNet:p02812", "input_text": "(defun make-acceptor (string)\n (let ((num 0)\n (pos 0))\n (lambda (c)\n (if (null c)\n num\n (cond ((and (= pos (1- (length string))) (char= c (char string pos)))\n (incf num)\n (setf pos 0))\n ((char= c (char string pos))\n (incf pos))\n (t\n (setf pos 0)))))))\n\n(let ((n (read))\n (x (make-acceptor \"ABC\")))\n (loop :for i :from 1 :to n\n :for c := (read-char)\n :do (funcall x c))\n (format t \"~A~%\" (funcall x nil)))\n", "language": "Lisp", "metadata": {"date": 1593716018, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s825951072.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s825951072", "user_id": "u608227593"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun make-acceptor (string)\n (let ((num 0)\n (pos 0))\n (lambda (c)\n (if (null c)\n num\n (cond ((and (= pos (1- (length string))) (char= c (char string pos)))\n (incf num)\n (setf pos 0))\n ((char= c (char string pos))\n (incf pos))\n (t\n (setf pos 0)))))))\n\n(let ((n (read))\n (x (make-acceptor \"ABC\")))\n (loop :for i :from 1 :to n\n :for c := (read-char)\n :do (funcall x c))\n (format t \"~A~%\" (funcall x nil)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 24428}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s284557756", "group_id": "codeNet:p02812", "input_text": "(let ((n (read))\n (s (read-line)))\n (format t \"~a~%\"\n (search \"ABC\" s)))", "language": "Lisp", "metadata": {"date": 1589046723, "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/s284557756.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s284557756", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((n (read))\n (s (read-line)))\n (format t \"~a~%\"\n (search \"ABC\" s)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 15, "memory_kb": 3680}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s991295200", "group_id": "codeNet:p02812", "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(let ((n (read))\n (l (split \"ABC\" (read-line))))\n (princ (- (length l) 1)))", "language": "Lisp", "metadata": {"date": 1585627411, "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/s991295200.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s991295200", "user_id": "u606976120"}, "prompt_components": {"gold_output": "2\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(let ((n (read))\n (l (split \"ABC\" (read-line))))\n (princ (- (length l) 1)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 439, "cpu_time_ms": 308, "memory_kb": 24032}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s524069841", "group_id": "codeNet:p02812", "input_text": "(defun check_A (x)\n (when (and x (char= (car x) #\\A))\n\t\t\t (check_B (cdr x))))\n(defun check_B (x)\n (when (and x (char= (car x) #\\B))\n\t\t\t (check_C (cdr x))))\n(defun check_C (x)\n (and x (char= (car x) #\\C)))\n\n(defun cnt (x)\n (if x\n\t(+ (if (check_A x) 1 0) (cnt (cdr x)))\n\t0))\n\n(defparameter n (read))\n(let ((str (concatenate 'list (read-line))))\n (princ (cnt str)))\n\n", "language": "Lisp", "metadata": {"date": 1578708649, "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/s524069841.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s524069841", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun check_A (x)\n (when (and x (char= (car x) #\\A))\n\t\t\t (check_B (cdr x))))\n(defun check_B (x)\n (when (and x (char= (car x) #\\B))\n\t\t\t (check_C (cdr x))))\n(defun check_C (x)\n (and x (char= (car x) #\\C)))\n\n(defun cnt (x)\n (if x\n\t(+ (if (check_A x) 1 0) (cnt (cdr x)))\n\t0))\n\n(defparameter n (read))\n(let ((str (concatenate 'list (read-line))))\n (princ (cnt str)))\n\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 369, "cpu_time_ms": 119, "memory_kb": 12260}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s053634606", "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 (+ (* (fact (1- n)) (1- (car lst))) (dec (cdr lst) (1- n)))\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": 1578713407, "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/s053634606.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s053634606", "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 (+ (* (fact (1- n)) (1- (car lst))) (dec (cdr lst) (1- n)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1080, "cpu_time_ms": 177, "memory_kb": 14688}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s435748695", "group_id": "codeNet:p02814", "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 `(make-array ,size :initial-contents :element-type 'fixnum (loop repeat ,size collect (read))))\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\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\n\n(defun divide-judge (xs)\n (declare (list xs))\n (cond\n ((every #'oddp xs) t)\n ((every #'evenp xs) (divide-judge (mapcar (lambda (x) (floor x 2)) xs)))\n (t nil)))\n\n(defun solve (m a)\n (let ((xb (mapcar (lambda (x) (floor x 2)) a)))\n (if (not (divide-judge xb))\n 0\n (let ((p (reduce #'lcm xb)))\n (ceiling (- m p) (* p 2))))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (m (read)))\n (let ((a (sort (read-numbers-to-list n) #'<)))\n (format t \"~a~&\" (solve m a)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1599891290, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s435748695.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s435748695", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\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 `(make-array ,size :initial-contents :element-type 'fixnum (loop repeat ,size collect (read))))\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\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\n\n(defun divide-judge (xs)\n (declare (list xs))\n (cond\n ((every #'oddp xs) t)\n ((every #'evenp xs) (divide-judge (mapcar (lambda (x) (floor x 2)) xs)))\n (t nil)))\n\n(defun solve (m a)\n (let ((xb (mapcar (lambda (x) (floor x 2)) a)))\n (if (not (divide-judge xb))\n 0\n (let ((p (reduce #'lcm xb)))\n (ceiling (- m p) (* p 2))))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (m (read)))\n (let ((a (sort (read-numbers-to-list n) #'<)))\n (format t \"~a~&\" (solve m a)))))\n\n#-swank (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3322, "cpu_time_ms": 233, "memory_kb": 83124}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s511312281", "group_id": "codeNet:p02814", "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(defparameter n (read))\n(defparameter m (read))\n\n(let* ((a (loop for i below n collect (read)))\n\t (x (reduce (lambda (x y) (let ((res (lcm x (floor y 2))))\n\t\t\t\t\t\t\t\t (if (> res m) (* 10 m) res)))\n\t\t\t\t a\n\t\t\t\t :initial-value 1)))\n (princ (floor (+ m x) (* x 2))))\n", "language": "Lisp", "metadata": {"date": 1578710626, "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/s511312281.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s511312281", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\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(defparameter n (read))\n(defparameter m (read))\n\n(let* ((a (loop for i below n collect (read)))\n\t (x (reduce (lambda (x y) (let ((res (lcm x (floor y 2))))\n\t\t\t\t\t\t\t\t (if (> res m) (* 10 m) res)))\n\t\t\t\t a\n\t\t\t\t :initial-value 1)))\n (princ (floor (+ m x) (* x 2))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 650, "cpu_time_ms": 329, "memory_kb": 62524}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s343175036", "group_id": "codeNet:p02814", "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(defparameter n (read))\n(defparameter m (read))\n\n(let* ((a (loop for i below n collect (read)))\n\t (x (reduce (lambda (x y) (let ((res (lcm x (/ y 2))))\n\t\t\t\t\t\t\t\t (if (> res m) (* 10 m) res)))\n\t\t\t\t a\n\t\t\t\t :initial-value 1)))\n (princ (floor (+ m x) (* x 2))))\n", "language": "Lisp", "metadata": {"date": 1578709920, "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/s343175036.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s343175036", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\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(defparameter n (read))\n(defparameter m (read))\n\n(let* ((a (loop for i below n collect (read)))\n\t (x (reduce (lambda (x y) (let ((res (lcm x (/ y 2))))\n\t\t\t\t\t\t\t\t (if (> res m) (* 10 m) res)))\n\t\t\t\t a\n\t\t\t\t :initial-value 1)))\n (princ (floor (+ m x) (* x 2))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 498, "memory_kb": 62648}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s829620041", "group_id": "codeNet:p02816", "input_text": ";; F - Xor Shift\n\n(defun main ()\n (let* ((N (read))\n (a (loop repeat N collect (read-fixnum)))\n (b (loop repeat N collect (read-fixnum))))\n (loop for kx in (solve N a b)\n do (format t \"~{~a~^ ~}~%\" kx))))\n\n(defun solve (N a-lst b-lst)\n (let ((a (make-array N :initial-contents a-lst))\n (b (make-array N :initial-contents b-lst))\n (a-xor (make-array N)) ; 直前の要素とのxor (循環)\n (b-xor (make-array (1- N)))) ; 〃 (先頭を除く)\n ; (k,x)が解 ⇔ a-xor[k:]がb-xorと一致, x = b[0] XOR a[k]\n ; a-xor, b-xorを構築\n (loop for i below N\n do (setf (aref a-xor i) (logxor (aref a i) (aref a (mod (1+ i) N)))))\n (loop for i below (1- N)\n do (setf (aref b-xor i) (logxor (aref b i) (aref b (1+ i)))))\n ; a-xor * 2中のb-xorと一致する位置をKMP法で探す\n (loop for k in (kmp-search a-xor b-xor)\n for x = (logxor (aref a (mod k N)) (aref b 0))\n when (< k N)\n collect (list k x))))\n\n(defun kmp-search (text pattern)\n \"text * 2中のpatternに一致する位置をすべて返す.\"\n (let ((n (array-dimension text 0))\n (m (array-dimension pattern 0))\n (pref (compute-prefix-function pattern)))\n (loop with q = 0\n for i from 0 below (* 2 n)\n for c = (aref text (mod i n))\n do (loop until (or (zerop q) (eql (aref pattern q) c))\n do (setf q (aref pref q))) ; next char does not match\n when (eql (aref pattern q) c)\n do (incf q) end ; next char matches\n when (= q m)\n collect (- i (1- m))\n and do (setf q (aref pref q))))) ; look for the next match\n\n(defun compute-prefix-function (pattern)\n \"pref : {1,2,...,m} -> {0,1,...,m-1}\n pref[q] = max {k : k < q and P[:q].endswith(P[:k])}\"\n (let* ((m (array-dimension pattern 0))\n (pref (make-array (1+ m) :initial-element 0)))\n (loop with k = 0\n for q from 1 below m\n for c = (aref pattern q)\n do (loop until (or (zerop k) (eql (aref pattern k) c))\n do (setf k (aref pref k)))\n when (eql (aref pattern k) c)\n do (incf k) end\n do (setf (aref pref (1+ q)) k))\n pref))\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": 1579970493, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02816.html", "problem_id": "p02816", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02816/input.txt", "sample_output_relpath": "derived/input_output/data/p02816/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02816/Lisp/s829620041.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s829620041", "user_id": "u227020436"}, "prompt_components": {"gold_output": "1 3\n", "input_to_evaluate": ";; F - Xor Shift\n\n(defun main ()\n (let* ((N (read))\n (a (loop repeat N collect (read-fixnum)))\n (b (loop repeat N collect (read-fixnum))))\n (loop for kx in (solve N a b)\n do (format t \"~{~a~^ ~}~%\" kx))))\n\n(defun solve (N a-lst b-lst)\n (let ((a (make-array N :initial-contents a-lst))\n (b (make-array N :initial-contents b-lst))\n (a-xor (make-array N)) ; 直前の要素とのxor (循環)\n (b-xor (make-array (1- N)))) ; 〃 (先頭を除く)\n ; (k,x)が解 ⇔ a-xor[k:]がb-xorと一致, x = b[0] XOR a[k]\n ; a-xor, b-xorを構築\n (loop for i below N\n do (setf (aref a-xor i) (logxor (aref a i) (aref a (mod (1+ i) N)))))\n (loop for i below (1- N)\n do (setf (aref b-xor i) (logxor (aref b i) (aref b (1+ i)))))\n ; a-xor * 2中のb-xorと一致する位置をKMP法で探す\n (loop for k in (kmp-search a-xor b-xor)\n for x = (logxor (aref a (mod k N)) (aref b 0))\n when (< k N)\n collect (list k x))))\n\n(defun kmp-search (text pattern)\n \"text * 2中のpatternに一致する位置をすべて返す.\"\n (let ((n (array-dimension text 0))\n (m (array-dimension pattern 0))\n (pref (compute-prefix-function pattern)))\n (loop with q = 0\n for i from 0 below (* 2 n)\n for c = (aref text (mod i n))\n do (loop until (or (zerop q) (eql (aref pattern q) c))\n do (setf q (aref pref q))) ; next char does not match\n when (eql (aref pattern q) c)\n do (incf q) end ; next char matches\n when (= q m)\n collect (- i (1- m))\n and do (setf q (aref pref q))))) ; look for the next match\n\n(defun compute-prefix-function (pattern)\n \"pref : {1,2,...,m} -> {0,1,...,m-1}\n pref[q] = max {k : k < q and P[:q].endswith(P[:k])}\"\n (let* ((m (array-dimension pattern 0))\n (pref (make-array (1+ m) :initial-element 0)))\n (loop with k = 0\n for q from 1 below m\n for c = (aref pattern q)\n do (loop until (or (zerop k) (eql (aref pattern k) c))\n do (setf k (aref pref k)))\n when (eql (aref pattern k) c)\n do (incf k) end\n do (setf (aref pref (1+ q)) k))\n pref))\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 : 600 points\n\nProblem Statement\n\nGiven are two sequences a=\\{a_0,\\ldots,a_{N-1}\\} and b=\\{b_0,\\ldots,b_{N-1}\\} of N non-negative integers each.\n\nSnuke will choose an integer k such that 0 \\leq k < N and an integer x not less than 0, to make a new sequence of length N, a'=\\{a_0',\\ldots,a_{N-1}'\\}, as follows:\n\na_i'= a_{i+k \\mod N}\\ XOR \\ x\n\nFind all pairs (k,x) such that a' will be equal to b.\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 N \\leq 2 \\times 10^5\n\n0 \\leq a_i,b_i < 2^{30}\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_{N-1}\nb_0 b_1 ... b_{N-1}\n\nOutput\n\nPrint all pairs (k, x) such that a' and b will be equal, using one line for each pair, in ascending order of k (ascending order of x for pairs with the same k).\n\nIf there are no such pairs, the output should be empty.\n\nSample Input 1\n\n3\n0 2 1\n1 2 3\n\nSample Output 1\n\n1 3\n\nIf (k,x)=(1,3),\n\na_0'=(a_1\\ XOR \\ 3)=1\n\na_1'=(a_2\\ XOR \\ 3)=2\n\na_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\nSample Input 2\n\n5\n0 0 0 0 0\n2 2 2 2 2\n\nSample Output 2\n\n0 2\n1 2\n2 2\n3 2\n4 2\n\nSample Input 3\n\n6\n0 1 3 7 6 4\n1 5 4 6 2 3\n\nSample Output 3\n\n2 2\n5 5\n\nSample Input 4\n\n2\n1 2\n0 0\n\nSample Output 4\n\nNo pairs may satisfy the condition.", "sample_input": "3\n0 2 1\n1 2 3\n"}, "reference_outputs": ["1 3\n"], "source_document_id": "p02816", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are two sequences a=\\{a_0,\\ldots,a_{N-1}\\} and b=\\{b_0,\\ldots,b_{N-1}\\} of N non-negative integers each.\n\nSnuke will choose an integer k such that 0 \\leq k < N and an integer x not less than 0, to make a new sequence of length N, a'=\\{a_0',\\ldots,a_{N-1}'\\}, as follows:\n\na_i'= a_{i+k \\mod N}\\ XOR \\ x\n\nFind all pairs (k,x) such that a' will be equal to b.\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 N \\leq 2 \\times 10^5\n\n0 \\leq a_i,b_i < 2^{30}\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_{N-1}\nb_0 b_1 ... b_{N-1}\n\nOutput\n\nPrint all pairs (k, x) such that a' and b will be equal, using one line for each pair, in ascending order of k (ascending order of x for pairs with the same k).\n\nIf there are no such pairs, the output should be empty.\n\nSample Input 1\n\n3\n0 2 1\n1 2 3\n\nSample Output 1\n\n1 3\n\nIf (k,x)=(1,3),\n\na_0'=(a_1\\ XOR \\ 3)=1\n\na_1'=(a_2\\ XOR \\ 3)=2\n\na_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\nSample Input 2\n\n5\n0 0 0 0 0\n2 2 2 2 2\n\nSample Output 2\n\n0 2\n1 2\n2 2\n3 2\n4 2\n\nSample Input 3\n\n6\n0 1 3 7 6 4\n1 5 4 6 2 3\n\nSample Output 3\n\n2 2\n5 5\n\nSample Input 4\n\n2\n1 2\n0 0\n\nSample Output 4\n\nNo pairs may satisfy the condition.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2606, "cpu_time_ms": 1095, "memory_kb": 51944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s157295253", "group_id": "codeNet:p02816", "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 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 (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;;;\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 (cumul1 powers1 cumul2 powers2)))\n ;; lower 31-bit value\n (cumul1 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers1 nil :type (simple-array (unsigned-byte 31) (*)))\n ;; upper 31-bit value\n (cumul2 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers2 nil :type (simple-array (unsigned-byte 31) (*))))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\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 (&optional mod1 mod2 base1 base2)\n \"Chooses two appropriate pairs of moduli and bases.\"\n (declare ((or null (unsigned-byte 31)) mod1 mod2 base1 base2))\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 #+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 (unless (and (boundp '+rhash-mod1+)\n (boundp '+rhash-mod2+)\n (boundp '+rhash-base1+)\n (boundp '+rhash-base2+))\n (multiple-value-bind (mod1 mod2 base1 base2) (%choose-moduli)\n (defconstant +rhash-mod1+ mod1)\n (defconstant +rhash-mod2+ mod2)\n (defconstant +rhash-base1+ base1)\n (defconstant +rhash-base2+ base2))))\n\n;; KLUDGE: Type derivation of MOD fails in some cases on SBCL. See\n;; https://bugs.launchpad.net/sbcl/+bug/1843108\n(declaim (inline %mod))\n(defun %mod (number divisor)\n (nth-value 1 (floor number divisor)))\n\n(declaim (inline make-rhash))\n(defun make-rhash (vector &key (key #'char-code))\n \"Returns the table of rolling-hash of VECTOR modulo +RHASH-MOD1+ and\n+RHASH-MOD2+. KEY is applied to each element of VECTOR prior to computing the\nhash value.\n\nKEY := FUNCTION returning FIXNUM\"\n (declare (optimize (speed 3))\n (vector vector)\n (function key))\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) +rhash-base1+) +rhash-mod1+)\n (aref powers2 (+ i 1))\n (%mod (* (aref powers2 i) +rhash-base2+) +rhash-mod2+))\n (let ((sum1 (+ (%mod (* +rhash-base1+ (aref cumul1 i)) +rhash-mod1+)\n (%mod (the fixnum (funcall key (aref vector i))) +rhash-mod1+)))\n (sum2 (+ (%mod (* +rhash-base2+ (aref cumul2 i)) +rhash-mod2+)\n (%mod (the fixnum (funcall key (aref vector i))) +rhash-mod2+))))\n (setf (aref cumul1 (+ i 1)) (if (>= sum1 +rhash-mod1+)\n (- sum1 +rhash-mod1+)\n sum1)\n (aref cumul2 (+ i 1)) (if (>= sum2 +rhash-mod2+)\n (- sum2 +rhash-mod2+)\n sum2))))\n (%make-rhash cumul1 powers1 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 (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* ((size (length vector))\n (lower 0)\n (upper 0))\n (declare ((unsigned-byte 31) lower upper))\n (dotimes (i size)\n (setf lower (%mod (+ (* +rhash-base1+ lower)\n (%mod (the fixnum (funcall key (aref vector i))) +rhash-mod1+))\n +rhash-mod1+))\n (setf upper (%mod (+ (* +rhash-base2+ upper)\n (%mod (the fixnum (funcall key (aref vector i))) +rhash-mod2+))\n +rhash-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 (cumul2 (rhash-cumul2 rhash))\n (powers2 (rhash-powers2 rhash)))\n (let ((lower (+ (aref cumul1 r)\n (- +rhash-mod1+ (%mod (* (aref cumul1 l) (aref powers1 (- r l))) +rhash-mod1+))))\n (upper (+ (aref cumul2 r)\n (- +rhash-mod2+ (%mod (* (aref cumul2 l) (aref powers2 (- r l))) +rhash-mod2+)))))\n (let ((lower (if (>= lower +rhash-mod1+) (- lower +rhash-mod1+) lower))\n (upper (if (>= upper +rhash-mod2+) (- upper +rhash-mod2+) upper)))\n (declare ((unsigned-byte 31) lower upper))\n (dpb upper (byte 31 31) lower)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (bs (make-array n :element-type 'uint31))\n (adeltas (make-array (* 2 n) :element-type 'uint31))\n (bdeltas (make-array n :element-type 'uint31)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (setf (aref bs i) (read-fixnum)))\n (dotimes (i (- n 1))\n (setf (aref adeltas i) (logxor (aref as i) (aref as (+ i 1)))\n (aref adeltas (+ i n)) (aref adeltas i))\n (setf (aref bdeltas i) (logxor (aref bs i) (aref bs (+ i 1)))))\n (setf (aref adeltas (- n 1))\n (logxor (aref as (- n 1)) (aref as 0))\n (aref adeltas (- (* 2 n) 1)) (aref adeltas (- n 1)))\n (setf (aref bdeltas (- n 1)) (logxor (aref bs (- n 1)) (aref bs 0)))\n (let ((ahash (make-rhash adeltas :key #'identity))\n (bhash (rhash-vector-hash bdeltas :key #'identity)))\n (with-buffered-stdout\n (dotimes (i n)\n (when (= (rhash-query ahash i (+ i n)) bhash)\n (format t \"~D ~D~%\" i (logxor (aref as i) (aref bs 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\n0 2 1\n1 2 3\n\"\n \"1 3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n0 0 0 0 0\n2 2 2 2 2\n\"\n \"0 2\n1 2\n2 2\n3 2\n4 2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n0 1 3 7 6 4\n1 5 4 6 2 3\n\"\n \"2 2\n5 5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n0 0\n\"\n \"\n\")))\n", "language": "Lisp", "metadata": {"date": 1578735151, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02816.html", "problem_id": "p02816", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02816/input.txt", "sample_output_relpath": "derived/input_output/data/p02816/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02816/Lisp/s157295253.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s157295253", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 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(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 (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;;;\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 (cumul1 powers1 cumul2 powers2)))\n ;; lower 31-bit value\n (cumul1 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers1 nil :type (simple-array (unsigned-byte 31) (*)))\n ;; upper 31-bit value\n (cumul2 nil :type (simple-array (unsigned-byte 31) (*)))\n (powers2 nil :type (simple-array (unsigned-byte 31) (*))))\n\n(eval-when (:compile-toplevel :load-toplevel :execute)\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 (&optional mod1 mod2 base1 base2)\n \"Chooses two appropriate pairs of moduli and bases.\"\n (declare ((or null (unsigned-byte 31)) mod1 mod2 base1 base2))\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 #+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 (unless (and (boundp '+rhash-mod1+)\n (boundp '+rhash-mod2+)\n (boundp '+rhash-base1+)\n (boundp '+rhash-base2+))\n (multiple-value-bind (mod1 mod2 base1 base2) (%choose-moduli)\n (defconstant +rhash-mod1+ mod1)\n (defconstant +rhash-mod2+ mod2)\n (defconstant +rhash-base1+ base1)\n (defconstant +rhash-base2+ base2))))\n\n;; KLUDGE: Type derivation of MOD fails in some cases on SBCL. See\n;; https://bugs.launchpad.net/sbcl/+bug/1843108\n(declaim (inline %mod))\n(defun %mod (number divisor)\n (nth-value 1 (floor number divisor)))\n\n(declaim (inline make-rhash))\n(defun make-rhash (vector &key (key #'char-code))\n \"Returns the table of rolling-hash of VECTOR modulo +RHASH-MOD1+ and\n+RHASH-MOD2+. KEY is applied to each element of VECTOR prior to computing the\nhash value.\n\nKEY := FUNCTION returning FIXNUM\"\n (declare (optimize (speed 3))\n (vector vector)\n (function key))\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) +rhash-base1+) +rhash-mod1+)\n (aref powers2 (+ i 1))\n (%mod (* (aref powers2 i) +rhash-base2+) +rhash-mod2+))\n (let ((sum1 (+ (%mod (* +rhash-base1+ (aref cumul1 i)) +rhash-mod1+)\n (%mod (the fixnum (funcall key (aref vector i))) +rhash-mod1+)))\n (sum2 (+ (%mod (* +rhash-base2+ (aref cumul2 i)) +rhash-mod2+)\n (%mod (the fixnum (funcall key (aref vector i))) +rhash-mod2+))))\n (setf (aref cumul1 (+ i 1)) (if (>= sum1 +rhash-mod1+)\n (- sum1 +rhash-mod1+)\n sum1)\n (aref cumul2 (+ i 1)) (if (>= sum2 +rhash-mod2+)\n (- sum2 +rhash-mod2+)\n sum2))))\n (%make-rhash cumul1 powers1 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 (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* ((size (length vector))\n (lower 0)\n (upper 0))\n (declare ((unsigned-byte 31) lower upper))\n (dotimes (i size)\n (setf lower (%mod (+ (* +rhash-base1+ lower)\n (%mod (the fixnum (funcall key (aref vector i))) +rhash-mod1+))\n +rhash-mod1+))\n (setf upper (%mod (+ (* +rhash-base2+ upper)\n (%mod (the fixnum (funcall key (aref vector i))) +rhash-mod2+))\n +rhash-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 (cumul2 (rhash-cumul2 rhash))\n (powers2 (rhash-powers2 rhash)))\n (let ((lower (+ (aref cumul1 r)\n (- +rhash-mod1+ (%mod (* (aref cumul1 l) (aref powers1 (- r l))) +rhash-mod1+))))\n (upper (+ (aref cumul2 r)\n (- +rhash-mod2+ (%mod (* (aref cumul2 l) (aref powers2 (- r l))) +rhash-mod2+)))))\n (let ((lower (if (>= lower +rhash-mod1+) (- lower +rhash-mod1+) lower))\n (upper (if (>= upper +rhash-mod2+) (- upper +rhash-mod2+) upper)))\n (declare ((unsigned-byte 31) lower upper))\n (dpb upper (byte 31 31) lower)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (bs (make-array n :element-type 'uint31))\n (adeltas (make-array (* 2 n) :element-type 'uint31))\n (bdeltas (make-array n :element-type 'uint31)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (setf (aref bs i) (read-fixnum)))\n (dotimes (i (- n 1))\n (setf (aref adeltas i) (logxor (aref as i) (aref as (+ i 1)))\n (aref adeltas (+ i n)) (aref adeltas i))\n (setf (aref bdeltas i) (logxor (aref bs i) (aref bs (+ i 1)))))\n (setf (aref adeltas (- n 1))\n (logxor (aref as (- n 1)) (aref as 0))\n (aref adeltas (- (* 2 n) 1)) (aref adeltas (- n 1)))\n (setf (aref bdeltas (- n 1)) (logxor (aref bs (- n 1)) (aref bs 0)))\n (let ((ahash (make-rhash adeltas :key #'identity))\n (bhash (rhash-vector-hash bdeltas :key #'identity)))\n (with-buffered-stdout\n (dotimes (i n)\n (when (= (rhash-query ahash i (+ i n)) bhash)\n (format t \"~D ~D~%\" i (logxor (aref as i) (aref bs 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\n0 2 1\n1 2 3\n\"\n \"1 3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n0 0 0 0 0\n2 2 2 2 2\n\"\n \"0 2\n1 2\n2 2\n3 2\n4 2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n0 1 3 7 6 4\n1 5 4 6 2 3\n\"\n \"2 2\n5 5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n0 0\n\"\n \"\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nGiven are two sequences a=\\{a_0,\\ldots,a_{N-1}\\} and b=\\{b_0,\\ldots,b_{N-1}\\} of N non-negative integers each.\n\nSnuke will choose an integer k such that 0 \\leq k < N and an integer x not less than 0, to make a new sequence of length N, a'=\\{a_0',\\ldots,a_{N-1}'\\}, as follows:\n\na_i'= a_{i+k \\mod N}\\ XOR \\ x\n\nFind all pairs (k,x) such that a' will be equal to b.\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 N \\leq 2 \\times 10^5\n\n0 \\leq a_i,b_i < 2^{30}\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_{N-1}\nb_0 b_1 ... b_{N-1}\n\nOutput\n\nPrint all pairs (k, x) such that a' and b will be equal, using one line for each pair, in ascending order of k (ascending order of x for pairs with the same k).\n\nIf there are no such pairs, the output should be empty.\n\nSample Input 1\n\n3\n0 2 1\n1 2 3\n\nSample Output 1\n\n1 3\n\nIf (k,x)=(1,3),\n\na_0'=(a_1\\ XOR \\ 3)=1\n\na_1'=(a_2\\ XOR \\ 3)=2\n\na_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\nSample Input 2\n\n5\n0 0 0 0 0\n2 2 2 2 2\n\nSample Output 2\n\n0 2\n1 2\n2 2\n3 2\n4 2\n\nSample Input 3\n\n6\n0 1 3 7 6 4\n1 5 4 6 2 3\n\nSample Output 3\n\n2 2\n5 5\n\nSample Input 4\n\n2\n1 2\n0 0\n\nSample Output 4\n\nNo pairs may satisfy the condition.", "sample_input": "3\n0 2 1\n1 2 3\n"}, "reference_outputs": ["1 3\n"], "source_document_id": "p02816", "source_text": "Score : 600 points\n\nProblem Statement\n\nGiven are two sequences a=\\{a_0,\\ldots,a_{N-1}\\} and b=\\{b_0,\\ldots,b_{N-1}\\} of N non-negative integers each.\n\nSnuke will choose an integer k such that 0 \\leq k < N and an integer x not less than 0, to make a new sequence of length N, a'=\\{a_0',\\ldots,a_{N-1}'\\}, as follows:\n\na_i'= a_{i+k \\mod N}\\ XOR \\ x\n\nFind all pairs (k,x) such that a' will be equal to b.\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 N \\leq 2 \\times 10^5\n\n0 \\leq a_i,b_i < 2^{30}\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_{N-1}\nb_0 b_1 ... b_{N-1}\n\nOutput\n\nPrint all pairs (k, x) such that a' and b will be equal, using one line for each pair, in ascending order of k (ascending order of x for pairs with the same k).\n\nIf there are no such pairs, the output should be empty.\n\nSample Input 1\n\n3\n0 2 1\n1 2 3\n\nSample Output 1\n\n1 3\n\nIf (k,x)=(1,3),\n\na_0'=(a_1\\ XOR \\ 3)=1\n\na_1'=(a_2\\ XOR \\ 3)=2\n\na_2'=(a_0\\ XOR \\ 3)=3\n\nand we have a' = b.\n\nSample Input 2\n\n5\n0 0 0 0 0\n2 2 2 2 2\n\nSample Output 2\n\n0 2\n1 2\n2 2\n3 2\n4 2\n\nSample Input 3\n\n6\n0 1 3 7 6 4\n1 5 4 6 2 3\n\nSample Output 3\n\n2 2\n5 5\n\nSample Input 4\n\n2\n1 2\n0 0\n\nSample Output 4\n\nNo pairs may satisfy the condition.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15308, "cpu_time_ms": 559, "memory_kb": 72552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s286974935", "group_id": "codeNet:p02817", "input_text": "(let ((s (read))\n\t(s_t (read)))\n\t(format t \"~(~A~A~)\" s_t s)\n)", "language": "Lisp", "metadata": {"date": 1593065822, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s286974935.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s286974935", "user_id": "u136500538"}, "prompt_components": {"gold_output": "atcoder\n", "input_to_evaluate": "(let ((s (read))\n\t(s_t (read)))\n\t(format t \"~(~A~A~)\" s_t s)\n)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 14, "memory_kb": 23452}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s147931911", "group_id": "codeNet:p02817", "input_text": "(let ((str (read)))\n (format t \"~(~A~A~)\" (read) str))", "language": "Lisp", "metadata": {"date": 1584573385, "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/s147931911.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s147931911", "user_id": "u334552723"}, "prompt_components": {"gold_output": "atcoder\n", "input_to_evaluate": "(let ((str (read)))\n (format t \"~(~A~A~)\" (read) str))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 100, "memory_kb": 9572}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s780436063", "group_id": "codeNet:p02817", "input_text": "(let* ((s (read-line))\n (pos (position #\\Space s)))\n (format t \"~A~A~%\" (subseq s (1+ pos)) (subseq s 0 pos)))\n", "language": "Lisp", "metadata": {"date": 1577667745, "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/s780436063.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s780436063", "user_id": "u202886318"}, "prompt_components": {"gold_output": "atcoder\n", "input_to_evaluate": "(let* ((s (read-line))\n (pos (position #\\Space s)))\n (format t \"~A~A~%\" (subseq s (1+ pos)) (subseq s 0 pos)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 32, "memory_kb": 5092}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s234410641", "group_id": "codeNet:p02818", "input_text": "(let ((a (read))\n (b (read))\n (k (read)))\n (if (> a k)\n (decf a k)\n (if (> (+ a b) k)\n (progn\n (decf b (- k a))\n (setq a 0)\n )\n (progn\n (setq a 0)\n (setq b 0))))\n (format t \"~D ~D\" a b)\n)", "language": "Lisp", "metadata": {"date": 1593106299, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02818.html", "problem_id": "p02818", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02818/input.txt", "sample_output_relpath": "derived/input_output/data/p02818/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02818/Lisp/s234410641.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s234410641", "user_id": "u136500538"}, "prompt_components": {"gold_output": "0 2\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (k (read)))\n (if (> a k)\n (decf a k)\n (if (> (+ a b) k)\n (progn\n (decf b (- k a))\n (setq a 0)\n )\n (progn\n (setq a 0)\n (setq b 0))))\n (format t \"~D ~D\" a b)\n)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi has A cookies, and Aoki has B cookies.\nTakahashi will do the following action K times:\n\nIf Takahashi has one or more cookies, eat one of his cookies.\n\nOtherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.\n\nIf they both have no cookies, do nothing.\n\nIn the end, how many cookies will Takahashi and Aoki have, respectively?\n\nConstraints\n\n0 \\leq A \\leq 10^{12}\n\n0 \\leq B \\leq 10^{12}\n\n0 \\leq K \\leq 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 K\n\nOutput\n\nPrint the numbers of Takahashi's and Aoki's cookies after K actions.\n\nSample Input 1\n\n2 3 3\n\nSample Output 1\n\n0 2\n\nTakahashi will do the following:\n\nHe has two cookies, so he eats one of them.\n\nNow he has one cookie left, and he eats it.\n\nNow he has no cookies left, but Aoki has three, so Takahashi eats one of them.\n\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.\n\nSample Input 2\n\n500000000000 500000000000 1000000000000\n\nSample Output 2\n\n0 0\n\nWatch out for overflows.", "sample_input": "2 3 3\n"}, "reference_outputs": ["0 2\n"], "source_document_id": "p02818", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi has A cookies, and Aoki has B cookies.\nTakahashi will do the following action K times:\n\nIf Takahashi has one or more cookies, eat one of his cookies.\n\nOtherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.\n\nIf they both have no cookies, do nothing.\n\nIn the end, how many cookies will Takahashi and Aoki have, respectively?\n\nConstraints\n\n0 \\leq A \\leq 10^{12}\n\n0 \\leq B \\leq 10^{12}\n\n0 \\leq K \\leq 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 K\n\nOutput\n\nPrint the numbers of Takahashi's and Aoki's cookies after K actions.\n\nSample Input 1\n\n2 3 3\n\nSample Output 1\n\n0 2\n\nTakahashi will do the following:\n\nHe has two cookies, so he eats one of them.\n\nNow he has one cookie left, and he eats it.\n\nNow he has no cookies left, but Aoki has three, so Takahashi eats one of them.\n\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.\n\nSample Input 2\n\n500000000000 500000000000 1000000000000\n\nSample Output 2\n\n0 0\n\nWatch out for overflows.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 24412}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s064439833", "group_id": "codeNet:p02819", "input_text": "(defun solve (n l)\n (if (< (car l) n)\n (solve n (remove-if (lambda (x) (zerop (mod x (car l)))) l))\n (car l)))\n\n(defun initialize ()\n (loop :as i\n :below 100002\n :collect (+ i 2)))\n\n(princ (solve (read) (initialize)))", "language": "Lisp", "metadata": {"date": 1585796859, "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/s064439833.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s064439833", "user_id": "u606976120"}, "prompt_components": {"gold_output": "23\n", "input_to_evaluate": "(defun solve (n l)\n (if (< (car l) n)\n (solve n (remove-if (lambda (x) (zerop (mod x (car l)))) l))\n (car l)))\n\n(defun initialize ()\n (loop :as i\n :below 100002\n :collect (+ i 2)))\n\n(princ (solve (read) (initialize)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 243, "cpu_time_ms": 1659, "memory_kb": 61864}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s168110370", "group_id": "codeNet:p02819", "input_text": "(defun solve (n l)\n (if (<= (car l) n)\n (solve n (remove-if (lambda (x) (zerop (mod x (car l)))) l))\n (car l)))\n\n(defun initialize ()\n (loop :as i\n :below 100002\n :collect (+ i 2)))\n\n(princ (solve (read) (initialize)))", "language": "Lisp", "metadata": {"date": 1585796755, "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/s168110370.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s168110370", "user_id": "u606976120"}, "prompt_components": {"gold_output": "23\n", "input_to_evaluate": "(defun solve (n l)\n (if (<= (car l) n)\n (solve n (remove-if (lambda (x) (zerop (mod x (car l)))) l))\n (car l)))\n\n(defun initialize ()\n (loop :as i\n :below 100002\n :collect (+ i 2)))\n\n(princ (solve (read) (initialize)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 244, "cpu_time_ms": 1704, "memory_kb": 61764}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s809601217", "group_id": "codeNet:p02822", "input_text": ";; F - Surrounded Nodes\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n(defparameter *2-inv* (/ (1+ *modulus*) 2)) ; 2^-1 (mod *modulus*)\n\n(defun main ()\n (let* ((N (read)) ; 頂点数\n (tree (read-tree N)))\n (princ (solve N tree))\n (fresh-line)))\n\n(defun solve (N tree)\n (let ((expt-2 (make-array N))\n (parent (make-array N :initial-element nil))\n (subtree-size (make-array N :initial-element nil))\n (sum-expt-2-subtree 0))\n ; 1, 2, 4, 8, ..., 2^(N - 1) をexpt-2に保存\n (loop for i below N for e = 1 then (mod (* e 2) *modulus*)\n do (setf (aref expt-2 i) e))\n (labels\n ((dfs (stack)\n (when stack\n (let* ((v (pop stack))\n (p (aref parent v)) ; vの親\n (size (aref subtree-size v))) ; vを根とする部分木の頂点数\n (if (aref subtree-size v)\n ; 帰りがけ\n (when p\n (incf sum-expt-2-subtree (1- (aref expt-2 size)))\n (incf sum-expt-2-subtree (1- (aref expt-2 (- N size))))\n (incf (aref subtree-size p) size))\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 ; sum-expt-2-subtree (2^(部分木の頂点数) - 1の総和) を計算\n (dfs (list 0))\n\n (loop repeat (1+ N)\n for e = (+ (* N (1- (aref expt-2 (1- N))))\n (- *modulus* (mod sum-expt-2-subtree *modulus*)))\n then (mod (* e *2-inv*) *modulus*)\n finally (return e)))))\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 (整数間に空白または改行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": 1578104044, "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/s809601217.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s809601217", "user_id": "u227020436"}, "prompt_components": {"gold_output": "125000001\n", "input_to_evaluate": ";; F - Surrounded Nodes\n\n(defparameter *modulus* (+ (expt 10 9) 7))\n(defparameter *2-inv* (/ (1+ *modulus*) 2)) ; 2^-1 (mod *modulus*)\n\n(defun main ()\n (let* ((N (read)) ; 頂点数\n (tree (read-tree N)))\n (princ (solve N tree))\n (fresh-line)))\n\n(defun solve (N tree)\n (let ((expt-2 (make-array N))\n (parent (make-array N :initial-element nil))\n (subtree-size (make-array N :initial-element nil))\n (sum-expt-2-subtree 0))\n ; 1, 2, 4, 8, ..., 2^(N - 1) をexpt-2に保存\n (loop for i below N for e = 1 then (mod (* e 2) *modulus*)\n do (setf (aref expt-2 i) e))\n (labels\n ((dfs (stack)\n (when stack\n (let* ((v (pop stack))\n (p (aref parent v)) ; vの親\n (size (aref subtree-size v))) ; vを根とする部分木の頂点数\n (if (aref subtree-size v)\n ; 帰りがけ\n (when p\n (incf sum-expt-2-subtree (1- (aref expt-2 size)))\n (incf sum-expt-2-subtree (1- (aref expt-2 (- N size))))\n (incf (aref subtree-size p) size))\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 ; sum-expt-2-subtree (2^(部分木の頂点数) - 1の総和) を計算\n (dfs (list 0))\n\n (loop repeat (1+ N)\n for e = (+ (* N (1- (aref expt-2 (1- N))))\n (- *modulus* (mod sum-expt-2-subtree *modulus*)))\n then (mod (* e *2-inv*) *modulus*)\n finally (return e)))))\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 (整数間に空白または改行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 : 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2634, "cpu_time_ms": 217, "memory_kb": 31080}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s575825172", "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\" (+ 1 (- B A 1) (min (1- A) (- N B))))\n (format t \"~A\" (floor (/ (- B A) 2))))\n", "language": "Lisp", "metadata": {"date": 1577600568, "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/s575825172.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s575825172", "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\" (+ 1 (- B A 1) (min (1- A) (- N B))))\n (format t \"~A\" (floor (/ (- B A) 2))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 107, "memory_kb": 9704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s906068979", "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(defparemeter 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": 1577599039, "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/s906068979.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s906068979", "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(defparemeter 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 128, "memory_kb": 12516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s299200190", "group_id": "codeNet:p02823", "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 (a (read))\n (b (read)))\n (if (evenp (- b a))\n (println (floor (- b a) 2))\n (println\n (min (+ a (floor (- b a 1) 2))\n (+ (+ (- n b) 1)\n (floor (- n (+ a (+ (- n b) 1))) 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 \"5 2 4\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 4\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 3\n\"\n \"2\n\")))\n", "language": "Lisp", "metadata": {"date": 1577585540, "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/s299200190.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s299200190", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (if (evenp (- b a))\n (println (floor (- b a) 2))\n (println\n (min (+ a (floor (- b a 1) 2))\n (+ (+ (- n b) 1)\n (floor (- n (+ a (+ (- n b) 1))) 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 \"5 2 4\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 3\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 4\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 3\n\"\n \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4080, "cpu_time_ms": 170, "memory_kb": 18916}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s402007962", "group_id": "codeNet:p02824", "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 \"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 (inline sort))\n (let* ((n (read))\n (m (read))\n (v (read))\n (p (read))\n (as (make-array n :element-type 'uint32)))\n (declare (uint31 n m v p))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (println\n (let ((as (sort as #'>)))\n (if (<= v p)\n ;; V <= PならターゲットのA_kはA_k+Mにできて、\n ;; p番目に大きいA_{p-1}以上になればOK\n (let ((threshold (aref as (- p 1))))\n (loop for a across as\n count (>= (+ a m) threshold)))\n ;; V > Pの場合、先頭P-1個には足し続ける(+M)。ターゲットにもたし続ける(+M)\n ;; 残りの(V-P)M票を分散して投票する\n (let ((as (subseq as (- p 1))))\n (labels ((feasible-p (as target sum)\n (declare (fixnum target sum))\n ;; sum 相投票量\n (let ((len (length as)))\n (loop for i from (- len 1) downto 0\n for dest = (min (+ (aref as i) m) (+ target m))\n do (decf sum (- dest (aref as i))))\n (<= sum 0))))\n ;; 0は絶対OK\n (sb-int:named-let bisect ((ok 0) (ng (length as)))\n (if (<= (- ng ok) 1)\n (+ p ok)\n (let* ((mid (ash (+ ok ng) -1))\n (excluded-as (remove (aref as mid) as :count 1)))\n (if (feasible-p excluded-as (aref as mid) (* m (- v p)))\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 \"6 1 2 2\n2 1 1 3 0 2\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1 5 2\n2 1 1 3 0 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 4 8 5\n7 2 3 6 1 6 5 4 6 5\n\"\n \"8\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1 2 2\n2 1 1 3 0 2\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1 5 2\n2 1 1 3 0 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 4 8 5\n7 2 3 6 1 6 5 4 6 5\n\"\n \"8\n\")))\n", "language": "Lisp", "metadata": {"date": 1577587958, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02824.html", "problem_id": "p02824", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02824/input.txt", "sample_output_relpath": "derived/input_output/data/p02824/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02824/Lisp/s402007962.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s402007962", "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 ;; 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 (declare (inline sort))\n (let* ((n (read))\n (m (read))\n (v (read))\n (p (read))\n (as (make-array n :element-type 'uint32)))\n (declare (uint31 n m v p))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (println\n (let ((as (sort as #'>)))\n (if (<= v p)\n ;; V <= PならターゲットのA_kはA_k+Mにできて、\n ;; p番目に大きいA_{p-1}以上になればOK\n (let ((threshold (aref as (- p 1))))\n (loop for a across as\n count (>= (+ a m) threshold)))\n ;; V > Pの場合、先頭P-1個には足し続ける(+M)。ターゲットにもたし続ける(+M)\n ;; 残りの(V-P)M票を分散して投票する\n (let ((as (subseq as (- p 1))))\n (labels ((feasible-p (as target sum)\n (declare (fixnum target sum))\n ;; sum 相投票量\n (let ((len (length as)))\n (loop for i from (- len 1) downto 0\n for dest = (min (+ (aref as i) m) (+ target m))\n do (decf sum (- dest (aref as i))))\n (<= sum 0))))\n ;; 0は絶対OK\n (sb-int:named-let bisect ((ok 0) (ng (length as)))\n (if (<= (- ng ok) 1)\n (+ p ok)\n (let* ((mid (ash (+ ok ng) -1))\n (excluded-as (remove (aref as mid) as :count 1)))\n (if (feasible-p excluded-as (aref as mid) (* m (- v p)))\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 \"6 1 2 2\n2 1 1 3 0 2\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1 5 2\n2 1 1 3 0 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 4 8 5\n7 2 3 6 1 6 5 4 6 5\n\"\n \"8\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1 2 2\n2 1 1 3 0 2\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 1 5 2\n2 1 1 3 0 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 4 8 5\n7 2 3 6 1 6 5 4 6 5\n\"\n \"8\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nN problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points.\n\nM judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges,\nand increase the score of each chosen problem by 1.\n\nAfter all M judges cast their vote, the problems will be sorted in non-increasing order of score, and the first P problems will be chosen for the problemset.\nProblems with the same score can be ordered arbitrarily, this order is decided by the chief judge.\n\nHow many problems out of the given N have a chance to be chosen for the problemset?\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le M \\le 10^9\n\n1 \\le V \\le N - 1\n\n1 \\le P \\le N - 1\n\n0 \\le A_i \\le 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M V P\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the number of problems that have a chance to be chosen for the problemset.\n\nSample Input 1\n\n6 1 2 2\n2 1 1 3 0 2\n\nSample Output 1\n\n5\n\nIf the only judge votes for problems 2 and 5, the scores will be 2 2 1 3 1 2.\nThe problemset will consist of problem 4 and one of problems 1, 2, or 6.\n\nIf the only judge votes for problems 3 and 4, the scores will be 2 1 2 4 0 2.\nThe problemset will consist of problem 4 and one of problems 1, 3, or 6.\n\nThus, problems 1, 2, 3, 4, and 6 have a chance to be chosen for the problemset. On the contrary, there is no way for problem 5 to be chosen.\n\nSample Input 2\n\n6 1 5 2\n2 1 1 3 0 2\n\nSample Output 2\n\n3\n\nOnly problems 1, 4, and 6 have a chance to be chosen.\n\nSample Input 3\n\n10 4 8 5\n7 2 3 6 1 6 5 4 6 5\n\nSample Output 3\n\n8", "sample_input": "6 1 2 2\n2 1 1 3 0 2\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02824", "source_text": "Score : 700 points\n\nProblem Statement\n\nN problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points.\n\nM judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges,\nand increase the score of each chosen problem by 1.\n\nAfter all M judges cast their vote, the problems will be sorted in non-increasing order of score, and the first P problems will be chosen for the problemset.\nProblems with the same score can be ordered arbitrarily, this order is decided by the chief judge.\n\nHow many problems out of the given N have a chance to be chosen for the problemset?\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le M \\le 10^9\n\n1 \\le V \\le N - 1\n\n1 \\le P \\le N - 1\n\n0 \\le A_i \\le 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M V P\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the number of problems that have a chance to be chosen for the problemset.\n\nSample Input 1\n\n6 1 2 2\n2 1 1 3 0 2\n\nSample Output 1\n\n5\n\nIf the only judge votes for problems 2 and 5, the scores will be 2 2 1 3 1 2.\nThe problemset will consist of problem 4 and one of problems 1, 2, or 6.\n\nIf the only judge votes for problems 3 and 4, the scores will be 2 1 2 4 0 2.\nThe problemset will consist of problem 4 and one of problems 1, 3, or 6.\n\nThus, problems 1, 2, 3, 4, and 6 have a chance to be chosen for the problemset. On the contrary, there is no way for problem 5 to be chosen.\n\nSample Input 2\n\n6 1 5 2\n2 1 1 3 0 2\n\nSample Output 2\n\n3\n\nOnly problems 1, 4, and 6 have a chance to be chosen.\n\nSample Input 3\n\n10 4 8 5\n7 2 3 6 1 6 5 4 6 5\n\nSample Output 3\n\n8", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6943, "cpu_time_ms": 301, "memory_kb": 37864}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s614301549", "group_id": "codeNet:p02825", "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\n(defun main ()\n (let* ((n (read)))\n (when (= n 5)\n (println -1)\n (return-from main))\n (error \"Huh?\")))\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 \"6\n\"\n \"aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n\"\n \"aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n\"\n \"-1\n\")))\n", "language": "Lisp", "metadata": {"date": 1577589857, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02825.html", "problem_id": "p02825", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02825/input.txt", "sample_output_relpath": "derived/input_output/data/p02825/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02825/Lisp/s614301549.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s614301549", "user_id": "u352600849"}, "prompt_components": {"gold_output": "aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\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\n(defun main ()\n (let* ((n (read)))\n (when (= n 5)\n (println -1)\n (return-from main))\n (error \"Huh?\")))\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 \"6\n\"\n \"aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n\"\n \"aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n\"\n \"-1\n\")))\n", "problem_context": "Score : 900 points\n\nProblem Statement\n\nLet us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid.\nEach domino piece covers two squares that have a common side. Each square can be covered by at most one piece.\n\nFor each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row.\nWe define the quality of each column similarly.\n\nFind a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column,\nor determine that such a placement doesn't exist.\n\nConstraints\n\n2 \\le N \\le 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf the required domino placement doesn't exist, print a single integer -1.\n\nOtherwise, output your placement as N strings of N characters each.\nIf a square is not covered, the corresponding character must be . (a dot).\nOtherwise, it must contain a lowercase English letter.\nSquares covered by the same domino piece must contain the same letter.\nIf two squares have a common side but belong to different pieces, they must contain different letters.\n\nSample Input 1\n\n6\n\nSample Output 1\n\naabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n\nThe quality of every row and every column is 2.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n-1", "sample_input": "6\n"}, "reference_outputs": ["aabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n"], "source_document_id": "p02825", "source_text": "Score : 900 points\n\nProblem Statement\n\nLet us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid.\nEach domino piece covers two squares that have a common side. Each square can be covered by at most one piece.\n\nFor each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row.\nWe define the quality of each column similarly.\n\nFind a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column,\nor determine that such a placement doesn't exist.\n\nConstraints\n\n2 \\le N \\le 1000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIf the required domino placement doesn't exist, print a single integer -1.\n\nOtherwise, output your placement as N strings of N characters each.\nIf a square is not covered, the corresponding character must be . (a dot).\nOtherwise, it must contain a lowercase English letter.\nSquares covered by the same domino piece must contain the same letter.\nIf two squares have a common side but belong to different pieces, they must contain different letters.\n\nSample Input 1\n\n6\n\nSample Output 1\n\naabb..\nb..zz.\nba....\n.a..aa\n..a..b\n..a..b\n\nThe quality of every row and every column is 2.\n\nSample Input 2\n\n2\n\nSample Output 2\n\n-1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3984, "cpu_time_ms": 147, "memory_kb": 16104}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s606196171", "group_id": "codeNet:p02829", "input_text": "(let ((a (read)) (b (read)))\n (if (and (not (eq a 1)) (not (eq b 1)))\n\t(princ 1)\n\t(if (and (not (eq a 2)) (not (eq b 2)))\n\t (princ 2)\n\t (princ 3))))\n", "language": "Lisp", "metadata": {"date": 1577070137, "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/s606196171.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s606196171", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((a (read)) (b (read)))\n (if (and (not (eq a 1)) (not (eq b 1)))\n\t(princ 1)\n\t(if (and (not (eq a 2)) (not (eq b 2)))\n\t (princ 2)\n\t (princ 3))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 59, "memory_kb": 7648}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s264141231", "group_id": "codeNet:p02830", "input_text": "(let ((n (read))\n (s-read (read))\n (t-read (read)))\n\n (dotimes (i n)\n (format t \"~(~A~)\" (subseq (string s-read) i (+ i 1)))\n (format t \"~(~A~)\" (subseq (string t-read) i (+ i 1)))\n )\n)", "language": "Lisp", "metadata": {"date": 1593700173, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s264141231.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s264141231", "user_id": "u136500538"}, "prompt_components": {"gold_output": "icpc\n", "input_to_evaluate": "(let ((n (read))\n (s-read (read))\n (t-read (read)))\n\n (dotimes (i n)\n (format t \"~(~A~)\" (subseq (string s-read) i (+ i 1)))\n (format t \"~(~A~)\" (subseq (string t-read) i (+ i 1)))\n )\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 23696}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s792711967", "group_id": "codeNet:p02830", "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)))a", "language": "Lisp", "metadata": {"date": 1589123538, "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/s792711967.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s792711967", "user_id": "u425762225"}, "prompt_components": {"gold_output": "icpc\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)))a", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 327, "cpu_time_ms": 149, "memory_kb": 13668}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s658018346", "group_id": "codeNet:p02830", "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 N (parse-integer (read-line)))\n(defparameter lst (split \" \" (read-line)))\n\n(defparameter *my-string* (make-array 0\n :element-type 'character\n :fill-pointer 0\n :adjustable t))\n\n(loop for i from 0 below N do\n (vector-push-extend (char (car lst) i) *my-string*)\n (vector-push-extend (char (cadr lst) i) *my-string*))\n\n(format t \"~A\" *my-string*)\n", "language": "Lisp", "metadata": {"date": 1577069632, "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/s658018346.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s658018346", "user_id": "u425317134"}, "prompt_components": {"gold_output": "icpc\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 N (parse-integer (read-line)))\n(defparameter lst (split \" \" (read-line)))\n\n(defparameter *my-string* (make-array 0\n :element-type 'character\n :fill-pointer 0\n :adjustable t))\n\n(loop for i from 0 below N do\n (vector-push-extend (char (car lst) i) *my-string*)\n (vector-push-extend (char (cadr lst) i) *my-string*))\n\n(format t \"~A\" *my-string*)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 668, "cpu_time_ms": 111, "memory_kb": 12388}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s550030203", "group_id": "codeNet:p02831", "input_text": "(format t \"~A~%\" (lcm (read) (read)))\n", "language": "Lisp", "metadata": {"date": 1593747679, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s550030203.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s550030203", "user_id": "u608227593"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(format t \"~A~%\" (lcm (read) (read)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 24100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s853256974", "group_id": "codeNet:p02831", "input_text": "(defun abc148c ()\n (format t \"~a~%\" (lcm (read) (read))))\n(abc148c)", "language": "Lisp", "metadata": {"date": 1586654341, "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/s853256974.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s853256974", "user_id": "u652695471"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defun abc148c ()\n (format t \"~a~%\" (lcm (read) (read))))\n(abc148c)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 95, "memory_kb": 9828}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s310826486", "group_id": "codeNet:p02831", "input_text": "(let ((a (read)) (b (read)))\n (princ (lcm a b)))\n", "language": "Lisp", "metadata": {"date": 1577070634, "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/s310826486.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s310826486", "user_id": "u493610446"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let ((a (read)) (b (read)))\n (princ (lcm a b)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 12, "memory_kb": 3300}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s992837197", "group_id": "codeNet:p02832", "input_text": "(let* ((n (read))\n (d 0))\n (loop :for i :from 1 :to n\n :for a := (read)\n :if (/= a (- i d))\n :do (incf d))\n (format t \"~A~%\" (if (= d n) -1 d)))\n", "language": "Lisp", "metadata": {"date": 1599855139, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s992837197.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s992837197", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (d 0))\n (loop :for i :from 1 :to n\n :for a := (read)\n :if (/= a (- i d))\n :do (incf d))\n (format t \"~A~%\" (if (= d n) -1 d)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 204, "memory_kb": 77044}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s152337493", "group_id": "codeNet:p02832", "input_text": "\n(defun maximal-natural-sequence-0 (arr)\n (labels ((rec (i)\n\t\t(when (= (1+ i) (length arr))\n\t\t (return-from rec 1))\n\t\t(1+ (loop for j from (1+ i) below (length arr)\n\t\t\t when (= (aref arr j) (1+ (aref arr i)))\n\t\t\t maximizing (rec j)))))\n\t (let ((a (loop for i from 0 below (length arr)\n\t\t\t when (= (aref arr i) 1) maximizing\n\t\t\t (rec i))))\n\t (if (= a 0)\n\t\t-1\n\t\t(- (length arr) a)))))\n\n(defun maximal-natural-sequence-1 (arr)\n (let ((table (make-array (length arr))))\n (setf (aref table (1- (length arr))) 1)\n (loop for i from (- (length arr) 2) downto 0 do\n\t (setf (aref table i)\n\t\t(1+ (loop for j from (1+ i) below (length arr)\n\t\t\t when (= (aref arr j) (1+ (aref arr i)))\n\t\t\t maximizing (aref table j)))))\n (loop for i from 0 below (length arr)\n\t when (= 1 (aref arr i))\n\t maximizing (aref table i))))\n\n(let* ((n (read))\n (a (make-array n))\n (has-1 nil))\n (dotimes (i n)\n (let ((r (read)))\n (when (= r 1) (setf has-1 t))\n (setf (aref a i) r)))\n (unless has-1\n (princ -1)\n (exit))\n (princ (- n (maximal-natural-sequence-1 a))))\n", "language": "Lisp", "metadata": {"date": 1591611171, "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/s152337493.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s152337493", "user_id": "u203134021"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "\n(defun maximal-natural-sequence-0 (arr)\n (labels ((rec (i)\n\t\t(when (= (1+ i) (length arr))\n\t\t (return-from rec 1))\n\t\t(1+ (loop for j from (1+ i) below (length arr)\n\t\t\t when (= (aref arr j) (1+ (aref arr i)))\n\t\t\t maximizing (rec j)))))\n\t (let ((a (loop for i from 0 below (length arr)\n\t\t\t when (= (aref arr i) 1) maximizing\n\t\t\t (rec i))))\n\t (if (= a 0)\n\t\t-1\n\t\t(- (length arr) a)))))\n\n(defun maximal-natural-sequence-1 (arr)\n (let ((table (make-array (length arr))))\n (setf (aref table (1- (length arr))) 1)\n (loop for i from (- (length arr) 2) downto 0 do\n\t (setf (aref table i)\n\t\t(1+ (loop for j from (1+ i) below (length arr)\n\t\t\t when (= (aref arr j) (1+ (aref arr i)))\n\t\t\t maximizing (aref table j)))))\n (loop for i from 0 below (length arr)\n\t when (= 1 (aref arr i))\n\t maximizing (aref table i))))\n\n(let* ((n (read))\n (a (make-array n))\n (has-1 nil))\n (dotimes (i n)\n (let ((r (read)))\n (when (= r 1) (setf has-1 t))\n (setf (aref a i) r)))\n (unless has-1\n (princ -1)\n (exit))\n (princ (- n (maximal-natural-sequence-1 a))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1084, "cpu_time_ms": 2105, "memory_kb": 61728}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s083361316", "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 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 make-bit-combinations (n)\n (sort (loop for i from 0 below (1- (expt 2 n))\n collect i)\n #'<\n :key #'logcount))\n \n (defun solve (n bricks)\n (loop for bits in (make-bit-combinations n)\n if (check-bits n bits bricks)\n do (return (logcount bits))\n finally (return -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)))", "language": "Lisp", "metadata": {"date": 1577079837, "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/s083361316.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s083361316", "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 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 make-bit-combinations (n)\n (sort (loop for i from 0 below (1- (expt 2 n))\n collect i)\n #'<\n :key #'logcount))\n \n (defun solve (n bricks)\n (loop for bits in (make-bit-combinations n)\n if (check-bits n bits bricks)\n do (return (logcount bits))\n finally (return -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)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1365, "cpu_time_ms": 2116, "memory_kb": 683320}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s778462331", "group_id": "codeNet:p02833", "input_text": "(let* ((n (read)))\n (princ (if (evenp n)\n (progn (setf n (/ n 2))\n (loop :for k :from 1 :until (= 0 (floor n (expt 5 k))) :sum (floor n (expt 5 k))) )\n 0)))", "language": "Lisp", "metadata": {"date": 1577132421, "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/s778462331.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s778462331", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read)))\n (princ (if (evenp n)\n (progn (setf n (/ n 2))\n (loop :for k :from 1 :until (= 0 (floor n (expt 5 k))) :sum (floor n (expt 5 k))) )\n 0)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 4452}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s806680940", "group_id": "codeNet:p02833", "input_text": "(defun /5 (n)\n (/5-f n 0))\n(defun /5-f (n k)\n (if (= 0 (mod n 5))\n (/5-f (/ n 5) (1+ k))\n k))\n(let* ((n (read)))\n (princ (if (evenp n)\n (loop :for k :from n :downto 1 :by 2 :sum (/5 k))\n 0)))\n", "language": "Lisp", "metadata": {"date": 1577130249, "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/s806680940.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s806680940", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun /5 (n)\n (/5-f n 0))\n(defun /5-f (n k)\n (if (= 0 (mod n 5))\n (/5-f (/ n 5) (1+ k))\n k))\n(let* ((n (read)))\n (princ (if (evenp n)\n (loop :for k :from n :downto 1 :by 2 :sum (/5 k))\n 0)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 229, "cpu_time_ms": 2104, "memory_kb": 4580}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s291557428", "group_id": "codeNet:p02833", "input_text": "(defun solve (n)\n (if (= (rem n 2) 0)\n (progn\n (setf n (floor n 2))\n (loop until (zerop n)\n sum (setf n (floor n 5))))\n 0))\n\n#-swank\n(let ((n (read)))\n (format t \"~A~%\" (solve n)))\n", "language": "Lisp", "metadata": {"date": 1577081253, "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/s291557428.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s291557428", "user_id": "u202886318"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun solve (n)\n (if (= (rem n 2) 0)\n (progn\n (setf n (floor n 2))\n (loop until (zerop n)\n sum (setf n (floor n 5))))\n 0))\n\n#-swank\n(let ((n (read)))\n (format t \"~A~%\" (solve n)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 220, "cpu_time_ms": 137, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s837847600", "group_id": "codeNet:p02833", "input_text": "(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)\n", "language": "Lisp", "metadata": {"date": 1577079192, "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/s837847600.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s837847600", "user_id": "u425317134"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(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)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 325, "cpu_time_ms": 73, "memory_kb": 8164}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s263195858", "group_id": "codeNet:p02838", "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 (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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint62))\n (res 0))\n (declare (uint31 res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (pos 61)\n (let* ((base (ash 1 pos))\n (x (loop for a across as\n count (zerop (logand base a))))\n (y (- n x)))\n (declare (uint31 x y))\n (incfmod res (mod* x y (mod base +mod+)))))\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\n1 2 3\n\"\n \"6\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 \"237\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820\n\"\n \"103715602\n\")))\n", "language": "Lisp", "metadata": {"date": 1575863168, "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/s263195858.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s263195858", "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;;;\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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint62))\n (res 0))\n (declare (uint31 res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (pos 61)\n (let* ((base (ash 1 pos))\n (x (loop for a across as\n count (zerop (logand base a))))\n (y (- n x)))\n (declare (uint31 x y))\n (incfmod res (mod* x y (mod base +mod+)))))\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\n1 2 3\n\"\n \"6\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 \"237\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820\n\"\n \"103715602\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6213, "cpu_time_ms": 262, "memory_kb": 28904}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s731870976", "group_id": "codeNet:p02838", "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(lst)\n (labels ((rec (lst a acc)\n (if (null lst)\n acc\n (rec (cdr lst) a (+ acc (logxor a (car lst))))))\n (rec0 (lst acc)\n (if (null (cdr lst))\n acc\n (rec0 (cdr lst) (rec (cdr lst) (car lst) acc)))))\n (rec0 lst 0)))\n(let* ((line0 (read-line nil nil))\n (line1 (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (mod (f line1) (+ 7 (expt 10 9)))))\n", "language": "Lisp", "metadata": {"date": 1575860594, "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/s731870976.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s731870976", "user_id": "u254205055"}, "prompt_components": {"gold_output": "6\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(lst)\n (labels ((rec (lst a acc)\n (if (null lst)\n acc\n (rec (cdr lst) a (+ acc (logxor a (car lst))))))\n (rec0 (lst acc)\n (if (null (cdr lst))\n acc\n (rec0 (cdr lst) (rec (cdr lst) (car lst) acc)))))\n (rec0 lst 0)))\n(let* ((line0 (read-line nil nil))\n (line1 (mapcar #'parse-integer (splitat #\\space (read-line nil nil)))))\n (format t \"~A~%\" (mod (f line1) (+ 7 (expt 10 9)))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2106, "memory_kb": 322632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s725370017", "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 (format nil \"~3,'0d\" i)\n (let ((f 0))\n (loop for j in s do\n (progn\n (if (eq j (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": 1594816091, "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/s725370017.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s725370017", "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 (format nil \"~3,'0d\" i)\n (let ((f 0))\n (loop for j in s do\n (progn\n (if (eq j (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 77, "memory_kb": 25472}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s922041032", "group_id": "codeNet:p02844", "input_text": "(let* ((n (read))\n (s (make-array n))\n (a (make-array 3 :initial-element 0 :element-type 'fixnum))\n (ans 0))\n (dotimes (i n)\n (setf (aref s i) (read-char))\n )\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= (aref 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": 1594740876, "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/s922041032.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s922041032", "user_id": "u136500538"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let* ((n (read))\n (s (make-array n))\n (a (make-array 3 :initial-element 0 :element-type 'fixnum))\n (ans 0))\n (dotimes (i n)\n (setf (aref s i) (read-char))\n )\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= (aref 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2207, "memory_kb": 78156}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s309892605", "group_id": "codeNet:p02847", "input_text": "(let ((s (read-line)))\n (cond ((string= s \"SUN\")\n (format t \"7~%\"))\n ((string= s \"MON\")\n (format t \"6~%\"))\n ((string= s \"TUE\")\n (format t \"5~%\"))\n ((string= s \"WED\")\n (format t \"4~%\"))\n ((string= s \"THU\")\n (format t \"3~%\"))\n ((string= s \"FRI\")\n (format t \"2~%\"))\n ((string= s \"SAT\")\n (format t \"1~%\"))))\n", "language": "Lisp", "metadata": {"date": 1593989620, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02847.html", "problem_id": "p02847", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02847/input.txt", "sample_output_relpath": "derived/input_output/data/p02847/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02847/Lisp/s309892605.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s309892605", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((s (read-line)))\n (cond ((string= s \"SUN\")\n (format t \"7~%\"))\n ((string= s \"MON\")\n (format t \"6~%\"))\n ((string= s \"TUE\")\n (format t \"5~%\"))\n ((string= s \"WED\")\n (format t \"4~%\"))\n ((string= s \"THU\")\n (format t \"3~%\"))\n ((string= s \"FRI\")\n (format t \"2~%\"))\n ((string= s \"SAT\")\n (format t \"1~%\"))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven is a string S representing the day of the week today.\n\nS is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.\n\nAfter how many days is the next Sunday (tomorrow or later)?\n\nConstraints\n\nS is SUN, MON, TUE, WED, THU, FRI, or SAT.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the number of days before the next Sunday.\n\nSample Input 1\n\nSAT\n\nSample Output 1\n\n1\n\nIt is Saturday today, and tomorrow will be Sunday.\n\nSample Input 2\n\nSUN\n\nSample Output 2\n\n7\n\nIt is Sunday today, and seven days later, it will be Sunday again.", "sample_input": "SAT\n"}, "reference_outputs": ["1\n"], "source_document_id": "p02847", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven is a string S representing the day of the week today.\n\nS is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.\n\nAfter how many days is the next Sunday (tomorrow or later)?\n\nConstraints\n\nS is SUN, MON, TUE, WED, THU, FRI, or SAT.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the number of days before the next Sunday.\n\nSample Input 1\n\nSAT\n\nSample Output 1\n\n1\n\nIt is Saturday today, and tomorrow will be Sunday.\n\nSample Input 2\n\nSUN\n\nSample Output 2\n\n7\n\nIt is Sunday today, and seven days later, it will be Sunday again.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 403, "cpu_time_ms": 18, "memory_kb": 23420}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s681088800", "group_id": "codeNet:p02850", "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;; -*- 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;; 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 (let* ((n (read))\n (as (make-array (- n 1) :element-type 'uint32))\n (bs (make-array (- n 1) :element-type 'uint32))\n (graph (make-array n :element-type 'list :initial-element nil))\n (table (make-hash-table :test #'equal)))\n (declare (uint32 n))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (setf (aref as i) a\n (aref bs i) b)\n (push a (aref graph b))\n (push b (aref graph a))))\n (sb-int:named-let dfs ((v 0) (parent -1) (parent-color -1))\n (declare (int32 v parent parent-color))\n (let ((color (if (zerop parent-color) 1 0)))\n (dolist (next (aref graph v))\n (declare (uint32 next))\n (unless (= parent next)\n (if (> v next)\n (setf (gethash (cons next v) table) color)\n (setf (gethash (cons v next) table) color))\n (dfs next v color)\n (incf color)\n (when (= color parent-color)\n (incf color))))))\n (println (+ 1 (loop for color being each hash-value of table maximize color)))\n (with-buffered-stdout\n (dotimes (i (- n 1))\n (let ((a (aref as i))\n (b (aref bs i)))\n (dbg a b)\n (println (+ 1 (gethash (cons a b) 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\n1 2\n2 3\n\"\n \"2\n1\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1 2\n2 3\n2 4\n2 5\n4 7\n5 6\n6 8\n\"\n \"4\n1\n2\n3\n4\n1\n1\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n1 2\n1 3\n1 4\n1 5\n1 6\n\"\n \"5\n1\n2\n3\n4\n5\n\")))\n", "language": "Lisp", "metadata": {"date": 1574653529, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02850.html", "problem_id": "p02850", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02850/input.txt", "sample_output_relpath": "derived/input_output/data/p02850/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02850/Lisp/s681088800.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s681088800", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n1\n2\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;; -*- 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;; 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 (let* ((n (read))\n (as (make-array (- n 1) :element-type 'uint32))\n (bs (make-array (- n 1) :element-type 'uint32))\n (graph (make-array n :element-type 'list :initial-element nil))\n (table (make-hash-table :test #'equal)))\n (declare (uint32 n))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (setf (aref as i) a\n (aref bs i) b)\n (push a (aref graph b))\n (push b (aref graph a))))\n (sb-int:named-let dfs ((v 0) (parent -1) (parent-color -1))\n (declare (int32 v parent parent-color))\n (let ((color (if (zerop parent-color) 1 0)))\n (dolist (next (aref graph v))\n (declare (uint32 next))\n (unless (= parent next)\n (if (> v next)\n (setf (gethash (cons next v) table) color)\n (setf (gethash (cons v next) table) color))\n (dfs next v color)\n (incf color)\n (when (= color parent-color)\n (incf color))))))\n (println (+ 1 (loop for color being each hash-value of table maximize color)))\n (with-buffered-stdout\n (dotimes (i (- n 1))\n (let ((a (aref as i))\n (b (aref bs i)))\n (dbg a b)\n (println (+ 1 (gethash (cons a b) 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\n1 2\n2 3\n\"\n \"2\n1\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n1 2\n2 3\n2 4\n2 5\n4 7\n5 6\n6 8\n\"\n \"4\n1\n2\n3\n4\n1\n1\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n1 2\n1 3\n1 4\n1 5\n1 6\n\"\n \"5\n1\n2\n3\n4\n5\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven is a tree G with N vertices.\nThe vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i.\n\nConsider painting the edges in G with some number of colors.\nWe want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.\n\nAmong the colorings satisfying the condition above, construct one that uses the minimum number of colors.\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le a_i \\lt b_i \\le N\n\nAll values in input are integers.\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\na_2 b_2\n\\vdots\na_{N-1} b_{N-1}\n\nOutput\n\nPrint N lines.\n\nThe first line should contain K, the number of colors used.\n\nThe (i+1)-th line (1 \\le i \\le N-1) should contain c_i, the integer representing the color of the i-th edge, where 1 \\le c_i \\le K must hold.\n\nIf there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\n2\n1\n2\n\nSample Input 2\n\n8\n1 2\n2 3\n2 4\n2 5\n4 7\n5 6\n6 8\n\nSample Output 2\n\n4\n1\n2\n3\n4\n1\n1\n2\n\nSample Input 3\n\n6\n1 2\n1 3\n1 4\n1 5\n1 6\n\nSample Output 3\n\n5\n1\n2\n3\n4\n5", "sample_input": "3\n1 2\n2 3\n"}, "reference_outputs": ["2\n1\n2\n"], "source_document_id": "p02850", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven is a tree G with N vertices.\nThe vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i.\n\nConsider painting the edges in G with some number of colors.\nWe want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.\n\nAmong the colorings satisfying the condition above, construct one that uses the minimum number of colors.\n\nConstraints\n\n2 \\le N \\le 10^5\n\n1 \\le a_i \\lt b_i \\le N\n\nAll values in input are integers.\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\na_2 b_2\n\\vdots\na_{N-1} b_{N-1}\n\nOutput\n\nPrint N lines.\n\nThe first line should contain K, the number of colors used.\n\nThe (i+1)-th line (1 \\le i \\le N-1) should contain c_i, the integer representing the color of the i-th edge, where 1 \\le c_i \\le K must hold.\n\nIf there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.\n\nSample Input 1\n\n3\n1 2\n2 3\n\nSample Output 1\n\n2\n1\n2\n\nSample Input 2\n\n8\n1 2\n2 3\n2 4\n2 5\n4 7\n5 6\n6 8\n\nSample Output 2\n\n4\n1\n2\n3\n4\n1\n1\n2\n\nSample Input 3\n\n6\n1 2\n1 3\n1 4\n1 5\n1 6\n\nSample Output 3\n\n5\n1\n2\n3\n4\n5", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7045, "cpu_time_ms": 277, "memory_kb": 38204}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s116434767", "group_id": "codeNet:p02859", "input_text": "(defun main ()\n (let* ((r (read)))\n (format t \"~a~%\" (* r r))))\n(main)", "language": "Lisp", "metadata": {"date": 1574017170, "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/s116434767.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s116434767", "user_id": "u652695471"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun main ()\n (let* ((r (read)))\n (format t \"~a~%\" (* r r))))\n(main)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 127, "memory_kb": 10980}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s735070102", "group_id": "codeNet:p02867", "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;;; 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(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(defpackage :cp/inverse-table\n (:use :cl)\n (:export #:make-inverse-table #:make-monotone-inverse-table!))\n(in-package :cp/inverse-table)\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;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/inverse-table :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(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/parallel-sort :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort sb-impl::stable-sort-list))\n (let* ((n (read))\n (as (make-array n :element-type 'uint31 :initial-element 0))\n (bs (make-array n :element-type 'uint31 :initial-element 0)))\n (labels ((no () (write-line \"No\") (return-from main))\n (yes () (write-line \"Yes\") (return-from main)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (setf (aref bs i) (read-fixnum)))\n (parallel-sort! bs #'< as)\n (let ((sorted-as (sort (copy-seq as) #'<)))\n ;; ソートしてNGならNo\n (when (loop for a across sorted-as\n for b across bs\n thereis (> a b))\n (no))\n ;; aに同じ要素があればYes\n (let ((table (make-hash-table :test #'eq)))\n (loop for a across as\n do (setf (gethash a table) t))\n (when (< (hash-table-count table) n)\n (yes)))\n ;; 1つぶん余裕があればYes\n (loop for i from 1 below n\n when (< (aref sorted-as i) (aref bs (- i 1)))\n do (yes))\n (let ((table (make-inverse-table sorted-as)))\n (dotimes (i n)\n (setf (aref as i) (gethash (aref as i) table))))\n (let ((cycles (decompose-to-cycles as)))\n (if (= (length cycles) 1)\n (no)\n (yes)))))))\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 \"3\n1 3 2\n1 2 3\n\" nil)))\n (5am:is\n (equal \"No\n\"\n (run \"3\n1 2 3\n2 2 2\n\" nil)))\n (5am:is\n (equal \"Yes\n\"\n (run \"6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600770033, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s735070102.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s735070102", "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;;;\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(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(defpackage :cp/inverse-table\n (:use :cl)\n (:export #:make-inverse-table #:make-monotone-inverse-table!))\n(in-package :cp/inverse-table)\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;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/inverse-table :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(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/parallel-sort :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort sb-impl::stable-sort-list))\n (let* ((n (read))\n (as (make-array n :element-type 'uint31 :initial-element 0))\n (bs (make-array n :element-type 'uint31 :initial-element 0)))\n (labels ((no () (write-line \"No\") (return-from main))\n (yes () (write-line \"Yes\") (return-from main)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (setf (aref bs i) (read-fixnum)))\n (parallel-sort! bs #'< as)\n (let ((sorted-as (sort (copy-seq as) #'<)))\n ;; ソートしてNGならNo\n (when (loop for a across sorted-as\n for b across bs\n thereis (> a b))\n (no))\n ;; aに同じ要素があればYes\n (let ((table (make-hash-table :test #'eq)))\n (loop for a across as\n do (setf (gethash a table) t))\n (when (< (hash-table-count table) n)\n (yes)))\n ;; 1つぶん余裕があればYes\n (loop for i from 1 below n\n when (< (aref sorted-as i) (aref bs (- i 1)))\n do (yes))\n (let ((table (make-inverse-table sorted-as)))\n (dotimes (i n)\n (setf (aref as i) (gethash (aref as i) table))))\n (let ((cycles (decompose-to-cycles as)))\n (if (= (length cycles) 1)\n (no)\n (yes)))))))\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 \"3\n1 3 2\n1 2 3\n\" nil)))\n (5am:is\n (equal \"No\n\"\n (run \"3\n1 2 3\n2 2 2\n\" nil)))\n (5am:is\n (equal \"Yes\n\"\n (run \"6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\" nil))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13282, "cpu_time_ms": 81, "memory_kb": 39700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s767245228", "group_id": "codeNet:p02867", "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;;; 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(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;; BEGIN_USE_PACKAGE\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(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/parallel-sort :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort sb-impl::stable-sort-list))\n (let* ((n (read))\n (as (make-array n :element-type 'uint31 :initial-element 0))\n (bs (make-array n :element-type 'uint31 :initial-element 0)))\n (labels ((no () (write-line \"No\") (return-from main))\n (yes () (write-line \"Yes\") (return-from main)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (setf (aref bs i) (read-fixnum)))\n (parallel-sort! bs #'< as)\n (let ((sorted-as (sort (copy-seq as) #'<)))\n (when (loop for a across sorted-as\n for b across bs\n thereis (> a b))\n (no)))\n (let ((table (make-hash-table :test #'eq)))\n (loop for a across as\n do (setf (gethash a table) t))\n (when (< (hash-table-count table) n)\n (yes)))\n (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#-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 \"3\n1 3 2\n1 2 3\n\" nil)))\n (5am:is\n (equal \"No\n\"\n (run \"3\n1 2 3\n2 2 2\n\" nil)))\n (5am:is\n (equal \"Yes\n\"\n (run \"6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600769617, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s767245228.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s767245228", "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;;;\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(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;; BEGIN_USE_PACKAGE\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(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/parallel-sort :cl-user))\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare (inline sort sb-impl::stable-sort-list))\n (let* ((n (read))\n (as (make-array n :element-type 'uint31 :initial-element 0))\n (bs (make-array n :element-type 'uint31 :initial-element 0)))\n (labels ((no () (write-line \"No\") (return-from main))\n (yes () (write-line \"Yes\") (return-from main)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (setf (aref bs i) (read-fixnum)))\n (parallel-sort! bs #'< as)\n (let ((sorted-as (sort (copy-seq as) #'<)))\n (when (loop for a across sorted-as\n for b across bs\n thereis (> a b))\n (no)))\n (let ((table (make-hash-table :test #'eq)))\n (loop for a across as\n do (setf (gethash a table) t))\n (when (< (hash-table-count table) n)\n (yes)))\n (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#-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 \"3\n1 3 2\n1 2 3\n\" nil)))\n (5am:is\n (equal \"No\n\"\n (run \"3\n1 2 3\n2 2 2\n\" nil)))\n (5am:is\n (equal \"Yes\n\"\n (run \"6\n3 1 2 6 3 4\n2 2 8 3 4 3\n\" nil))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11391, "cpu_time_ms": 81, "memory_kb": 38044}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s138928167", "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 new-as i) table)))\n (if (= 1 (length (decompose-to-cycles comped-as)))\n (error \"Huh?\")\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": 1573369481, "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/s138928167.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s138928167", "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 new-as i) table)))\n (if (= 1 (length (decompose-to-cycles comped-as)))\n (error \"Huh?\")\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 21483, "cpu_time_ms": 1222, "memory_kb": 73056}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s720456935", "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 (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 (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": 1600774534, "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/s720456935.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s720456935", "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 (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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14650, "cpu_time_ms": 95, "memory_kb": 33056}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s945682375", "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 (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 (floor cstart 2))\n (bstart (+ 1 (floor cstart 2)))\n rems)\n (dbg astart bstart cstart)\n (loop for a downfrom astart\n for b from bstart by 2\n for c from cstart\n while (and (>= a k) (< b cstart) (< cstart (+ k (* 3 n))))\n do (unless (= (+ a b) c)\n (loop))\n (format out \"~D ~D ~D~%\" a b c)\n (dbg a b c)\n finally (loop for rem-a from a downto k\n do (push rem-a rems))\n (loop for rem-b from (+ bstart 1) below cstart by 2\n do (push rem-b rems))\n (let (treap)\n (dolist (rem rems)\n (treap-push rem treap #'<))\n (dbg a b c)\n (loop for rem-c from c below (+ k (* 3 n))\n for a = (treap-first treap)\n for max-b = (- rem-c a)\n for b = (treap-bisect-right-1 treap max-b)\n do (dbg rem-c a max-b b)\n when (or (null b) (eql a b))\n do (no)\n do (format out \"~D ~D ~D~%\" a b rem-c)\n (treap-pop a treap #'<)\n (treap-pop b treap #'<))))\n (write-string (get-output-stream-string out)))\n (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#-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": 1600773751, "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/s945682375.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s945682375", "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 (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 (floor cstart 2))\n (bstart (+ 1 (floor cstart 2)))\n rems)\n (dbg astart bstart cstart)\n (loop for a downfrom astart\n for b from bstart by 2\n for c from cstart\n while (and (>= a k) (< b cstart) (< cstart (+ k (* 3 n))))\n do (unless (= (+ a b) c)\n (loop))\n (format out \"~D ~D ~D~%\" a b c)\n (dbg a b c)\n finally (loop for rem-a from a downto k\n do (push rem-a rems))\n (loop for rem-b from (+ bstart 1) below cstart by 2\n do (push rem-b rems))\n (let (treap)\n (dolist (rem rems)\n (treap-push rem treap #'<))\n (dbg a b c)\n (loop for rem-c from c below (+ k (* 3 n))\n for a = (treap-first treap)\n for max-b = (- rem-c a)\n for b = (treap-bisect-right-1 treap max-b)\n do (dbg rem-c a max-b b)\n when (or (null b) (eql a b))\n do (no)\n do (format out \"~D ~D ~D~%\" a b rem-c)\n (treap-pop a treap #'<)\n (treap-pop b treap #'<))))\n (write-string (get-output-stream-string out)))\n (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#-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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15503, "cpu_time_ms": 115, "memory_kb": 35960}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s947754527", "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(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(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 priority 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 (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 (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-find (treap key &key (order #'<))\n \"Finds the key that satisfies (and (not (funcall order key (%treap-key\nsub-treap))) (not (funcall order (%treap-key sub-treap) key))) and returns KEY\nand the assigned value. Returns NIL if KEY is not contained.\"\n (declare (function order)\n ((or null treap) treap))\n (cond ((null treap) (values nil nil))\n ((funcall order key (%treap-key treap))\n (treap-find (%treap-left treap) key :order order))\n ((funcall order (%treap-key treap) key)\n (treap-find (%treap-right treap) key :order order))\n (t (values key (%treap-value treap)))))\n\n(defun treap-bisect-right-1 (treap key &key (order #'<))\n \"Returns the largest key equal to or smaller than KEY and the assigned\nvalue. Returns NIL if KEY is smaller 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 (force-down treap)\n (if (funcall order key (%treap-key treap))\n (recur (%treap-left treap))\n (or (recur (%treap-right 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(defun treap-bisect-left (treap key &key (order #'<))\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 ((or null treap) treap)\n (function order))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (force-down treap)\n (if (funcall order (%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 &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 (if (null treap)\n (values nil nil)\n (progn\n (force-down treap)\n (if (funcall order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split (%treap-right treap) key :order order)\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 :order order)\n (setf (%treap-left treap) right)\n (force-up treap)\n (values left treap))))))\n\n(declaim (inline treap-insert))\n(defun treap-insert (treap key value &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 (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 (%treap-key node) :order order))\n (force-up node)\n node)\n (progn\n (if (funcall 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-up treap)\n treap))))\n (recur (%make-treap key (random most-positive-fixnum) value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (treap key value &key (order #'<) 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 already contains KEY, TREAP-ENSURE-KEY\nupdates the value by the function instead of overwriting it with VALUE.\"\n (declare (function order)\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 ((funcall order key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n (force-up treap)\n t))\n ((funcall order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n (force-up treap)\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n (force-up treap)\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert treap key value :order order))))\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 (declare (optimize (speed 3))\n ((or null treap) 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 (> (%treap-priority left) (%treap-priority right))\n (progn\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (force-up right)\n right)))))\n\n(defun treap-delete (treap key &key (order #'<))\n \"Destructively deletes the KEY in TREAP and returns the resultant\ntreap. Returns the unmodified TREAP If KEY doesn't exist. You cannot rely on the\nside effect. Use the returned value.\n\n (Note that this function deletes at most one node even if duplicated keys\nexist.)\"\n (declare ((or null treap) treap)\n (function order))\n (when treap\n (force-down treap)\n (cond ((funcall order key (%treap-key treap))\n (setf (%treap-left treap)\n (treap-delete (%treap-left treap) key :order order))\n (force-up treap)\n treap)\n ((funcall order (%treap-key treap) key)\n (setf (%treap-right treap)\n (treap-delete (%treap-right treap) key :order order))\n (force-up treap)\n treap)\n (t\n (treap-merge (%treap-left treap) (%treap-right 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 two arguments: KEY and VALUE.\"\n (labels ((recur (treap)\n (when treap\n (force-down treap)\n (recur (%treap-left treap))\n (funcall function (%treap-key treap) (%treap-value treap))\n (recur (%treap-right treap))\n (force-up 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 value)\n (if init\n (setf init nil)\n (write-char #\\ stream))\n (format stream \"<~A . ~A>\" key value))\n object))))\n\n(defmacro do-treap ((key-var value-var treap &optional result) &body body)\n \"Successively binds the key and value of INODE[0], ..., INODE[SIZE-1] to\nKEY-VAR and VALUE-VAR and executes BODY.\"\n `(block nil\n (treap-map (lambda (,key-var ,value-var) ,@body) ,treap)\n ,result))\n\n;; Reference: https://cp-algorithms.com/data_structures/treap.html\n;; TODO: take a sorted list as the argument\n(declaim (inline make-treap))\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 (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 +op-identity+)))\n (setf (%treap-left node) (build l mid))\n (setf (%treap-right node) (build (+ mid 1) r))\n (heapify node)\n node))))\n (build 0 (length sorted-vector))))\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 ~S.\"\n (invalid-treap-index-error-index condition)\n (invalid-treap-index-error-treap condition)))))\n\n;; FIXME: might be problematic when two priorities collide.\n(declaim (inline treap-query))\n(defun treap-query (treap &key left right (order #'<))\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 treap right :order order)\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 treap left :order order)\n (prog1 (treap-accumulator treap-l-n)\n (treap-merge treap-0-l treap-l-n)))\n (progn\n (assert (not (funcall order right left)))\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split treap left :order order)\n (multiple-value-bind (treap-l-r treap-r-n)\n (treap-split treap-l-n right :order order)\n (prog1 (treap-accumulator treap-l-r)\n (treap-merge treap-0-l (treap-merge treap-l-r treap-r-n)))))))))\n\n(declaim (inline treap-update))\n(defun treap-update (treap x left right &key (order #'<))\n \"Updates TREAP[KEY] := (OP TREAP[KEY] X) for all KEY in [l, r)\"\n (assert (not (funcall order right left)))\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split treap left :order order)\n (multiple-value-bind (treap-l-r treap-r-n)\n (treap-split treap-l-n right :order order)\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\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 poor-solve (n ls rs &optional lrs seq)\n;; (let ((res 0))\n;; (dotimes (bits (- (expt 2 n) 1))\n;; (unless (zerop bits)\n;; (let ((cumuls1 (make-array 101 :element-type 'int32))\n;; (cumuls2 (make-array 101 :element-type 'int32)))\n;; (dotimes (i n)\n;; (if (logbitp i bits)\n;; (progn (incf (aref cumuls1 (aref ls i)))\n;; (decf (aref cumuls1 (aref rs i))))\n;; (progn (incf (aref cumuls2 (aref ls i)))\n;; (decf (aref cumuls2 (aref rs i))))))\n;; (dotimes (i 100)\n;; (incf (aref cumuls1 (+ i 1)) (aref cumuls1 i))\n;; (incf (aref cumuls2 (+ i 1)) (aref cumuls2 i)))\n;; (let* ((required1 (logcount bits))\n;; (required2 (- n required1)))\n;; (when (and (= required1 (reduce #'max cumuls1))\n;; (= required2 (reduce #'max cumuls2)))\n;; (dbg required1 required2)\n;; (setq res (max res (+ (count required1 cumuls1)\n;; (count required2 cumuls2)))))))))\n;; (println res)\n;; res))\n\n(defun solve (n ls rs lrs seq)\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 0) (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 0) (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 #>i\n #>treap1\n #>treap2\n (dbg max1l max1r max2l max2r)\n (unless (zerop i)\n (setq res (max res new-score)))))\n (dbg l r)\n (treap-update treap1 1 l r)\n (treap-update treap2 -1 l r)))\n res))\n\n;; 4 #(55 62 52 39) #(79 96 82 93)\n;; 4 #(2 0 3 0) #(9 9 7 8)\n\n;; (defun random-solver ()\n;; (let* ((n 4)\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 (random 10))\n;; (r (random 9)))\n;; (when (> l r)\n;; (rotatef l r))\n;; (incf r)\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 #'< :key #'cdr))\n;; (setq seq (delete-adjacent-duplicates seq))\n;; (unless (= (poor-solve n ls rs lrs seq)\n;; (let ((tmp (solve n ls rs lrs seq)))\n;; (dotimes (i n)\n;; #>ls #>rs\n;; (let ((l (aref ls i))\n;; (r (aref rs i)))\n;; (setf (aref ls i) (- 20 r)\n;; (aref rs i) (- 20 l)))\n;; (setf (aref lrs i) (cons (aref ls i) (aref rs i))))\n;; (dotimes (i (length seq))\n;; (setf (aref seq i) (- 20 (aref seq i))))\n;; (setq seq (sort seq #'<)\n;; lrs (sort lrs #'< :key #'cdr))\n;; (dbg ls rs lrs seq)\n;; (let ((tmp2 (solve n ls rs lrs seq)))\n;; (max tmp tmp2))))\n;; (error \"~A ~A ~A\" n ls rs))\n;; )\n;; )\n(defun main ()\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 #'< :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": 1572851755, "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/s947754527.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s947754527", "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(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(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 priority 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 (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 (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-find (treap key &key (order #'<))\n \"Finds the key that satisfies (and (not (funcall order key (%treap-key\nsub-treap))) (not (funcall order (%treap-key sub-treap) key))) and returns KEY\nand the assigned value. Returns NIL if KEY is not contained.\"\n (declare (function order)\n ((or null treap) treap))\n (cond ((null treap) (values nil nil))\n ((funcall order key (%treap-key treap))\n (treap-find (%treap-left treap) key :order order))\n ((funcall order (%treap-key treap) key)\n (treap-find (%treap-right treap) key :order order))\n (t (values key (%treap-value treap)))))\n\n(defun treap-bisect-right-1 (treap key &key (order #'<))\n \"Returns the largest key equal to or smaller than KEY and the assigned\nvalue. Returns NIL if KEY is smaller 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 (force-down treap)\n (if (funcall order key (%treap-key treap))\n (recur (%treap-left treap))\n (or (recur (%treap-right 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(defun treap-bisect-left (treap key &key (order #'<))\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 ((or null treap) treap)\n (function order))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (force-down treap)\n (if (funcall order (%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 &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 (if (null treap)\n (values nil nil)\n (progn\n (force-down treap)\n (if (funcall order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split (%treap-right treap) key :order order)\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 :order order)\n (setf (%treap-left treap) right)\n (force-up treap)\n (values left treap))))))\n\n(declaim (inline treap-insert))\n(defun treap-insert (treap key value &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 (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 (%treap-key node) :order order))\n (force-up node)\n node)\n (progn\n (if (funcall 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-up treap)\n treap))))\n (recur (%make-treap key (random most-positive-fixnum) value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (treap key value &key (order #'<) 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 already contains KEY, TREAP-ENSURE-KEY\nupdates the value by the function instead of overwriting it with VALUE.\"\n (declare (function order)\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 ((funcall order key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n (force-up treap)\n t))\n ((funcall order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n (force-up treap)\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n (force-up treap)\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert treap key value :order order))))\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 (declare (optimize (speed 3))\n ((or null treap) 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 (> (%treap-priority left) (%treap-priority right))\n (progn\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n (force-up left)\n left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n (force-up right)\n right)))))\n\n(defun treap-delete (treap key &key (order #'<))\n \"Destructively deletes the KEY in TREAP and returns the resultant\ntreap. Returns the unmodified TREAP If KEY doesn't exist. You cannot rely on the\nside effect. Use the returned value.\n\n (Note that this function deletes at most one node even if duplicated keys\nexist.)\"\n (declare ((or null treap) treap)\n (function order))\n (when treap\n (force-down treap)\n (cond ((funcall order key (%treap-key treap))\n (setf (%treap-left treap)\n (treap-delete (%treap-left treap) key :order order))\n (force-up treap)\n treap)\n ((funcall order (%treap-key treap) key)\n (setf (%treap-right treap)\n (treap-delete (%treap-right treap) key :order order))\n (force-up treap)\n treap)\n (t\n (treap-merge (%treap-left treap) (%treap-right 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 two arguments: KEY and VALUE.\"\n (labels ((recur (treap)\n (when treap\n (force-down treap)\n (recur (%treap-left treap))\n (funcall function (%treap-key treap) (%treap-value treap))\n (recur (%treap-right treap))\n (force-up 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 value)\n (if init\n (setf init nil)\n (write-char #\\ stream))\n (format stream \"<~A . ~A>\" key value))\n object))))\n\n(defmacro do-treap ((key-var value-var treap &optional result) &body body)\n \"Successively binds the key and value of INODE[0], ..., INODE[SIZE-1] to\nKEY-VAR and VALUE-VAR and executes BODY.\"\n `(block nil\n (treap-map (lambda (,key-var ,value-var) ,@body) ,treap)\n ,result))\n\n;; Reference: https://cp-algorithms.com/data_structures/treap.html\n;; TODO: take a sorted list as the argument\n(declaim (inline make-treap))\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 (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 +op-identity+)))\n (setf (%treap-left node) (build l mid))\n (setf (%treap-right node) (build (+ mid 1) r))\n (heapify node)\n node))))\n (build 0 (length sorted-vector))))\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 ~S.\"\n (invalid-treap-index-error-index condition)\n (invalid-treap-index-error-treap condition)))))\n\n;; FIXME: might be problematic when two priorities collide.\n(declaim (inline treap-query))\n(defun treap-query (treap &key left right (order #'<))\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 treap right :order order)\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 treap left :order order)\n (prog1 (treap-accumulator treap-l-n)\n (treap-merge treap-0-l treap-l-n)))\n (progn\n (assert (not (funcall order right left)))\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split treap left :order order)\n (multiple-value-bind (treap-l-r treap-r-n)\n (treap-split treap-l-n right :order order)\n (prog1 (treap-accumulator treap-l-r)\n (treap-merge treap-0-l (treap-merge treap-l-r treap-r-n)))))))))\n\n(declaim (inline treap-update))\n(defun treap-update (treap x left right &key (order #'<))\n \"Updates TREAP[KEY] := (OP TREAP[KEY] X) for all KEY in [l, r)\"\n (assert (not (funcall order right left)))\n (multiple-value-bind (treap-0-l treap-l-n)\n (treap-split treap left :order order)\n (multiple-value-bind (treap-l-r treap-r-n)\n (treap-split treap-l-n right :order order)\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\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 poor-solve (n ls rs &optional lrs seq)\n;; (let ((res 0))\n;; (dotimes (bits (- (expt 2 n) 1))\n;; (unless (zerop bits)\n;; (let ((cumuls1 (make-array 101 :element-type 'int32))\n;; (cumuls2 (make-array 101 :element-type 'int32)))\n;; (dotimes (i n)\n;; (if (logbitp i bits)\n;; (progn (incf (aref cumuls1 (aref ls i)))\n;; (decf (aref cumuls1 (aref rs i))))\n;; (progn (incf (aref cumuls2 (aref ls i)))\n;; (decf (aref cumuls2 (aref rs i))))))\n;; (dotimes (i 100)\n;; (incf (aref cumuls1 (+ i 1)) (aref cumuls1 i))\n;; (incf (aref cumuls2 (+ i 1)) (aref cumuls2 i)))\n;; (let* ((required1 (logcount bits))\n;; (required2 (- n required1)))\n;; (when (and (= required1 (reduce #'max cumuls1))\n;; (= required2 (reduce #'max cumuls2)))\n;; (dbg required1 required2)\n;; (setq res (max res (+ (count required1 cumuls1)\n;; (count required2 cumuls2)))))))))\n;; (println res)\n;; res))\n\n(defun solve (n ls rs lrs seq)\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 0) (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 0) (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 #>i\n #>treap1\n #>treap2\n (dbg max1l max1r max2l max2r)\n (unless (zerop i)\n (setq res (max res new-score)))))\n (dbg l r)\n (treap-update treap1 1 l r)\n (treap-update treap2 -1 l r)))\n res))\n\n;; 4 #(55 62 52 39) #(79 96 82 93)\n;; 4 #(2 0 3 0) #(9 9 7 8)\n\n;; (defun random-solver ()\n;; (let* ((n 4)\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 (random 10))\n;; (r (random 9)))\n;; (when (> l r)\n;; (rotatef l r))\n;; (incf r)\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 #'< :key #'cdr))\n;; (setq seq (delete-adjacent-duplicates seq))\n;; (unless (= (poor-solve n ls rs lrs seq)\n;; (let ((tmp (solve n ls rs lrs seq)))\n;; (dotimes (i n)\n;; #>ls #>rs\n;; (let ((l (aref ls i))\n;; (r (aref rs i)))\n;; (setf (aref ls i) (- 20 r)\n;; (aref rs i) (- 20 l)))\n;; (setf (aref lrs i) (cons (aref ls i) (aref rs i))))\n;; (dotimes (i (length seq))\n;; (setf (aref seq i) (- 20 (aref seq i))))\n;; (setq seq (sort seq #'<)\n;; lrs (sort lrs #'< :key #'cdr))\n;; (dbg ls rs lrs seq)\n;; (let ((tmp2 (solve n ls rs lrs seq)))\n;; (max tmp tmp2))))\n;; (error \"~A ~A ~A\" n ls rs))\n;; )\n;; )\n(defun main ()\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 #'< :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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 28698, "cpu_time_ms": 2105, "memory_kb": 83684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s567336289", "group_id": "codeNet:p02881", "input_text": "(defun solve (n)\n (loop for i from (isqrt n) downto 1\n do (multiple-value-bind (quotient remainder)\n (truncate n i)\n (when (zerop remainder)\n (return (- (+ quotient i) 2))))))\n\n#-swank\n(let* ((n (read)))\n (format t \"~A~%\" (solve n)))\n", "language": "Lisp", "metadata": {"date": 1579317118, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02881.html", "problem_id": "p02881", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02881/input.txt", "sample_output_relpath": "derived/input_output/data/p02881/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02881/Lisp/s567336289.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s567336289", "user_id": "u202886318"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun solve (n)\n (loop for i from (isqrt n) downto 1\n do (multiple-value-bind (quotient remainder)\n (truncate n i)\n (when (zerop remainder)\n (return (- (+ quotient i) 2))))))\n\n#-swank\n(let* ((n (read)))\n (format t \"~A~%\" (solve n)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi is standing on a multiplication table with infinitely many rows and columns.\n\nThe square (i,j) contains the integer i \\times j. Initially, Takahashi is standing at (1,1).\n\nIn one move, he can move from (i,j) to either (i+1,j) or (i,j+1).\n\nGiven an integer N, find the minimum number of moves needed to reach a square that contains N.\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 minimum number of moves needed to reach a square that contains the integer N.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n5\n\n(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.\n\nSample Input 2\n\n50\n\nSample Output 2\n\n13\n\n(5, 10) can be reached in 13 moves.\n\nSample Input 3\n\n10000000019\n\nSample Output 3\n\n10000000018\n\nBoth input and output may be enormous.", "sample_input": "10\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02881", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi is standing on a multiplication table with infinitely many rows and columns.\n\nThe square (i,j) contains the integer i \\times j. Initially, Takahashi is standing at (1,1).\n\nIn one move, he can move from (i,j) to either (i+1,j) or (i,j+1).\n\nGiven an integer N, find the minimum number of moves needed to reach a square that contains N.\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 minimum number of moves needed to reach a square that contains the integer N.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n5\n\n(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.\n\nSample Input 2\n\n50\n\nSample Output 2\n\n13\n\n(5, 10) can be reached in 13 moves.\n\nSample Input 3\n\n10000000019\n\nSample Output 3\n\n10000000018\n\nBoth input and output may be enormous.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 146, "memory_kb": 14568}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s725316544", "group_id": "codeNet:p02881", "input_text": "(defun search-value (target &optional (i 1) (result-list (list nil)))\n (if (> (* i i) target)\n (car (sort (cdr (reverse result-list)) #'<))\n (progn\n (when (= (mod target i) 0)\n (let ((j (/ target i)))\n (push (- (+ i j) 2) result-list)))\n (search-value target (1+ i) result-list))))\n\n(princ (search-value (read)))\n", "language": "Lisp", "metadata": {"date": 1572888827, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02881.html", "problem_id": "p02881", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02881/input.txt", "sample_output_relpath": "derived/input_output/data/p02881/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02881/Lisp/s725316544.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s725316544", "user_id": "u631655863"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun search-value (target &optional (i 1) (result-list (list nil)))\n (if (> (* i i) target)\n (car (sort (cdr (reverse result-list)) #'<))\n (progn\n (when (= (mod target i) 0)\n (let ((j (/ target i)))\n (push (- (+ i j) 2) result-list)))\n (search-value target (1+ i) result-list))))\n\n(princ (search-value (read)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi is standing on a multiplication table with infinitely many rows and columns.\n\nThe square (i,j) contains the integer i \\times j. Initially, Takahashi is standing at (1,1).\n\nIn one move, he can move from (i,j) to either (i+1,j) or (i,j+1).\n\nGiven an integer N, find the minimum number of moves needed to reach a square that contains N.\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 minimum number of moves needed to reach a square that contains the integer N.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n5\n\n(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.\n\nSample Input 2\n\n50\n\nSample Output 2\n\n13\n\n(5, 10) can be reached in 13 moves.\n\nSample Input 3\n\n10000000019\n\nSample Output 3\n\n10000000018\n\nBoth input and output may be enormous.", "sample_input": "10\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02881", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi is standing on a multiplication table with infinitely many rows and columns.\n\nThe square (i,j) contains the integer i \\times j. Initially, Takahashi is standing at (1,1).\n\nIn one move, he can move from (i,j) to either (i+1,j) or (i,j+1).\n\nGiven an integer N, find the minimum number of moves needed to reach a square that contains N.\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 minimum number of moves needed to reach a square that contains the integer N.\n\nSample Input 1\n\n10\n\nSample Output 1\n\n5\n\n(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.\n\nSample Input 2\n\n50\n\nSample Output 2\n\n13\n\n(5, 10) can be reached in 13 moves.\n\nSample Input 3\n\n10000000019\n\nSample Output 3\n\n10000000018\n\nBoth input and output may be enormous.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 121, "memory_kb": 9316}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s856729420", "group_id": "codeNet:p02882", "input_text": "(let ((a (read))\n (b (read))\n (x (read)))\n (cond ((<= (* 2 x) (* a a b))\n (format t \"~F~%\" (/ (* 180 (atan (/ (* a b b) (* 2 x)))) pi)))\n (t\n (format t \"~F~%\" (- 90 (/ (* 180 (atan (/ (* a a a) (* 2.0d0 (- (* a a b) x))))) pi))))))\n", "language": "Lisp", "metadata": {"date": 1595471094, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02882.html", "problem_id": "p02882", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02882/input.txt", "sample_output_relpath": "derived/input_output/data/p02882/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02882/Lisp/s856729420.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s856729420", "user_id": "u608227593"}, "prompt_components": {"gold_output": "45.0000000000\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (x (read)))\n (cond ((<= (* 2 x) (* a a b))\n (format t \"~F~%\" (/ (* 180 (atan (/ (* a b b) (* 2 x)))) pi)))\n (t\n (format t \"~F~%\" (- 90 (/ (* 180 (atan (/ (* a a a) (* 2.0d0 (- (* a a b) x))))) pi))))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a~\\mathrm{cm} and whose height is b~\\mathrm{cm}. (The thickness of the bottle can be ignored.)\n\nWe will pour x~\\mathrm{cm}^3 of water into the bottle, and gradually tilt the bottle around one of the sides of the base.\n\nWhen will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq a \\leq 100\n\n1 \\leq b \\leq 100\n\n1 \\leq x \\leq a^2b\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b x\n\nOutput\n\nPrint the maximum angle in which we can tilt the bottle without spilling any water, in degrees.\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\n2 2 4\n\nSample Output 1\n\n45.0000000000\n\nThis bottle has a cubic shape, and it is half-full. The water gets spilled when we tilt the bottle more than 45 degrees.\n\nSample Input 2\n\n12 21 10\n\nSample Output 2\n\n89.7834636934\n\nThis bottle is almost empty. When the water gets spilled, the bottle is nearly horizontal.\n\nSample Input 3\n\n3 1 8\n\nSample Output 3\n\n4.2363947991\n\nThis bottle is almost full. When the water gets spilled, the bottle is still nearly vertical.", "sample_input": "2 2 4\n"}, "reference_outputs": ["45.0000000000\n"], "source_document_id": "p02882", "source_text": "Score : 400 points\n\nProblem Statement\n\nTakahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a~\\mathrm{cm} and whose height is b~\\mathrm{cm}. (The thickness of the bottle can be ignored.)\n\nWe will pour x~\\mathrm{cm}^3 of water into the bottle, and gradually tilt the bottle around one of the sides of the base.\n\nWhen will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq a \\leq 100\n\n1 \\leq b \\leq 100\n\n1 \\leq x \\leq a^2b\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b x\n\nOutput\n\nPrint the maximum angle in which we can tilt the bottle without spilling any water, in degrees.\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\n2 2 4\n\nSample Output 1\n\n45.0000000000\n\nThis bottle has a cubic shape, and it is half-full. The water gets spilled when we tilt the bottle more than 45 degrees.\n\nSample Input 2\n\n12 21 10\n\nSample Output 2\n\n89.7834636934\n\nThis bottle is almost empty. When the water gets spilled, the bottle is nearly horizontal.\n\nSample Input 3\n\n3 1 8\n\nSample Output 3\n\n4.2363947991\n\nThis bottle is almost full. When the water gets spilled, the bottle is still nearly vertical.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 266, "cpu_time_ms": 34, "memory_kb": 26912}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s338867466", "group_id": "codeNet:p02885", "input_text": "(defun curtain (w c)\n (if (< (- w (* 2 c)) 0)\n 0\n (- w (* 2 c))\n )\n )\n(princ (curtain (read) (read)))", "language": "Lisp", "metadata": {"date": 1581601762, "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/s338867466.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s338867466", "user_id": "u606976120"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun curtain (w c)\n (if (< (- w (* 2 c)) 0)\n 0\n (- w (* 2 c))\n )\n )\n(princ (curtain (read) (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 97, "memory_kb": 11236}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s745270521", "group_id": "codeNet:p02885", "input_text": "(let* ((n (- (read) (* 2 (read)))))\n (if (minusp n)\n (princ 0)\n (princ n)))", "language": "Lisp", "metadata": {"date": 1571542910, "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/s745270521.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s745270521", "user_id": "u610490393"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let* ((n (- (read) (* 2 (read)))))\n (if (minusp n)\n (princ 0)\n (princ 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 99, "memory_kb": 11108}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s125447576", "group_id": "codeNet:p02885", "input_text": "(defun katen ()\n (let ((a (read))\n (b (read))\n (rst 0))\n (setf rst (- a (* b 2)))\n (format t \"~a\" (if (> rst 0) rst 0))))\n\n(katen)", "language": "Lisp", "metadata": {"date": 1571533671, "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/s125447576.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s125447576", "user_id": "u845695466"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun katen ()\n (let ((a (read))\n (b (read))\n (rst 0))\n (setf rst (- a (* b 2)))\n (format t \"~a\" (if (> rst 0) rst 0))))\n\n(katen)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 395, "memory_kb": 12384}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s426194672", "group_id": "codeNet:p02886", "input_text": "(let* ((n (read))\n (l (loop :repeat n :collect (read))))\n (princ (loop :as i\n :in l\n :as m\n :below (- n 1)\n :sum (loop :as j\n :in (nthcdr (+ m 1) l)\n :sum (* i j)))))", "language": "Lisp", "metadata": {"date": 1586397281, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02886.html", "problem_id": "p02886", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02886/input.txt", "sample_output_relpath": "derived/input_output/data/p02886/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02886/Lisp/s426194672.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s426194672", "user_id": "u606976120"}, "prompt_components": {"gold_output": "11\n", "input_to_evaluate": "(let* ((n (read))\n (l (loop :repeat n :collect (read))))\n (princ (loop :as i\n :in l\n :as m\n :below (- n 1)\n :sum (loop :as j\n :in (nthcdr (+ m 1) l)\n :sum (* i j)))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIt's now the season of TAKOYAKI FESTIVAL!\n\nThis year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i.\n\nAs is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \\times y health points.\n\nThere are \\frac{N \\times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \\frac{N \\times (N - 1)}{2} values.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 50\n\n0 \\leq d_i \\leq 100\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 sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served.\n\nSample Input 1\n\n3\n3 1 2\n\nSample Output 1\n\n11\n\nThere are three possible choices:\n\nEat the first and second takoyaki. You will restore 3 health points.\n\nEat the second and third takoyaki. You will restore 2 health points.\n\nEat the first and third takoyaki. You will restore 6 health points.\n\nThe sum of these values is 11.\n\nSample Input 2\n\n7\n5 0 7 8 3 3 2\n\nSample Output 2\n\n312", "sample_input": "3\n3 1 2\n"}, "reference_outputs": ["11\n"], "source_document_id": "p02886", "source_text": "Score : 200 points\n\nProblem Statement\n\nIt's now the season of TAKOYAKI FESTIVAL!\n\nThis year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i.\n\nAs is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \\times y health points.\n\nThere are \\frac{N \\times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \\frac{N \\times (N - 1)}{2} values.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 50\n\n0 \\leq d_i \\leq 100\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 sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served.\n\nSample Input 1\n\n3\n3 1 2\n\nSample Output 1\n\n11\n\nThere are three possible choices:\n\nEat the first and second takoyaki. You will restore 3 health points.\n\nEat the second and third takoyaki. You will restore 2 health points.\n\nEat the first and third takoyaki. You will restore 6 health points.\n\nThe sum of these values is 11.\n\nSample Input 2\n\n7\n5 0 7 8 3 3 2\n\nSample Output 2\n\n312", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 158, "memory_kb": 13796}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s566793882", "group_id": "codeNet:p02887", "input_text": "(defmacro read-to-list ()\n `(read-from-string\n (concatenate 'string \"(\" (read-line) \")\")))\n\n(defun solve (s &optional (res 0) (prev #\\0))\n (if (null s)\n res\n (if (char-equal (first s)\n prev)\n (solve (rest s) res (first s))\n (solve (rest s) (1+ res) (first s)))))\n\n\n(defun main ()\n (let ((n (read))\n (s (concatenate 'list (read-line))))\n (format t \"~a~%\" (solve s))))\n\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1598710800, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02887.html", "problem_id": "p02887", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02887/input.txt", "sample_output_relpath": "derived/input_output/data/p02887/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02887/Lisp/s566793882.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s566793882", "user_id": "u425762225"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defmacro read-to-list ()\n `(read-from-string\n (concatenate 'string \"(\" (read-line) \")\")))\n\n(defun solve (s &optional (res 0) (prev #\\0))\n (if (null s)\n res\n (if (char-equal (first s)\n prev)\n (solve (rest s) res (first s))\n (solve (rest s) (1+ res) (first s)))))\n\n\n(defun main ()\n (let ((n (read))\n (s (concatenate 'list (read-line))))\n (format t \"~a~%\" (solve s))))\n\n\n(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.\n\nAdjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.\n\nUltimately, how many slimes will be there?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n|S| = N\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the final number of slimes.\n\nSample Input 1\n\n10\naabbbbaaca\n\nSample Output 1\n\n5\n\nUltimately, these slimes will fuse into abaca.\n\nSample Input 2\n\n5\naaaaa\n\nSample Output 2\n\n1\n\nAll the slimes will fuse into one.\n\nSample Input 3\n\n20\nxxzaffeeeeddfkkkkllq\n\nSample Output 3\n\n10", "sample_input": "10\naabbbbaaca\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02887", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.\n\nAdjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.\n\nUltimately, how many slimes will be there?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n|S| = N\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the final number of slimes.\n\nSample Input 1\n\n10\naabbbbaaca\n\nSample Output 1\n\n5\n\nUltimately, these slimes will fuse into abaca.\n\nSample Input 2\n\n5\naaaaa\n\nSample Output 2\n\n1\n\nAll the slimes will fuse into one.\n\nSample Input 3\n\n20\nxxzaffeeeeddfkkkkllq\n\nSample Output 3\n\n10", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 26, "memory_kb": 27296}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s763738436", "group_id": "codeNet:p02887", "input_text": "(defun solve (n s)\n (let ((i 0)\n (count 0))\n (loop\n (when (<= n i)\n (return count))\n (let ((char (aref s i)))\n (incf count)\n (loop for j from (1+ i) below n\n while (char= char (aref s j))\n finally (setf i j))))))\n\n#-swank\n(let* ((n (read))\n (s (read-line)))\n (format t \"~A~%\" (solve n s)))\n", "language": "Lisp", "metadata": {"date": 1579450892, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02887.html", "problem_id": "p02887", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02887/input.txt", "sample_output_relpath": "derived/input_output/data/p02887/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02887/Lisp/s763738436.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s763738436", "user_id": "u202886318"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun solve (n s)\n (let ((i 0)\n (count 0))\n (loop\n (when (<= n i)\n (return count))\n (let ((char (aref s i)))\n (incf count)\n (loop for j from (1+ i) below n\n while (char= char (aref s j))\n finally (setf i j))))))\n\n#-swank\n(let* ((n (read))\n (s (read-line)))\n (format t \"~A~%\" (solve n s)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.\n\nAdjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.\n\nUltimately, how many slimes will be there?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n|S| = N\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the final number of slimes.\n\nSample Input 1\n\n10\naabbbbaaca\n\nSample Output 1\n\n5\n\nUltimately, these slimes will fuse into abaca.\n\nSample Input 2\n\n5\naaaaa\n\nSample Output 2\n\n1\n\nAll the slimes will fuse into one.\n\nSample Input 3\n\n20\nxxzaffeeeeddfkkkkllq\n\nSample Output 3\n\n10", "sample_input": "10\naabbbbaaca\n"}, "reference_outputs": ["5\n"], "source_document_id": "p02887", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.\n\nAdjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.\n\nUltimately, how many slimes will be there?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n|S| = N\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the final number of slimes.\n\nSample Input 1\n\n10\naabbbbaaca\n\nSample Output 1\n\n5\n\nUltimately, these slimes will fuse into abaca.\n\nSample Input 2\n\n5\naaaaa\n\nSample Output 2\n\n1\n\nAll the slimes will fuse into one.\n\nSample Input 3\n\n20\nxxzaffeeeeddfkkkkllq\n\nSample Output 3\n\n10", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 30, "memory_kb": 6756}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s690982339", "group_id": "codeNet:p02893", "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 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;;;\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 (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 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (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(declaim (inline bit-vector-to-integer))\n(defun bit-vector-to-integer (bit-vector modulus start end)\n (let ((result 0))\n (declare (uint31 result))\n (loop for i from start below end\n do (setq result\n (mod (+ (* 2 result) (aref bit-vector i)) modulus)))\n result))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (xs (make-array n :element-type 'bit))\n (dp (make-array (+ 1 (* 2 n)) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref xs i) (if (char= #\\0 (read-schar)) 0 1)))\n (loop for d from 2 to (* 2 n)\n for value of-type uint31 = 0\n when (and (zerop (mod (* 2 n) d))\n (oddp (floor (* 2 n) d)))\n do (let* ((d/2 (floor d 2))\n (max-prefix-int (bit-vector-to-integer xs +mod+ 0 d/2))\n (seq (concatenate 'simple-bit-vector\n (subseq xs 0 d/2)\n (bit-not (subseq xs 0 d/2) t))))\n (Declare (uint31 d/2 max-prefix-int))\n (incfmod value max-prefix-int)\n (let ((max-seq (make-array n :element-type 'bit)))\n (loop for i below n\n do (setf (aref max-seq i)\n (aref seq (mod i d))))\n (loop for i below n\n for i%d = 0 then (if (= (+ i%d 1) d) 0 (+ i%d 1))\n do (cond ((> (aref max-seq i%d) (aref xs i))\n (return))\n ((< (aref max-seq i%d) (aref xs i))\n (incfmod value 1)\n (return)))\n finally (incfmod value 1))))\n (setf (aref dp d) value))\n (inverse-divisor-transform! dp #'mod-)\n (loop with res of-type uint31 = 0\n for d from 2 to (* 2 n)\n when (and (zerop (mod (* 2 n) d))\n (oddp (floor (* 2 n) d)))\n do (incfmod res (mod* d (aref dp d)))\n finally (println res))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1571547850, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02893.html", "problem_id": "p02893", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02893/input.txt", "sample_output_relpath": "derived/input_output/data/p02893/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02893/Lisp/s690982339.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s690982339", "user_id": "u352600849"}, "prompt_components": {"gold_output": "40\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 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;;;\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 (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 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (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(declaim (inline bit-vector-to-integer))\n(defun bit-vector-to-integer (bit-vector modulus start end)\n (let ((result 0))\n (declare (uint31 result))\n (loop for i from start below end\n do (setq result\n (mod (+ (* 2 result) (aref bit-vector i)) modulus)))\n result))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (xs (make-array n :element-type 'bit))\n (dp (make-array (+ 1 (* 2 n)) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref xs i) (if (char= #\\0 (read-schar)) 0 1)))\n (loop for d from 2 to (* 2 n)\n for value of-type uint31 = 0\n when (and (zerop (mod (* 2 n) d))\n (oddp (floor (* 2 n) d)))\n do (let* ((d/2 (floor d 2))\n (max-prefix-int (bit-vector-to-integer xs +mod+ 0 d/2))\n (seq (concatenate 'simple-bit-vector\n (subseq xs 0 d/2)\n (bit-not (subseq xs 0 d/2) t))))\n (Declare (uint31 d/2 max-prefix-int))\n (incfmod value max-prefix-int)\n (let ((max-seq (make-array n :element-type 'bit)))\n (loop for i below n\n do (setf (aref max-seq i)\n (aref seq (mod i d))))\n (loop for i below n\n for i%d = 0 then (if (= (+ i%d 1) d) 0 (+ i%d 1))\n do (cond ((> (aref max-seq i%d) (aref xs i))\n (return))\n ((< (aref max-seq i%d) (aref xs i))\n (incfmod value 1)\n (return)))\n finally (incfmod value 1))))\n (setf (aref dp d) value))\n (inverse-divisor-transform! dp #'mod-)\n (loop with res of-type uint31 = 0\n for d from 2 to (* 2 n)\n when (and (zerop (mod (* 2 n) d))\n (oddp (floor (* 2 n) d)))\n do (incfmod res (mod* d (aref dp d)))\n finally (println res))))\n\n#-swank (main)\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nGiven are integers N and X. For each integer k between 0 and X (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo 998244353.\n\nLet us repeat the following operation on the integer k. Operation: if the integer is currently odd, subtract 1 from it and divide it by 2; otherwise, divide it by 2 and add 2^{N-1} to it. How many operations need to be performed until k returns to its original value? (The answer is considered to be 0 if k never returns to its original value.)\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n0 \\leq X < 2^N\n\nX is given in binary and has exactly N digits. (In case X has less than N digits, it is given with leading zeroes.)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX\n\nOutput\n\nPrint the sum of the answers to the questions for the integers between 0 and X (inclusive), modulo 998244353.\n\nSample Input 1\n\n3\n111\n\nSample Output 1\n\n40\n\nFor example, for k=3, the operation changes k as follows: 1,0,4,6,7,3. Therefore the answer for k=3 is 6.\n\nSample Input 2\n\n6\n110101\n\nSample Output 2\n\n616\n\nSample Input 3\n\n30\n001110011011011101010111011100\n\nSample Output 3\n\n549320998", "sample_input": "3\n111\n"}, "reference_outputs": ["40\n"], "source_document_id": "p02893", "source_text": "Score : 800 points\n\nProblem Statement\n\nGiven are integers N and X. For each integer k between 0 and X (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo 998244353.\n\nLet us repeat the following operation on the integer k. Operation: if the integer is currently odd, subtract 1 from it and divide it by 2; otherwise, divide it by 2 and add 2^{N-1} to it. How many operations need to be performed until k returns to its original value? (The answer is considered to be 0 if k never returns to its original value.)\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n0 \\leq X < 2^N\n\nX is given in binary and has exactly N digits. (In case X has less than N digits, it is given with leading zeroes.)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nX\n\nOutput\n\nPrint the sum of the answers to the questions for the integers between 0 and X (inclusive), modulo 998244353.\n\nSample Input 1\n\n3\n111\n\nSample Output 1\n\n40\n\nFor example, for k=3, the operation changes k as follows: 1,0,4,6,7,3. Therefore the answer for k=3 is 6.\n\nSample Input 2\n\n6\n110101\n\nSample Output 2\n\n616\n\nSample Input 3\n\n30\n001110011011011101010111011100\n\nSample Output 3\n\n549320998", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5771, "cpu_time_ms": 635, "memory_kb": 75112}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s033834799", "group_id": "codeNet:p02897", "input_text": "(defun odds-of-oddness ()\n (let ((n (read))\n (ans 0))\n (dotimes (i n)\n (if (= (rem (1+ i) 2) 1)\n (incf ans))) \n (float (/ ans n))))\n\n(format t \"~D~%\" (odds-of-oddness))\n", "language": "Lisp", "metadata": {"date": 1582933151, "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/s033834799.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s033834799", "user_id": "u091381267"}, "prompt_components": {"gold_output": "0.5000000000\n", "input_to_evaluate": "(defun odds-of-oddness ()\n (let ((n (read))\n (ans 0))\n (dotimes (i n)\n (if (= (rem (1+ i) 2) 1)\n (incf ans))) \n (float (/ ans n))))\n\n(format t \"~D~%\" (odds-of-oddness))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 135, "memory_kb": 13664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s654588567", "group_id": "codeNet:p02897", "input_text": "(defun main ()\n (let* ((N (read))\n (diff (if (= N 1)\n 1\n (fceiling N 2))))\n (princ (float (/ diff N)))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1569810994, "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/s654588567.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s654588567", "user_id": "u631655863"}, "prompt_components": {"gold_output": "0.5000000000\n", "input_to_evaluate": "(defun main ()\n (let* ((N (read))\n (diff (if (= N 1)\n 1\n (fceiling N 2))))\n (princ (float (/ diff N)))))\n\n(main)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 185, "memory_kb": 19428}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s887275884", "group_id": "codeNet:p02897", "input_text": "(setq *n* (read))\n\n(defun ans (n)\n (cond\n ((evenp n) (/ (/ n 2) n))\n (t (/ (ceiling (/ n 2)) n))\n )\n )\n\n(print (float (ans *n*)))\n", "language": "Lisp", "metadata": {"date": 1569719210, "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/s887275884.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s887275884", "user_id": "u358554431"}, "prompt_components": {"gold_output": "0.5000000000\n", "input_to_evaluate": "(setq *n* (read))\n\n(defun ans (n)\n (cond\n ((evenp n) (/ (/ n 2) n))\n (t (/ (ceiling (/ n 2)) n))\n )\n )\n\n(print (float (ans *n*)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 138, "memory_kb": 14180}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s987196102", "group_id": "codeNet:p02898", "input_text": "(setq n (read) k (read))\n(setq ans 0)\n(dotimes (i n)\n\t(when (>= (read) k)\n\t\t(setq ans (1+ ans))))\n\n(write ans)\n", "language": "Lisp", "metadata": {"date": 1570667955, "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/s987196102.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s987196102", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(setq n (read) k (read))\n(setq ans 0)\n(dotimes (i n)\n\t(when (>= (read) k)\n\t\t(setq ans (1+ ans))))\n\n(write ans)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 176, "memory_kb": 57828}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s874282399", "group_id": "codeNet:p02898", "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 *k* (read))\n\n(defun ans (cnt)\n (cond\n ((<= *n* cnt) 0)\n ((>= (read) *k*) (1+ (ans (1+ cnt))))\n (t (ans (1+ cnt)))\n ))\n\n\n(format t \"~a~%\" (ans 0))\n", "language": "Lisp", "metadata": {"date": 1569722492, "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/s874282399.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s874282399", "user_id": "u358554431"}, "prompt_components": {"gold_output": "2\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 *k* (read))\n\n(defun ans (cnt)\n (cond\n ((<= *n* cnt) 0)\n ((>= (read) *k*) (1+ (ans (1+ cnt))))\n (t (ans (1+ cnt)))\n ))\n\n\n(format t \"~a~%\" (ans 0))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 438, "memory_kb": 63076}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s812544216", "group_id": "codeNet:p02898", "input_text": "(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 *k* (read))\n\n(setq *hi* (split \" \" (read-line)))\n\n(format t \"~a~%\" *hi*)", "language": "Lisp", "metadata": {"date": 1569721585, "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/s812544216.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s812544216", "user_id": "u358554431"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(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 *k* (read))\n\n(setq *hi* (split \" \" (read-line)))\n\n(format t \"~a~%\" *hi*)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 724, "cpu_time_ms": 2116, "memory_kb": 1012116}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s319758547", "group_id": "codeNet:p02899", "input_text": "(let* ((n (read))\n (lst (loop :repeat n :collect (read)))\n (ans nil))\n (loop :for k :from 1 :upto n :do(push (1+ (position k lst :test #'=)) ans))\n (setf ans (reverse ans))\n (defun princ-list (lst-a)\n (princ (car lst-a))\n (if (cdr lst-a) (progn (princ \" \") (princ-list (cdr lst-a)))))\n (princ-list ans))", "language": "Lisp", "metadata": {"date": 1569719386, "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/s319758547.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s319758547", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3 1 2\n", "input_to_evaluate": "(let* ((n (read))\n (lst (loop :repeat n :collect (read)))\n (ans nil))\n (loop :for k :from 1 :upto n :do(push (1+ (position k lst :test #'=)) ans))\n (setf ans (reverse ans))\n (defun princ-list (lst-a)\n (princ (car lst-a))\n (if (cdr lst-a) (progn (princ \" \") (princ-list (cdr lst-a)))))\n (princ-list ans))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 325, "cpu_time_ms": 2104, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s371348109", "group_id": "codeNet:p02900", "input_text": "(defun prime-factorization (n)\n (let ((ans '()))\n (labels ((divide (m i c)\n\t\t (unless (zerop (rem m i))\n\t\t (return-from divide (values m (cons i c))))\n\t\t (divide (/ m i) i (1+ c)))\n\t (take-apart (m i)\n\t\t\t (when (= m 1)\n\t\t\t (return-from take-apart ans))\n\n\t\t\t (when (< (sqrt m) i)\n\t\t\t (return-from take-apart\n\t\t\t (setf ans (append ans (list (cons m 1))))))\n\n\t\t\t (if (zerop (rem m i))\n\t\t\t (multiple-value-bind (m2 part) (divide m i 0)\n\t\t\t (setf ans (append ans (list part)))\n\t\t\t (take-apart m2 (1+ i)))\n\t\t\t (take-apart m (1+ i)))))\n (take-apart n 2)\n ans)))\n\n(defun abc142d ()\n (let* ((a (read))\n\t (b (read)))\n (format t \"~a~%\"\n\t (1+\n\t (length\n\t (intersection\n\t\t (mapcar #'car (prime-factorization a))\n\t\t (mapcar #'car (prime-factorization b))))))))\n\n(abc142d)", "language": "Lisp", "metadata": {"date": 1586435527, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02900.html", "problem_id": "p02900", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02900/input.txt", "sample_output_relpath": "derived/input_output/data/p02900/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02900/Lisp/s371348109.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s371348109", "user_id": "u652695471"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun prime-factorization (n)\n (let ((ans '()))\n (labels ((divide (m i c)\n\t\t (unless (zerop (rem m i))\n\t\t (return-from divide (values m (cons i c))))\n\t\t (divide (/ m i) i (1+ c)))\n\t (take-apart (m i)\n\t\t\t (when (= m 1)\n\t\t\t (return-from take-apart ans))\n\n\t\t\t (when (< (sqrt m) i)\n\t\t\t (return-from take-apart\n\t\t\t (setf ans (append ans (list (cons m 1))))))\n\n\t\t\t (if (zerop (rem m i))\n\t\t\t (multiple-value-bind (m2 part) (divide m i 0)\n\t\t\t (setf ans (append ans (list part)))\n\t\t\t (take-apart m2 (1+ i)))\n\t\t\t (take-apart m (1+ i)))))\n (take-apart n 2)\n ans)))\n\n(defun abc142d ()\n (let* ((a (read))\n\t (b (read)))\n (format t \"~a~%\"\n\t (1+\n\t (length\n\t (intersection\n\t\t (mapcar #'car (prime-factorization a))\n\t\t (mapcar #'car (prime-factorization b))))))))\n\n(abc142d)", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven are positive integers A and B.\n\nLet us choose some number of positive common divisors of A and B.\n\nHere, any two of the chosen divisors must be coprime.\n\nAt most, how many divisors can we choose?\n\nDefinition of common divisor\n\nAn integer d is said to be a common divisor of integers x and y when d divides both x and y.\n\nDefinition of being coprime\n\nIntegers x and y are said to be coprime when x and y have no positive common divisors other than 1.\n\nDefinition of dividing\n\nAn integer x is said to divide another integer y when there exists an integer \\alpha such that y = \\alpha x.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the maximum number of divisors that can be chosen to satisfy the condition.\n\nSample Input 1\n\n12 18\n\nSample Output 1\n\n3\n\n12 and 18 have the following positive common divisors: 1, 2, 3, and 6.\n\n1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1, 2, and 3, which achieve the maximum result.\n\nSample Input 2\n\n420 660\n\nSample Output 2\n\n4\n\nSample Input 3\n\n1 2019\n\nSample Output 3\n\n1\n\n1 and 2019 have no positive common divisors other than 1.", "sample_input": "12 18\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02900", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven are positive integers A and B.\n\nLet us choose some number of positive common divisors of A and B.\n\nHere, any two of the chosen divisors must be coprime.\n\nAt most, how many divisors can we choose?\n\nDefinition of common divisor\n\nAn integer d is said to be a common divisor of integers x and y when d divides both x and y.\n\nDefinition of being coprime\n\nIntegers x and y are said to be coprime when x and y have no positive common divisors other than 1.\n\nDefinition of dividing\n\nAn integer x is said to divide another integer y when there exists an integer \\alpha such that y = \\alpha x.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A, B \\leq 10^{12}\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the maximum number of divisors that can be chosen to satisfy the condition.\n\nSample Input 1\n\n12 18\n\nSample Output 1\n\n3\n\n12 and 18 have the following positive common divisors: 1, 2, 3, and 6.\n\n1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1, 2, and 3, which achieve the maximum result.\n\nSample Input 2\n\n420 660\n\nSample Output 2\n\n4\n\nSample Input 3\n\n1 2019\n\nSample Output 3\n\n1\n\n1 and 2019 have no positive common divisors other than 1.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 830, "cpu_time_ms": 134, "memory_kb": 15844}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s234793061", "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(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)\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(defconstant +inf+ #xffffffff)\n\n(defun calc-min-dists (src n graph)\n (declare #.OPT\n ((simple-array list (*)) graph)\n (uint32 n src))\n (let ((que (make-queue))\n (dists (make-array n :element-type 'uint32 :initial-element +inf+))\n (init t))\n (enqueue src que)\n (loop until (queue-empty-p que)\n for current of-type uint32 = (dequeue que)\n for dist = (if init 0 (aref dists current))\n do (setq init nil)\n (dolist (neighbor (aref graph current))\n (declare (uint32 neighbor))\n (when (= +inf+ (aref dists neighbor))\n (setf (aref dists neighbor) (+ dist 1))\n (enqueue neighbor que))))\n dists))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n ;; in : out\n (graph (make-array n :element-type 'list :initial-element nil))\n (min-len +inf+)\n (min-src 0)\n min-dists)\n (declare (uint32 n m min-len min-src))\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 (dotimes (i n)\n (let* ((dists (calc-min-dists i n graph))\n (len (aref dists i)))\n (declare ((simple-array uint32 (*)) dists))\n (declare (uint32 len))\n (when (< len min-len)\n (setq min-len len\n min-src i\n min-dists dists))))\n (if (= min-len +inf+)\n (println -1)\n (let* ((marked (make-array n :element-type 'bit :initial-element 0))\n (path\n (block dfs\n (sb-int:named-let recur ((v min-src) (path nil) (init t))\n (unless init\n (when (= v min-src)\n (return-from dfs (nreverse path)))\n (setf (aref marked v) 1))\n (let ((dist (if init 0 (aref min-dists v))))\n (dolist (neighbor (aref graph v))\n (when (and (zerop (aref marked neighbor))\n (= (aref min-dists neighbor) (+ dist 1)))\n (recur neighbor (cons neighbor path) nil))))))))\n (declare ((simple-array uint32 (*)) min-dists))\n (println min-len)\n (dolist (v path) (println (+ v 1)))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569727233, "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/s234793061.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s234793061", "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(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)\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(defconstant +inf+ #xffffffff)\n\n(defun calc-min-dists (src n graph)\n (declare #.OPT\n ((simple-array list (*)) graph)\n (uint32 n src))\n (let ((que (make-queue))\n (dists (make-array n :element-type 'uint32 :initial-element +inf+))\n (init t))\n (enqueue src que)\n (loop until (queue-empty-p que)\n for current of-type uint32 = (dequeue que)\n for dist = (if init 0 (aref dists current))\n do (setq init nil)\n (dolist (neighbor (aref graph current))\n (declare (uint32 neighbor))\n (when (= +inf+ (aref dists neighbor))\n (setf (aref dists neighbor) (+ dist 1))\n (enqueue neighbor que))))\n dists))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n ;; in : out\n (graph (make-array n :element-type 'list :initial-element nil))\n (min-len +inf+)\n (min-src 0)\n min-dists)\n (declare (uint32 n m min-len min-src))\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 (dotimes (i n)\n (let* ((dists (calc-min-dists i n graph))\n (len (aref dists i)))\n (declare ((simple-array uint32 (*)) dists))\n (declare (uint32 len))\n (when (< len min-len)\n (setq min-len len\n min-src i\n min-dists dists))))\n (if (= min-len +inf+)\n (println -1)\n (let* ((marked (make-array n :element-type 'bit :initial-element 0))\n (path\n (block dfs\n (sb-int:named-let recur ((v min-src) (path nil) (init t))\n (unless init\n (when (= v min-src)\n (return-from dfs (nreverse path)))\n (setf (aref marked v) 1))\n (let ((dist (if init 0 (aref min-dists v))))\n (dolist (neighbor (aref graph v))\n (when (and (zerop (aref marked neighbor))\n (= (aref min-dists neighbor) (+ dist 1)))\n (recur neighbor (cons neighbor path) nil))))))))\n (declare ((simple-array uint32 (*)) min-dists))\n (println min-len)\n (dolist (v path) (println (+ v 1)))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5927, "cpu_time_ms": 240, "memory_kb": 35432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s543481665", "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 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. (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 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(declaim (inline inverse-multiple-transform!))\n(defun inverse-multiple-transform! (vector &optional (op- #'-) (handle-zero t))\n \"Does the inverse transform of MULTIPLE-TRANSFORM!.\"\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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(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+ nil)\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 (declare (uint31 x y))\n (let ((res (+ x (- +mod+ y))))\n (if (>= res +mod+)\n (- res +mod+)\n res)))\n nil)\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": 1569181547, "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/s543481665.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s543481665", "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 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. (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 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(declaim (inline inverse-multiple-transform!))\n(defun inverse-multiple-transform! (vector &optional (op- #'-) (handle-zero t))\n \"Does the inverse transform of MULTIPLE-TRANSFORM!.\"\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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(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+ nil)\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 (declare (uint31 x y))\n (let ((res (+ x (- +mod+ y))))\n (if (>= res +mod+)\n (- res +mod+)\n res)))\n nil)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6858, "cpu_time_ms": 492, "memory_kb": 45416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s042511536", "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 #.OPT\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 (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 (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": 1569631926, "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/s042511536.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s042511536", "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 #.OPT\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 (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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5163, "cpu_time_ms": 227, "memory_kb": 27880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s098632170", "group_id": "codeNet:p02910", "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* ((s (read-line)))\n (write-line\n (if (loop for i from 1 to (length s)\n for c across s\n always (if (oddp i)\n (member c '(#\\R #\\U #\\D))\n (member c '(#\\L #\\U #\\D))))\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 \"RUDLUDR\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"DULL\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"UUUUUUUUUUUUUUU\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"ULURU\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"RDULULDURURLRDULRLR\n\"\n \"Yes\n\")))\n", "language": "Lisp", "metadata": {"date": 1568595822, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02910.html", "problem_id": "p02910", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02910/input.txt", "sample_output_relpath": "derived/input_output/data/p02910/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02910/Lisp/s098632170.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s098632170", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (write-line\n (if (loop for i from 1 to (length s)\n for c across s\n always (if (oddp i)\n (member c '(#\\R #\\U #\\D))\n (member c '(#\\L #\\U #\\D))))\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 \"RUDLUDR\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"DULL\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"UUUUUUUUUUUUUUU\n\"\n \"Yes\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"ULURU\n\"\n \"No\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"RDULULDURURLRDULRLR\n\"\n \"Yes\n\")))\n", "problem_context": "Score: 200 points\n\nProblem Statement\n\nTakahashi will do a tap dance. The dance is described by a string S where each character is L, R, U, or D. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character.\n\nS is said to be easily playable if and only if it satisfies both of the following conditions:\n\nEvery character in an odd position (1-st, 3-rd, 5-th, \\ldots) is R, U, or D.\n\nEvery character in an even position (2-nd, 4-th, 6-th, \\ldots) is L, U, or D.\n\nYour task is to print Yes if S is easily playable, and No otherwise.\n\nConstraints\n\nS is a string of length between 1 and 100 (inclusive).\n\nEach character of S is L, R, U, or D.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint Yes if S is easily playable, and No otherwise.\n\nSample Input 1\n\nRUDLUDR\n\nSample Output 1\n\nYes\n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is R, U, or D.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is L, U, or D.\n\nThus, S is easily playable.\n\nSample Input 2\n\nDULL\n\nSample Output 2\n\nNo\n\nThe 3-rd character is not R, U, nor D, so S is not easily playable.\n\nSample Input 3\n\nUUUUUUUUUUUUUUU\n\nSample Output 3\n\nYes\n\nSample Input 4\n\nULURU\n\nSample Output 4\n\nNo\n\nSample Input 5\n\nRDULULDURURLRDULRLR\n\nSample Output 5\n\nYes", "sample_input": "RUDLUDR\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02910", "source_text": "Score: 200 points\n\nProblem Statement\n\nTakahashi will do a tap dance. The dance is described by a string S where each character is L, R, U, or D. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character.\n\nS is said to be easily playable if and only if it satisfies both of the following conditions:\n\nEvery character in an odd position (1-st, 3-rd, 5-th, \\ldots) is R, U, or D.\n\nEvery character in an even position (2-nd, 4-th, 6-th, \\ldots) is L, U, or D.\n\nYour task is to print Yes if S is easily playable, and No otherwise.\n\nConstraints\n\nS is a string of length between 1 and 100 (inclusive).\n\nEach character of S is L, R, U, or D.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint Yes if S is easily playable, and No otherwise.\n\nSample Input 1\n\nRUDLUDR\n\nSample Output 1\n\nYes\n\nEvery character in an odd position (1-st, 3-rd, 5-th, 7-th) is R, U, or D.\n\nEvery character in an even position (2-nd, 4-th, 6-th) is L, U, or D.\n\nThus, S is easily playable.\n\nSample Input 2\n\nDULL\n\nSample Output 2\n\nNo\n\nThe 3-rd character is not R, U, nor D, so S is not easily playable.\n\nSample Input 3\n\nUUUUUUUUUUUUUUU\n\nSample Output 3\n\nYes\n\nSample Input 4\n\nULURU\n\nSample Output 4\n\nNo\n\nSample Input 5\n\nRDULULDURURLRDULRLR\n\nSample Output 5\n\nYes", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3992, "cpu_time_ms": 172, "memory_kb": 18276}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s232948408", "group_id": "codeNet:p02911", "input_text": "(defun count-a (n a)\n (let ((c (make-array n :initial-element 0)))\n (loop :for i :in a\n :do (setf (aref c (1- i)) (1+ (aref c (1- i)))))\n c))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (q (read))\n (a (loop :repeat q\n :collect (read)))\n (c (count-a n a)))\n (loop :for i :across c\n :do (format t \"~A~%\" (if (> i (- q k)) \"Yes\" \"No\")))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1568601655, "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/s232948408.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s232948408", "user_id": "u924821799"}, "prompt_components": {"gold_output": "No\nNo\nYes\nNo\nNo\nNo\n", "input_to_evaluate": "(defun count-a (n a)\n (let ((c (make-array n :initial-element 0)))\n (loop :for i :in a\n :do (setf (aref c (1- i)) (1+ (aref c (1- i)))))\n c))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (q (read))\n (a (loop :repeat q\n :collect (read)))\n (c (count-a n a)))\n (loop :for i :across c\n :do (format t \"~A~%\" (if (> i (- q k)) \"Yes\" \"No\")))))\n\n(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 417, "cpu_time_ms": 444, "memory_kb": 60264}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s620107204", "group_id": "codeNet:p02911", "input_text": "(defun calc-point (a i k q)\n (if (> (count i a) (- q k))\n \"Yes\"\n \"No\"))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (q (read))\n (a (loop :repeat q\n :collect (read))))\n (loop :for i :from 1 :to n\n :do (format t \"~A~%\" (calc-point a i k q)))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1568600089, "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/s620107204.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s620107204", "user_id": "u924821799"}, "prompt_components": {"gold_output": "No\nNo\nYes\nNo\nNo\nNo\n", "input_to_evaluate": "(defun calc-point (a i k q)\n (if (> (count i a) (- q k))\n \"Yes\"\n \"No\"))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (q (read))\n (a (loop :repeat q\n :collect (read))))\n (loop :for i :from 1 :to n\n :do (format t \"~A~%\" (calc-point a i k q)))))\n\n(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2104, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s825599082", "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)\n (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 (make-array 100000 :element-type 'uint62)))\n (declare (uint32 n))\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": 1568962527, "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/s825599082.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s825599082", "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)\n (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 (make-array 100000 :element-type 'uint62)))\n (declare (uint32 n))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5438, "cpu_time_ms": 226, "memory_kb": 24676}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s767240965", "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(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;;; 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.82f0)\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 (shuffle! as)\n (let ((rxor 0)\n (totalxor (reduce #'logxor as))\n (max-temp (float (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": 1568613512, "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/s767240965.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s767240965", "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(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;;; 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.82f0)\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 (shuffle! as)\n (let ((rxor 0)\n (totalxor (reduce #'logxor as))\n (max-temp (float (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4559, "cpu_time_ms": 1929, "memory_kb": 14948}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s342147231", "group_id": "codeNet:p02915", "input_text": "(princ(expt(read)3))", "language": "Lisp", "metadata": {"date": 1574492836, "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/s342147231.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s342147231", "user_id": "u657913472"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(princ(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 20, "cpu_time_ms": 23, "memory_kb": 3808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s873259972", "group_id": "codeNet:p02915", "input_text": "(print (expt (read) 3))", "language": "Lisp", "metadata": {"date": 1567911601, "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/s873259972.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s873259972", "user_id": "u529272520"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(print (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 21, "memory_kb": 3936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s842584718", "group_id": "codeNet:p02915", "input_text": "(print (expt (read) 3)))", "language": "Lisp", "metadata": {"date": 1567904517, "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/s842584718.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s842584718", "user_id": "u396817842"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(print (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 24, "cpu_time_ms": 95, "memory_kb": 9444}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s117922181", "group_id": "codeNet:p02915", "input_text": "(princ (expt (read) 3))", "language": "Lisp", "metadata": {"date": 1567904476, "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/s117922181.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s117922181", "user_id": "u610490393"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(princ (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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:s949938698", "group_id": "codeNet:p02916", "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 (as (make-array n :element-type 'uint32))\n (bs (make-array n :element-type 'uint32))\n (cs (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref as i) (- (read) 1)))\n (dotimes (i n) (setf (aref bs i) (read)))\n (dotimes (i (- n 1)) (setf (aref cs i) (read)))\n (let ((res (reduce #'+ bs)))\n #>res\n (dotimes (i (- n 1))\n (when (= (+ 1 (aref as i)) (aref as (+ i 1)))\n (incf res (aref cs (aref as 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\n3 1 2\n2 5 4\n3 6\n\"\n \"14\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n2 3 4 1\n13 5 8 24\n45 9 15\n\"\n \"74\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n50 50\n50\n\"\n \"150\n\")))\n", "language": "Lisp", "metadata": {"date": 1567904750, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02916.html", "problem_id": "p02916", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02916/input.txt", "sample_output_relpath": "derived/input_output/data/p02916/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02916/Lisp/s949938698.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s949938698", "user_id": "u352600849"}, "prompt_components": {"gold_output": "14\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 (as (make-array n :element-type 'uint32))\n (bs (make-array n :element-type 'uint32))\n (cs (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref as i) (- (read) 1)))\n (dotimes (i n) (setf (aref bs i) (read)))\n (dotimes (i (- n 1)) (setf (aref cs i) (read)))\n (let ((res (reduce #'+ bs)))\n #>res\n (dotimes (i (- n 1))\n (when (= (+ 1 (aref as i)) (aref as (+ i 1)))\n (incf res (aref cs (aref as 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\n3 1 2\n2 5 4\n3 6\n\"\n \"14\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n2 3 4 1\n13 5 8 24\n45 9 15\n\"\n \"74\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n50 50\n50\n\"\n \"150\n\")))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \\ldots, Dish N) once.\n\nThe i-th dish (1 \\leq i \\leq N) he ate was Dish A_i.\n\nWhen he eats Dish i (1 \\leq i \\leq N), he gains B_i satisfaction points.\n\nAdditionally, when he eats Dish i+1 just after eating Dish i (1 \\leq i \\leq N - 1), he gains C_i more satisfaction points.\n\nFind the sum of the satisfaction points he gained.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 20\n\n1 \\leq A_i \\leq N\n\nA_1, A_2, ..., A_N are all different.\n\n1 \\leq B_i \\leq 50\n\n1 \\leq C_i \\leq 50\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\nC_1 C_2 ... C_{N-1}\n\nOutput\n\nPrint the sum of the satisfaction points Takahashi gained, as an integer.\n\nSample Input 1\n\n3\n3 1 2\n2 5 4\n3 6\n\nSample Output 1\n\n14\n\nTakahashi gained 14 satisfaction points in total, as follows:\n\nFirst, he ate Dish 3 and gained 4 satisfaction points.\n\nNext, he ate Dish 1 and gained 2 satisfaction points.\n\nLastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.\n\nSample Input 2\n\n4\n2 3 4 1\n13 5 8 24\n45 9 15\n\nSample Output 2\n\n74\n\nSample Input 3\n\n2\n1 2\n50 50\n50\n\nSample Output 3\n\n150", "sample_input": "3\n3 1 2\n2 5 4\n3 6\n"}, "reference_outputs": ["14\n"], "source_document_id": "p02916", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \\ldots, Dish N) once.\n\nThe i-th dish (1 \\leq i \\leq N) he ate was Dish A_i.\n\nWhen he eats Dish i (1 \\leq i \\leq N), he gains B_i satisfaction points.\n\nAdditionally, when he eats Dish i+1 just after eating Dish i (1 \\leq i \\leq N - 1), he gains C_i more satisfaction points.\n\nFind the sum of the satisfaction points he gained.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 20\n\n1 \\leq A_i \\leq N\n\nA_1, A_2, ..., A_N are all different.\n\n1 \\leq B_i \\leq 50\n\n1 \\leq C_i \\leq 50\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\nC_1 C_2 ... C_{N-1}\n\nOutput\n\nPrint the sum of the satisfaction points Takahashi gained, as an integer.\n\nSample Input 1\n\n3\n3 1 2\n2 5 4\n3 6\n\nSample Output 1\n\n14\n\nTakahashi gained 14 satisfaction points in total, as follows:\n\nFirst, he ate Dish 3 and gained 4 satisfaction points.\n\nNext, he ate Dish 1 and gained 2 satisfaction points.\n\nLastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.\n\nSample Input 2\n\n4\n2 3 4 1\n13 5 8 24\n45 9 15\n\nSample Output 2\n\n74\n\nSample Input 3\n\n2\n1 2\n50 50\n50\n\nSample Output 3\n\n150", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4092, "cpu_time_ms": 173, "memory_kb": 19168}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s531714257", "group_id": "codeNet:p02917", "input_text": "(let* ((n (read))\n (b (make-array `(,n) :initial-element 0))\n (a 0))\n (loop :for i :from 1 :to (1- n)\n :do (setf (aref b i) (read)))\n ;\n (incf a (aref b 1))\n (loop :for i :from 2 :to (1- n)\n :do (incf a (min (aref b (1- i)) (aref b i))))\n (incf a (aref b (1- n)))\n (format t \"~A~%\" a))\n", "language": "Lisp", "metadata": {"date": 1598137338, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s531714257.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s531714257", "user_id": "u608227593"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(let* ((n (read))\n (b (make-array `(,n) :initial-element 0))\n (a 0))\n (loop :for i :from 1 :to (1- n)\n :do (setf (aref b i) (read)))\n ;\n (incf a (aref b 1))\n (loop :for i :from 2 :to (1- n)\n :do (incf a (min (aref b (1- i)) (aref b i))))\n (incf a (aref b (1- n)))\n (format t \"~A~%\" a))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 318, "cpu_time_ms": 17, "memory_kb": 24484}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s759311238", "group_id": "codeNet:p02917", "input_text": "(defun solve (n b)\n (declare (ignore n))\n (+ (first b)\n (loop for (x . xs) on b\n if (and xs\n (< (first xs) x))\n sum (first xs)\n else\n sum x)))\n\n#-swank\n(let* ((n (read))\n (b (loop repeat (1- n) collect (read))))\n (format t \"~A~%\" (solve n b)))\n", "language": "Lisp", "metadata": {"date": 1579751634, "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/s759311238.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s759311238", "user_id": "u202886318"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun solve (n b)\n (declare (ignore n))\n (+ (first b)\n (loop for (x . xs) on b\n if (and xs\n (< (first xs) x))\n sum (first xs)\n else\n sum x)))\n\n#-swank\n(let* ((n (read))\n (b (loop repeat (1- n) collect (read))))\n (format t \"~A~%\" (solve n b)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 198, "memory_kb": 18788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s707304531", "group_id": "codeNet:p02917", "input_text": "(defun calc-a (x y)\n (if (> x y)\n y\n x))\n\n(defun gen-a (n b)\n (append (list (aref b 0))\n (loop :for i :from 0 :to (- n 3)\n :collect (calc-a (aref b i) (aref b (1+ i))))\n (list (aref b (- n 2)))))\n\n(defun main ()\n (let* ((n (read))\n (b (coerce (loop :repeat (1- n) :for i = (read) :collect i)\n 'vector)))\n (format t \"~A~%\" (reduce #'+ (gen-a n b)))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1567909730, "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/s707304531.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s707304531", "user_id": "u924821799"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun calc-a (x y)\n (if (> x y)\n y\n x))\n\n(defun gen-a (n b)\n (append (list (aref b 0))\n (loop :for i :from 0 :to (- n 3)\n :collect (calc-a (aref b i) (aref b (1+ i))))\n (list (aref b (- n 2)))))\n\n(defun main ()\n (let* ((n (read))\n (b (coerce (loop :repeat (1- n) :for i = (read) :collect i)\n 'vector)))\n (format t \"~A~%\" (reduce #'+ (gen-a n b)))))\n\n(main)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 430, "cpu_time_ms": 142, "memory_kb": 16480}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s101103892", "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 &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 (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 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 (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 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": 1567959990, "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/s101103892.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s101103892", "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 &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 (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 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 (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 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9435, "cpu_time_ms": 1344, "memory_kb": 29288}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s657907788", "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": 1567948714, "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/s657907788.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s657907788", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11401, "cpu_time_ms": 1355, "memory_kb": 45280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s993638547", "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 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 (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 (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 (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 n :element-type 'uint32)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref ps i) (read-fixnum)))\n (let ((itreap (make-itreap n :initial-contents ps)))\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 (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": 1567948305, "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/s993638547.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s993638547", "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 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 (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 (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 (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 n :element-type 'uint32)))\n (declare (uint31 n))\n (dotimes (i n)\n (setf (aref ps i) (read-fixnum)))\n (let ((itreap (make-itreap n :initial-contents ps)))\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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11321, "cpu_time_ms": 1739, "memory_kb": 39268}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s317383063", "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\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\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(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(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 #.OPT\n ((simple-array uint32 (100000)) 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 (aref initial-contents mid)\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 (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 (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 'uint32)))\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 (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 (itreap-query itreap 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 (itreap-query itreap 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 (itreap-query itreap 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 (itreap-query itreap 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": 1567888328, "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/s317383063.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s317383063", "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\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\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(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(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 #.OPT\n ((simple-array uint32 (100000)) 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 (aref initial-contents mid)\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 (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 (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 'uint32)))\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 (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 (itreap-query itreap 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 (itreap-query itreap 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 (itreap-query itreap 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 (itreap-query itreap 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10784, "cpu_time_ms": 1713, "memory_kb": 42084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s757004147", "group_id": "codeNet:p02920", "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;;; 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(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)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +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 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 force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count 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 #.OPT\n ((integer 0 #.most-positive-fixnum) index))\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 #.OPT\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 and returns the resultant treap.\"\n (declare #.OPT\n ((or null itreap) itreap)\n ((integer 0 #.most-positive-fixnum) 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(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 %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 initial-contents)\n (declare (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 (aref initial-contents mid)\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-delete (itreap index)\n \"Destructively deletes the object at INDEX in ITREAP.\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) 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(defun itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) 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 itreap-bisect-left)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) itreap-bisect-left))\n(defun itreap-bisect-left (itreap threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\n\n(defun copy-itreap (itreap)\n \"Note that this copier uses the same priorities.\"\n (declare #.OPT\n (inline %make-itreap))\n (and itreap\n (%make-itreap (%itreap-value itreap)\n (%itreap-priority itreap)\n :left (copy-itreap (%itreap-left itreap))\n :right (copy-itreap (%itreap-right itreap))\n :count (%itreap-count 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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defmacro itreap-push (obj itreap pos)\n `(setf ,itreap (itreap-insert ,itreap ,pos ,obj)))\n\n(defmacro itreap-pop (itreap pos)\n (let ((p (gensym)))\n `(let ((,p ,pos))\n (prog1 (itreap-ref ,itreap ,p)\n (setf ,itreap (itreap-delete ,itreap ,p))))))\n\n(defun main ()\n (declare #.OPT)\n (declare (inline sort))\n (let* ((n (read))\n (len (expt 2 n))\n (ss (make-array len :element-type 'uint32)))\n (declare ((integer 1 18) n)\n ((simple-array uint32 (*)) ss))\n (dotimes (i len)\n (setf (aref ss i) (read-fixnum)))\n (setf ss (sort ss #'>))\n (let* ((rest (make-itreap len ss))\n current-set)\n (itreap-push (itreap-ref rest 0) current-set 0)\n (itreap-pop rest 0)\n (dotimes (i n)\n (let ((next-set (copy-itreap current-set)))\n (do-itreap (x current-set)\n (let ((pos (itreap-bisect-right rest x #'>)))\n (when (= pos (itreap-count rest))\n (write-line \"No\")\n (return-from main))\n (let ((next-hp (the uint32 (itreap-pop rest pos))))\n (setq next-set (itreap-insort next-set next-hp #'>)))))\n (setq current-set next-set)))\n (write-line \"Yes\"))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567938557, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02920.html", "problem_id": "p02920", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02920/input.txt", "sample_output_relpath": "derived/input_output/data/p02920/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02920/Lisp/s757004147.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s757004147", "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 (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;;; 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(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)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +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 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 force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count 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 #.OPT\n ((integer 0 #.most-positive-fixnum) index))\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 #.OPT\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 and returns the resultant treap.\"\n (declare #.OPT\n ((or null itreap) itreap)\n ((integer 0 #.most-positive-fixnum) 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(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 %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 initial-contents)\n (declare (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 (aref initial-contents mid)\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-delete (itreap index)\n \"Destructively deletes the object at INDEX in ITREAP.\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) 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(defun itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) 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 itreap-bisect-left)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) itreap-bisect-left))\n(defun itreap-bisect-left (itreap threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\n\n(defun copy-itreap (itreap)\n \"Note that this copier uses the same priorities.\"\n (declare #.OPT\n (inline %make-itreap))\n (and itreap\n (%make-itreap (%itreap-value itreap)\n (%itreap-priority itreap)\n :left (copy-itreap (%itreap-left itreap))\n :right (copy-itreap (%itreap-right itreap))\n :count (%itreap-count 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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defmacro itreap-push (obj itreap pos)\n `(setf ,itreap (itreap-insert ,itreap ,pos ,obj)))\n\n(defmacro itreap-pop (itreap pos)\n (let ((p (gensym)))\n `(let ((,p ,pos))\n (prog1 (itreap-ref ,itreap ,p)\n (setf ,itreap (itreap-delete ,itreap ,p))))))\n\n(defun main ()\n (declare #.OPT)\n (declare (inline sort))\n (let* ((n (read))\n (len (expt 2 n))\n (ss (make-array len :element-type 'uint32)))\n (declare ((integer 1 18) n)\n ((simple-array uint32 (*)) ss))\n (dotimes (i len)\n (setf (aref ss i) (read-fixnum)))\n (setf ss (sort ss #'>))\n (let* ((rest (make-itreap len ss))\n current-set)\n (itreap-push (itreap-ref rest 0) current-set 0)\n (itreap-pop rest 0)\n (dotimes (i n)\n (let ((next-set (copy-itreap current-set)))\n (do-itreap (x current-set)\n (let ((pos (itreap-bisect-right rest x #'>)))\n (when (= pos (itreap-count rest))\n (write-line \"No\")\n (return-from main))\n (let ((next-hp (the uint32 (itreap-pop rest pos))))\n (setq next-set (itreap-insort next-set next-hp #'>)))))\n (setq current-set next-set)))\n (write-line \"Yes\"))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have one slime.\n\nYou can set the health of this slime to any integer value of your choice.\n\nA slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second.\n\nDetermine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S.\n\nHere S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 18\n\n1 \\leq S_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 S_2 ... S_{2^N}\n\nOutput\n\nIf it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n4 2 3 1\n\nSample Output 1\n\nYes\n\nWe will show one way to make the multiset of the healths of the slimes that will exist in 2 seconds equal to S.\n\nFirst, set the health of the first slime to 4.\n\nBy letting the first slime spawn a slime whose health is 3, the healths of the slimes that exist in 1 second can be 4,~3.\n\nThen, by letting the first slime spawn a slime whose health is 2, and letting the second slime spawn a slime whose health is 1, the healths of the slimes that exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.\n\nSample Input 2\n\n2\n1 2 3 1\n\nSample Output 2\n\nYes\n\nS may contain multiple instances of the same integer.\n\nSample Input 3\n\n1\n1 1\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n5\n4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3\n\nSample Output 4\n\nNo", "sample_input": "2\n4 2 3 1\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02920", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have one slime.\n\nYou can set the health of this slime to any integer value of your choice.\n\nA slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second.\n\nDetermine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S.\n\nHere S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 18\n\n1 \\leq S_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 S_2 ... S_{2^N}\n\nOutput\n\nIf it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n4 2 3 1\n\nSample Output 1\n\nYes\n\nWe will show one way to make the multiset of the healths of the slimes that will exist in 2 seconds equal to S.\n\nFirst, set the health of the first slime to 4.\n\nBy letting the first slime spawn a slime whose health is 3, the healths of the slimes that exist in 1 second can be 4,~3.\n\nThen, by letting the first slime spawn a slime whose health is 2, and letting the second slime spawn a slime whose health is 1, the healths of the slimes that exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.\n\nSample Input 2\n\n2\n1 2 3 1\n\nSample Output 2\n\nYes\n\nS may contain multiple instances of the same integer.\n\nSample Input 3\n\n1\n1 1\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n5\n4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3\n\nSample Output 4\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15004, "cpu_time_ms": 548, "memory_kb": 80744}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s367539817", "group_id": "codeNet:p02920", "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;;; 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(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)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +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 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 force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count 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 #.OPT\n ((integer 0 #.most-positive-fixnum) index))\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 #.OPT\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 and returns the resultant treap.\"\n (declare #.OPT\n ((or null itreap) itreap)\n ((integer 0 #.most-positive-fixnum) 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(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 %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-delete (itreap index)\n \"Destructively deletes the object at INDEX in ITREAP.\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) 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(defun itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) 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 itreap-bisect-left)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) itreap-bisect-left))\n(defun itreap-bisect-left (itreap threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\n\n(defun copy-itreap (itreap)\n \"Note that this copier uses the same priorities.\"\n (declare #.OPT\n (inline %make-itreap))\n (and itreap\n (%make-itreap (%itreap-value itreap)\n (%itreap-priority itreap)\n :left (copy-itreap (%itreap-left itreap))\n :right (copy-itreap (%itreap-right itreap))\n :count (%itreap-count 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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defmacro itreap-push (obj itreap pos)\n `(setf ,itreap (itreap-insert ,itreap ,pos ,obj)))\n\n(defmacro itreap-pop (itreap pos)\n (let ((p (gensym)))\n `(let ((,p ,pos))\n (prog1 (itreap-ref ,itreap ,p)\n (setf ,itreap (itreap-delete ,itreap ,p))))))\n\n(defun main ()\n (declare #.OPT)\n (declare (inline sort))\n (let* ((n (read))\n (len (expt 2 n))\n (ss (make-array len :element-type 'uint32)))\n (declare ((integer 1 18) n)\n ((simple-array uint32 (*)) ss))\n (dotimes (i len)\n (setf (aref ss i) (read-fixnum)))\n (setf ss (sort ss #'>))\n (let* ((rest (make-itreap len :initial-contents ss))\n current-set)\n (itreap-push (itreap-ref rest 0) current-set 0)\n (itreap-pop rest 0)\n (dotimes (i n)\n (let ((next-set (copy-itreap current-set)))\n (do-itreap (x current-set)\n (let ((pos (itreap-bisect-right rest x #'>)))\n (when (= pos (itreap-count rest))\n (write-line \"No\")\n (return-from main))\n (let ((next-hp (the uint32 (itreap-pop rest pos))))\n (setq next-set (itreap-insort next-set next-hp #'>)))))\n (setq current-set next-set)))\n (write-line \"Yes\"))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567938428, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02920.html", "problem_id": "p02920", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02920/input.txt", "sample_output_relpath": "derived/input_output/data/p02920/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02920/Lisp/s367539817.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s367539817", "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 (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;;; 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(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)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +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 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 force-up))\n(defun force-up (itreap)\n \"Propagates up the information from children.\"\n (declare (itreap itreap))\n (update-count 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 #.OPT\n ((integer 0 #.most-positive-fixnum) index))\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 #.OPT\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 and returns the resultant treap.\"\n (declare #.OPT\n ((or null itreap) itreap)\n ((integer 0 #.most-positive-fixnum) 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(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 %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-delete (itreap index)\n \"Destructively deletes the object at INDEX in ITREAP.\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) 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(defun itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) 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 itreap-bisect-left)\n (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) itreap-bisect-left))\n(defun itreap-bisect-left (itreap threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(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) threshold)\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 threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nTHRESHOLD < ITREAP[index], where < is ORDER. Returns the size of ITREAP if\nITREAP[length-1] <= THRESHOLD. 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 threshold (%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.\"\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\n\n(defun copy-itreap (itreap)\n \"Note that this copier uses the same priorities.\"\n (declare #.OPT\n (inline %make-itreap))\n (and itreap\n (%make-itreap (%itreap-value itreap)\n (%itreap-priority itreap)\n :left (copy-itreap (%itreap-left itreap))\n :right (copy-itreap (%itreap-right itreap))\n :count (%itreap-count 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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-default-float-format* 'double-float))\n (prog1 (princ obj stream) (terpri stream))))\n\n(defconstant +mod+ 1000000007)\n\n;;;\n;;; Body\n;;;\n\n(defmacro itreap-push (obj itreap pos)\n `(setf ,itreap (itreap-insert ,itreap ,pos ,obj)))\n\n(defmacro itreap-pop (itreap pos)\n (let ((p (gensym)))\n `(let ((,p ,pos))\n (prog1 (itreap-ref ,itreap ,p)\n (setf ,itreap (itreap-delete ,itreap ,p))))))\n\n(defun main ()\n (declare #.OPT)\n (declare (inline sort))\n (let* ((n (read))\n (len (expt 2 n))\n (ss (make-array len :element-type 'uint32)))\n (declare ((integer 1 18) n)\n ((simple-array uint32 (*)) ss))\n (dotimes (i len)\n (setf (aref ss i) (read-fixnum)))\n (setf ss (sort ss #'>))\n (let* ((rest (make-itreap len :initial-contents ss))\n current-set)\n (itreap-push (itreap-ref rest 0) current-set 0)\n (itreap-pop rest 0)\n (dotimes (i n)\n (let ((next-set (copy-itreap current-set)))\n (do-itreap (x current-set)\n (let ((pos (itreap-bisect-right rest x #'>)))\n (when (= pos (itreap-count rest))\n (write-line \"No\")\n (return-from main))\n (let ((next-hp (the uint32 (itreap-pop rest pos))))\n (setq next-set (itreap-insort next-set next-hp #'>)))))\n (setq current-set next-set)))\n (write-line \"Yes\"))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nWe have one slime.\n\nYou can set the health of this slime to any integer value of your choice.\n\nA slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second.\n\nDetermine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S.\n\nHere S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 18\n\n1 \\leq S_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 S_2 ... S_{2^N}\n\nOutput\n\nIf it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n4 2 3 1\n\nSample Output 1\n\nYes\n\nWe will show one way to make the multiset of the healths of the slimes that will exist in 2 seconds equal to S.\n\nFirst, set the health of the first slime to 4.\n\nBy letting the first slime spawn a slime whose health is 3, the healths of the slimes that exist in 1 second can be 4,~3.\n\nThen, by letting the first slime spawn a slime whose health is 2, and letting the second slime spawn a slime whose health is 1, the healths of the slimes that exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.\n\nSample Input 2\n\n2\n1 2 3 1\n\nSample Output 2\n\nYes\n\nS may contain multiple instances of the same integer.\n\nSample Input 3\n\n1\n1 1\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n5\n4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3\n\nSample Output 4\n\nNo", "sample_input": "2\n4 2 3 1\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02920", "source_text": "Score : 600 points\n\nProblem Statement\n\nWe have one slime.\n\nYou can set the health of this slime to any integer value of your choice.\n\nA slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second.\n\nDetermine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S.\n\nHere S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 18\n\n1 \\leq S_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1 S_2 ... S_{2^N}\n\nOutput\n\nIf it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print Yes; otherwise, print No.\n\nSample Input 1\n\n2\n4 2 3 1\n\nSample Output 1\n\nYes\n\nWe will show one way to make the multiset of the healths of the slimes that will exist in 2 seconds equal to S.\n\nFirst, set the health of the first slime to 4.\n\nBy letting the first slime spawn a slime whose health is 3, the healths of the slimes that exist in 1 second can be 4,~3.\n\nThen, by letting the first slime spawn a slime whose health is 2, and letting the second slime spawn a slime whose health is 1, the healths of the slimes that exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.\n\nSample Input 2\n\n2\n1 2 3 1\n\nSample Output 2\n\nYes\n\nS may contain multiple instances of the same integer.\n\nSample Input 3\n\n1\n1 1\n\nSample Output 3\n\nNo\n\nSample Input 4\n\n5\n4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3\n\nSample Output 4\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15297, "cpu_time_ms": 549, "memory_kb": 80740}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s492121287", "group_id": "codeNet:p02922", "input_text": "(setq *a* (read))\n(setq *b* (read))\n\n(defun enlarge (now a b)\n (if (<= b now)\n 0\n (1+ (enlarge (+ now (1- a)) a b))))\n\n(print (enlarge 1 *a* *b*))", "language": "Lisp", "metadata": {"date": 1569524276, "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/s492121287.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s492121287", "user_id": "u358554431"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(setq *a* (read))\n(setq *b* (read))\n\n(defun enlarge (now a b)\n (if (<= b now)\n 0\n (1+ (enlarge (+ now (1- a)) a b))))\n\n(print (enlarge 1 *a* *b*))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 14, "memory_kb": 3816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s779182349", "group_id": "codeNet:p02922", "input_text": "(let ((a (read))\n (b (read)))\n (print (1+ (mod b a))))", "language": "Lisp", "metadata": {"date": 1567479130, "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/s779182349.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s779182349", "user_id": "u529272520"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (print (1+ (mod b a))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 13, "memory_kb": 3684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s875657285", "group_id": "codeNet:p02922", "input_text": "(let ((a (read))\n (b (read)))\n (princ (+ 1 (ceiling (max 0 (- b a)) (1- a)))))\n", "language": "Lisp", "metadata": {"date": 1567365076, "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/s875657285.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s875657285", "user_id": "u994767958"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (princ (+ 1 (ceiling (max 0 (- 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 132, "memory_kb": 12776}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s932062946", "group_id": "codeNet:p02923", "input_text": "(defun solve (l &optional (memo (+ (expt 10 9) 1)) (c 0) (ans 0))\n (cond \n ((null l) ans)\n ((<= (car l) memo) (solve (cdr l) (car l) (+ c 1) (max (1- c) ans)))\n (t (solve (cdr l) (+ (expt 10 9) 1) 0 ans))))\n\n(let* ((n (read))\n (l (read-from-string\n (concatenate 'string \"(\" (read-line) \")\"))))\n (princ (solve l)))", "language": "Lisp", "metadata": {"date": 1590343737, "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/s932062946.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s932062946", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve (l &optional (memo (+ (expt 10 9) 1)) (c 0) (ans 0))\n (cond \n ((null l) ans)\n ((<= (car l) memo) (solve (cdr l) (car l) (+ c 1) (max (1- c) ans)))\n (t (solve (cdr l) (+ (expt 10 9) 1) 0 ans))))\n\n(let* ((n (read))\n (l (read-from-string\n (concatenate 'string \"(\" (read-line) \")\"))))\n (princ (solve l)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 360, "cpu_time_ms": 247, "memory_kb": 47460}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s417839210", "group_id": "codeNet:p02923", "input_text": "(defun go-down (h)\n (loop with count = 0\n for (x . xs) on h\n if (or (null xs)\n (< x (first xs)))\n do (return (values count xs))\n else\n do (incf count)))\n\n(defun solve (n h)\n (declare (ignore n))\n (let ((result 0))\n (loop\n (multiple-value-bind (count rest)\n (go-down h)\n (setf result (max result count))\n (unless rest\n (return))\n (setf h rest)))\n result))\n\n#-swank\n(let* ((n (read))\n (h (loop repeat n collect (read))))\n (format t \"~A~%\" (solve n h)))\n", "language": "Lisp", "metadata": {"date": 1579730397, "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/s417839210.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s417839210", "user_id": "u202886318"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun go-down (h)\n (loop with count = 0\n for (x . xs) on h\n if (or (null xs)\n (< x (first xs)))\n do (return (values count xs))\n else\n do (incf count)))\n\n(defun solve (n h)\n (declare (ignore n))\n (let ((result 0))\n (loop\n (multiple-value-bind (count rest)\n (go-down h)\n (setf result (max result count))\n (unless rest\n (return))\n (setf h rest)))\n result))\n\n#-swank\n(let* ((n (read))\n (h (loop repeat n collect (read))))\n (format t \"~A~%\" (solve n h)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 560, "cpu_time_ms": 325, "memory_kb": 59876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s978553802", "group_id": "codeNet:p02923", "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(lst n)\n (labels ((rec(a lst i)\n\t\t (if (null lst)\n\t\t\t (list i nil)\n\t\t\t (if (<= (car lst) a)\n\t\t\t (rec (car lst) (cdr lst) (1+ i))\n\t\t\t (list i lst)))))\n\t(let ((r (rec (car lst) (cdr lst) 0)))\n\t (if (null (cadr r))\n\t\tr\n\t (f (cadr r) (car r))))))\n(compile 'f)\n(let* ((line0 (read-line nil nil))\n\t (line (read-line nil nil))\n\t (splited (mapcar #'parse-integer (splitat #\\space line))))\n (format t \"~A\" (car (f splited 0))))\n", "language": "Lisp", "metadata": {"date": 1567367627, "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/s978553802.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s978553802", "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(lst n)\n (labels ((rec(a lst i)\n\t\t (if (null lst)\n\t\t\t (list i nil)\n\t\t\t (if (<= (car lst) a)\n\t\t\t (rec (car lst) (cdr lst) (1+ i))\n\t\t\t (list i lst)))))\n\t(let ((r (rec (car lst) (cdr lst) 0)))\n\t (if (null (cadr r))\n\t\tr\n\t (f (cadr r) (car r))))))\n(compile 'f)\n(let* ((line0 (read-line nil nil))\n\t (line (read-line nil nil))\n\t (splited (mapcar #'parse-integer (splitat #\\space line))))\n (format t \"~A\" (car (f splited 0))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 689, "cpu_time_ms": 2105, "memory_kb": 113692}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s255300993", "group_id": "codeNet:p02924", "input_text": "(let ((n (read)))\n (princ\n (floor (* n (1- n)) 2)))\n(fresh-line)", "language": "Lisp", "metadata": {"date": 1593893698, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s255300993.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s255300993", "user_id": "u425762225"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((n (read)))\n (princ\n (floor (* n (1- n)) 2)))\n(fresh-line)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 15, "memory_kb": 24076}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s770147008", "group_id": "codeNet:p02924", "input_text": "(defun solve (n)\n (if (= n 1)\n 0\n (1+ (loop for i from 2 to (1- n)\n sum i))))\n\n#-swank\n(let* ((n (read)))\n (format t \"~A~%\" (solve n)))\n", "language": "Lisp", "metadata": {"date": 1579986235, "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/s770147008.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s770147008", "user_id": "u202886318"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun solve (n)\n (if (= n 1)\n 0\n (1+ (loop for i from 2 to (1- n)\n sum i))))\n\n#-swank\n(let* ((n (read)))\n (format t \"~A~%\" (solve n)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2104, "memory_kb": 7400}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s066498173", "group_id": "codeNet:p02924", "input_text": "(let ((n (read)))\n (cond ((= 1 n) (format t \"0~%\"))\n ((= 2 n) (format t \"1~%\"))\n (t (format t \"~A~%\" (/ (* (+ 1 (1- n)) (1- n)) 2)))))", "language": "Lisp", "metadata": {"date": 1567367570, "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/s066498173.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s066498173", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((n (read)))\n (cond ((= 1 n) (format t \"0~%\"))\n ((= 2 n) (format t \"1~%\"))\n (t (format t \"~A~%\" (/ (* (+ 1 (1- n)) (1- 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 176, "memory_kb": 12388}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s501706832", "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": 1567430444, "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/s501706832.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s501706832", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 244, "memory_kb": 26724}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s207014516", "group_id": "codeNet:p02927", "input_text": "(let* ((n (read))\n (m (read)))\n (defun seki-p (m d)\n (let* ((d10 (floor d 10))\n (d1 (mod d 10)))\n (and (<= 2 d1) (<= 2 d10) (= m (* d1 d10)))))\n (princ (loop :for t-month :from 1 :upto n\n :sum(loop :for t-day :from 1 :upto m :count(seki-p t-month t-day)))))", "language": "Lisp", "metadata": {"date": 1566695186, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02927.html", "problem_id": "p02927", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02927/input.txt", "sample_output_relpath": "derived/input_output/data/p02927/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02927/Lisp/s207014516.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s207014516", "user_id": "u610490393"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(let* ((n (read))\n (m (read)))\n (defun seki-p (m d)\n (let* ((d10 (floor d 10))\n (d1 (mod d 10)))\n (and (<= 2 d1) (<= 2 d10) (= m (* d1 d10)))))\n (princ (loop :for t-month :from 1 :upto n\n :sum(loop :for t-day :from 1 :upto m :count(seki-p t-month t-day)))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nToday is August 24, one of the five Product Days in a year.\n\nA date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day):\n\nd_1 \\geq 2\n\nd_{10} \\geq 2\n\nd_1 \\times d_{10} = m\n\nTakahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D.\n\nIn Takahashi Calendar, how many Product Days does a year have?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq M \\leq 100\n\n1 \\leq D \\leq 99\n\nInput\n\nInput is given from Standard Input in the following format:\n\nM D\n\nOutput\n\nPrint the number of Product Days in a year in Takahashi Calender.\n\nSample Input 1\n\n15 40\n\nSample Output 1\n\n10\n\nThere are 10 Product Days in a year, as follows (m-d denotes Month m, Day d):\n\n4-22\n\n6-23\n\n6-32\n\n8-24\n\n9-33\n\n10-25\n\n12-26\n\n12-34\n\n14-27\n\n15-35\n\nSample Input 2\n\n12 31\n\nSample Output 2\n\n5\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\n0", "sample_input": "15 40\n"}, "reference_outputs": ["10\n"], "source_document_id": "p02927", "source_text": "Score : 200 points\n\nProblem Statement\n\nToday is August 24, one of the five Product Days in a year.\n\nA date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day):\n\nd_1 \\geq 2\n\nd_{10} \\geq 2\n\nd_1 \\times d_{10} = m\n\nTakahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D.\n\nIn Takahashi Calendar, how many Product Days does a year have?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq M \\leq 100\n\n1 \\leq D \\leq 99\n\nInput\n\nInput is given from Standard Input in the following format:\n\nM D\n\nOutput\n\nPrint the number of Product Days in a year in Takahashi Calender.\n\nSample Input 1\n\n15 40\n\nSample Output 1\n\n10\n\nThere are 10 Product Days in a year, as follows (m-d denotes Month m, Day d):\n\n4-22\n\n6-23\n\n6-32\n\n8-24\n\n9-33\n\n10-25\n\n12-26\n\n12-34\n\n14-27\n\n15-35\n\nSample Input 2\n\n12 31\n\nSample Output 2\n\n5\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 290, "cpu_time_ms": 426, "memory_kb": 15840}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s358501110", "group_id": "codeNet:p02928", "input_text": "(let ((n (read))\n (k (read))\n (a (make-array 0 :element-type 'integer\n :adjustable t\n :fill-pointer t))\n (ans 0)\n kp kd)\n (dotimes (i n)\n (vector-push-extend (read) a))\n (setf kp (floor (* k (1+ k)) 2))\n (setf kd (floor (* k (1- k)) 2))\n (loop for i from 0 upto (1- n)\n do (let ((m (aref a i))\n (cnt 0)\n (mcnt 0))\n (loop for j from 0 upto (1- n)\n do (cond ((and (< j i) (< (aref a j) m)) (incf mcnt))\n ((< (aref a j) m) (incf cnt))))\n (incf ans (* cnt kp))\n (incf ans (* mcnt kd))\n (setf ans (rem ans 1000000007))))\n (princ ans))\n", "language": "Lisp", "metadata": {"date": 1566696826, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02928.html", "problem_id": "p02928", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02928/input.txt", "sample_output_relpath": "derived/input_output/data/p02928/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02928/Lisp/s358501110.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s358501110", "user_id": "u994767958"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((n (read))\n (k (read))\n (a (make-array 0 :element-type 'integer\n :adjustable t\n :fill-pointer t))\n (ans 0)\n kp kd)\n (dotimes (i n)\n (vector-push-extend (read) a))\n (setf kp (floor (* k (1+ k)) 2))\n (setf kd (floor (* k (1- k)) 2))\n (loop for i from 0 upto (1- n)\n do (let ((m (aref a i))\n (cnt 0)\n (mcnt 0))\n (loop for j from 0 upto (1- n)\n do (cond ((and (< j i) (< (aref a j) m)) (incf mcnt))\n ((< (aref a j) m) (incf cnt))))\n (incf ans (* cnt kp))\n (incf ans (* mcnt kd))\n (setf ans (rem ans 1000000007))))\n (princ ans))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.\n\nLet B be a sequence of K \\times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.\n\nFind the inversion number of B, modulo 10^9 + 7.\n\nHere the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \\leq i < j \\leq K \\times N - 1) such that B_i > B_j.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2000\n\n1 \\leq K \\leq 10^9\n\n1 \\leq A_i \\leq 2000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_0 A_1 ... A_{N - 1}\n\nOutput\n\nPrint the inversion number of B, modulo 10^9 + 7.\n\nSample Input 1\n\n2 2\n2 1\n\nSample Output 1\n\n3\n\nIn this case, B~=~2,~1,~2,~1. We have:\n\nB_0 > B_1\n\nB_0 > B_3\n\nB_2 > B_3\n\nThus, the inversion number of B is 3.\n\nSample Input 2\n\n3 5\n1 1 1\n\nSample Output 2\n\n0\n\nA may contain multiple occurrences of the same number.\n\nSample Input 3\n\n10 998244353\n10 9 8 7 5 6 3 4 2 1\n\nSample Output 3\n\n185297239\n\nBe sure to print the output modulo 10^9 + 7.", "sample_input": "2 2\n2 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02928", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.\n\nLet B be a sequence of K \\times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.\n\nFind the inversion number of B, modulo 10^9 + 7.\n\nHere the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \\leq i < j \\leq K \\times N - 1) such that B_i > B_j.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2000\n\n1 \\leq K \\leq 10^9\n\n1 \\leq A_i \\leq 2000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_0 A_1 ... A_{N - 1}\n\nOutput\n\nPrint the inversion number of B, modulo 10^9 + 7.\n\nSample Input 1\n\n2 2\n2 1\n\nSample Output 1\n\n3\n\nIn this case, B~=~2,~1,~2,~1. We have:\n\nB_0 > B_1\n\nB_0 > B_3\n\nB_2 > B_3\n\nThus, the inversion number of B is 3.\n\nSample Input 2\n\n3 5\n1 1 1\n\nSample Output 2\n\n0\n\nA may contain multiple occurrences of the same number.\n\nSample Input 3\n\n10 998244353\n10 9 8 7 5 6 3 4 2 1\n\nSample Output 3\n\n185297239\n\nBe sure to print the output modulo 10^9 + 7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 734, "cpu_time_ms": 300, "memory_kb": 16612}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s286208748", "group_id": "codeNet:p02928", "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 calc-base (as)\n (declare ((simple-array uint32 (*)) as))\n (let ((n (length as))\n (res 0))\n (dotimes (i n)\n (loop for j from (+ i 1) below n\n do (when (> (aref as i) (aref as j))\n (incf res))))\n res))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (let ((base (* k (calc-base as)))\n (delta 0))\n #>base\n (dotimes (i n)\n (dotimes (j n)\n (when (> (aref as j) (aref as i))\n (incf delta))))\n #>delta\n (let ((res (* delta (floor (* k (- k 1)) 2))))\n (println (mod (+ res base) +mod+))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566695449, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02928.html", "problem_id": "p02928", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02928/input.txt", "sample_output_relpath": "derived/input_output/data/p02928/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02928/Lisp/s286208748.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s286208748", "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(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 calc-base (as)\n (declare ((simple-array uint32 (*)) as))\n (let ((n (length as))\n (res 0))\n (dotimes (i n)\n (loop for j from (+ i 1) below n\n do (when (> (aref as i) (aref as j))\n (incf res))))\n res))\n\n(defun main ()\n (let* ((n (read))\n (k (read))\n (as (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (let ((base (* k (calc-base as)))\n (delta 0))\n #>base\n (dotimes (i n)\n (dotimes (j n)\n (when (> (aref as j) (aref as i))\n (incf delta))))\n #>delta\n (let ((res (* delta (floor (* k (- k 1)) 2))))\n (println (mod (+ res base) +mod+))))))\n\n#-swank (main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.\n\nLet B be a sequence of K \\times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.\n\nFind the inversion number of B, modulo 10^9 + 7.\n\nHere the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \\leq i < j \\leq K \\times N - 1) such that B_i > B_j.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2000\n\n1 \\leq K \\leq 10^9\n\n1 \\leq A_i \\leq 2000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_0 A_1 ... A_{N - 1}\n\nOutput\n\nPrint the inversion number of B, modulo 10^9 + 7.\n\nSample Input 1\n\n2 2\n2 1\n\nSample Output 1\n\n3\n\nIn this case, B~=~2,~1,~2,~1. We have:\n\nB_0 > B_1\n\nB_0 > B_3\n\nB_2 > B_3\n\nThus, the inversion number of B is 3.\n\nSample Input 2\n\n3 5\n1 1 1\n\nSample Output 2\n\n0\n\nA may contain multiple occurrences of the same number.\n\nSample Input 3\n\n10 998244353\n10 9 8 7 5 6 3 4 2 1\n\nSample Output 3\n\n185297239\n\nBe sure to print the output modulo 10^9 + 7.", "sample_input": "2 2\n2 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02928", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.\n\nLet B be a sequence of K \\times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.\n\nFind the inversion number of B, modulo 10^9 + 7.\n\nHere the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \\leq i < j \\leq K \\times N - 1) such that B_i > B_j.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 2000\n\n1 \\leq K \\leq 10^9\n\n1 \\leq A_i \\leq 2000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nA_0 A_1 ... A_{N - 1}\n\nOutput\n\nPrint the inversion number of B, modulo 10^9 + 7.\n\nSample Input 1\n\n2 2\n2 1\n\nSample Output 1\n\n3\n\nIn this case, B~=~2,~1,~2,~1. We have:\n\nB_0 > B_1\n\nB_0 > B_3\n\nB_2 > B_3\n\nThus, the inversion number of B is 3.\n\nSample Input 2\n\n3 5\n1 1 1\n\nSample Output 2\n\n0\n\nA may contain multiple occurrences of the same number.\n\nSample Input 3\n\n10 998244353\n10 9 8 7 5 6 3 4 2 1\n\nSample Output 3\n\n185297239\n\nBe sure to print the output modulo 10^9 + 7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3080, "cpu_time_ms": 477, "memory_kb": 24936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s497871879", "group_id": "codeNet:p02930", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (list n n) :element-type 'uint32)))\n (declare (uint31 n))\n (labels ((recur (l r level)\n (declare (uint31 l r level))\n (when (>= (- r l) 2)\n (let ((c (floor (+ l r) 2)))\n (loop for i from l below c\n do (loop for j from c below r\n do (setf (aref as i j) level)))\n (recur l c (+ level 1))\n (recur c r (+ level 1))))))\n (recur 0 n 1)\n (with-buffered-stdout\n (loop for i below (- n 1)\n for init = t\n do (loop for j from (+ i 1) below n\n do (if init\n (setq init nil)\n (write-char #\\ ))\n (princ (aref as i j)))\n (terpri))))))\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\n\"\n \"1 2\n1\n\")))\n", "language": "Lisp", "metadata": {"date": 1571368554, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02930.html", "problem_id": "p02930", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02930/input.txt", "sample_output_relpath": "derived/input_output/data/p02930/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02930/Lisp/s497871879.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s497871879", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1 2\n1\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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (list n n) :element-type 'uint32)))\n (declare (uint31 n))\n (labels ((recur (l r level)\n (declare (uint31 l r level))\n (when (>= (- r l) 2)\n (let ((c (floor (+ l r) 2)))\n (loop for i from l below c\n do (loop for j from c below r\n do (setf (aref as i j) level)))\n (recur l c (+ level 1))\n (recur c r (+ level 1))))))\n (recur 0 n 1)\n (with-buffered-stdout\n (loop for i below (- n 1)\n for init = t\n do (loop for j from (+ i 1) below n\n do (if init\n (setq init nil)\n (write-char #\\ ))\n (princ (aref as i j)))\n (terpri))))))\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\n\"\n \"1 2\n1\n\")))\n", "problem_context": "Score: 600 points\n\nProblem Statement\n\nAtCoder's head office consists of N rooms numbered 1 to N. For any two rooms, there is a direct passage connecting these rooms.\n\nFor security reasons, Takahashi the president asked you to set a level for every passage, which is a positive integer and must satisfy the following condition:\n\nFor each room i\\ (1 \\leq i \\leq N), if we leave Room i, pass through some passages whose levels are all equal and get back to Room i, the number of times we pass through a passage is always even.\n\nYour task is to set levels to the passages so that the highest level of a passage is minimized.\n\nConstraints\n\nN is an integer between 2 and 500 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint one way to set levels to the passages so that the objective is achieved, as follows:\n\na_{1,2} a_{1,3} ... a_{1,N}\na_{2,3} ... a_{2,N}\n.\n.\n.\na_{N-1,N}\n\nHere a_{i,j} is the level of the passage connecting Room i and Room j.\n\nIf there are multiple solutions, any of them will be accepted.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n1 2\n1\n\nThe following image describes this output:\n\nFor example, if we leave Room 2, traverse the path 2 \\to 3 \\to 2 \\to 3 \\to 2 \\to 1 \\to 2 while only passing passages of level 1 and get back to Room 2, we pass through a passage six times.", "sample_input": "3\n"}, "reference_outputs": ["1 2\n1\n"], "source_document_id": "p02930", "source_text": "Score: 600 points\n\nProblem Statement\n\nAtCoder's head office consists of N rooms numbered 1 to N. For any two rooms, there is a direct passage connecting these rooms.\n\nFor security reasons, Takahashi the president asked you to set a level for every passage, which is a positive integer and must satisfy the following condition:\n\nFor each room i\\ (1 \\leq i \\leq N), if we leave Room i, pass through some passages whose levels are all equal and get back to Room i, the number of times we pass through a passage is always even.\n\nYour task is to set levels to the passages so that the highest level of a passage is minimized.\n\nConstraints\n\nN is an integer between 2 and 500 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint one way to set levels to the passages so that the objective is achieved, as follows:\n\na_{1,2} a_{1,3} ... a_{1,N}\na_{2,3} ... a_{2,N}\n.\n.\n.\na_{N-1,N}\n\nHere a_{i,j} is the level of the passage connecting Room i and Room j.\n\nIf there are multiple solutions, any of them will be accepted.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n1 2\n1\n\nThe following image describes this output:\n\nFor example, if we leave Room 2, traverse the path 2 \\to 3 \\to 2 \\to 3 \\to 2 \\to 1 \\to 2 while only passing passages of level 1 and get back to Room 2, we pass through a passage six times.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4738, "cpu_time_ms": 68, "memory_kb": 10856}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s600816569", "group_id": "codeNet:p02934", "input_text": "(princ (float (/ 1 (reduce #'+ (loop :repeat (read) :collect (/ 1 (read)))))))", "language": "Lisp", "metadata": {"date": 1567135156, "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/s600816569.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s600816569", "user_id": "u610490393"}, "prompt_components": {"gold_output": "7.5\n", "input_to_evaluate": "(princ (float (/ 1 (reduce #'+ (loop :repeat (read) :collect (/ 1 (read)))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 4064}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s767233645", "group_id": "codeNet:p02935", "input_text": "(let* ((lst (sort (loop :repeat (read) :collect (read)) #'<)))\n (defun mod-add (a b)\n (/ (+ a b) 2))\n (princ (float (reduce #'mod-add lst))))", "language": "Lisp", "metadata": {"date": 1572361813, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02935.html", "problem_id": "p02935", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02935/input.txt", "sample_output_relpath": "derived/input_output/data/p02935/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02935/Lisp/s767233645.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s767233645", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3.5\n", "input_to_evaluate": "(let* ((lst (sort (loop :repeat (read) :collect (read)) #'<)))\n (defun mod-add (a b)\n (/ (+ a b) 2))\n (princ (float (reduce #'mod-add lst))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \\leq i \\leq N) is v_i.\n\nWhen you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.\n\nAfter you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.\n\nConstraints\n\n2 \\leq N \\leq 50\n\n1 \\leq v_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\nv_1 v_2 \\ldots v_N\n\nOutput\n\nPrint a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.\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\n3 4\n\nSample Output 1\n\n3.5\n\nIf you start with two ingredients, the only choice is to put both of them in the pot. The value of the ingredient resulting from the ingredients of values 3 and 4 is (3 + 4) / 2 = 3.5.\n\nPrinting 3.50001, 3.49999, and so on will also be accepted.\n\nSample Input 2\n\n3\n500 300 200\n\nSample Output 2\n\n375\n\nYou start with three ingredients this time, and you can choose what to use in the first composition. There are three possible choices:\n\nUse the ingredients of values 500 and 300 to produce an ingredient of value (500 + 300) / 2 = 400. The next composition will use this ingredient and the ingredient of value 200, resulting in an ingredient of value (400 + 200) / 2 = 300.\n\nUse the ingredients of values 500 and 200 to produce an ingredient of value (500 + 200) / 2 = 350. The next composition will use this ingredient and the ingredient of value 300, resulting in an ingredient of value (350 + 300) / 2 = 325.\n\nUse the ingredients of values 300 and 200 to produce an ingredient of value (300 + 200) / 2 = 250. The next composition will use this ingredient and the ingredient of value 500, resulting in an ingredient of value (250 + 500) / 2 = 375.\n\nThus, the maximum possible value of the last ingredient remaining is 375.\n\nPrinting 375.0 and so on will also be accepted.\n\nSample Input 3\n\n5\n138 138 138 138 138\n\nSample Output 3\n\n138", "sample_input": "2\n3 4\n"}, "reference_outputs": ["3.5\n"], "source_document_id": "p02935", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \\leq i \\leq N) is v_i.\n\nWhen you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.\n\nAfter you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.\n\nConstraints\n\n2 \\leq N \\leq 50\n\n1 \\leq v_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\nv_1 v_2 \\ldots v_N\n\nOutput\n\nPrint a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.\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\n3 4\n\nSample Output 1\n\n3.5\n\nIf you start with two ingredients, the only choice is to put both of them in the pot. The value of the ingredient resulting from the ingredients of values 3 and 4 is (3 + 4) / 2 = 3.5.\n\nPrinting 3.50001, 3.49999, and so on will also be accepted.\n\nSample Input 2\n\n3\n500 300 200\n\nSample Output 2\n\n375\n\nYou start with three ingredients this time, and you can choose what to use in the first composition. There are three possible choices:\n\nUse the ingredients of values 500 and 300 to produce an ingredient of value (500 + 300) / 2 = 400. The next composition will use this ingredient and the ingredient of value 200, resulting in an ingredient of value (400 + 200) / 2 = 300.\n\nUse the ingredients of values 500 and 200 to produce an ingredient of value (500 + 200) / 2 = 350. The next composition will use this ingredient and the ingredient of value 300, resulting in an ingredient of value (350 + 300) / 2 = 325.\n\nUse the ingredients of values 300 and 200 to produce an ingredient of value (300 + 200) / 2 = 250. The next composition will use this ingredient and the ingredient of value 500, resulting in an ingredient of value (250 + 500) / 2 = 375.\n\nThus, the maximum possible value of the last ingredient remaining is 375.\n\nPrinting 375.0 and so on will also be accepted.\n\nSample Input 3\n\n5\n138 138 138 138 138\n\nSample Output 3\n\n138", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 154, "memory_kb": 14308}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s899469490", "group_id": "codeNet:p02940", "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;;; Arithmetic operations with static modulus\n;;;\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\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(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+ 998244353)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((n (read))\n (s (read-line))\n (r 0)\n (g 0)\n (b 0)\n (rg 0)\n (gb 0)\n (br 0)\n (res 1))\n (declare (uint31 r g b rg gb br res))\n (dotimes (i (* 3 n))\n (ecase (aref s i)\n (#\\R (cond ((> gb 0)\n (mulfmod res gb)\n (decf gb))\n ((> g 0)\n (mulfmod res g)\n (decf g)\n (incf rg))\n ((> b 0)\n (mulfmod res b)\n (decf b)\n (incf br))\n (t (incf r))))\n (#\\G (cond ((> br 0)\n (mulfmod res br)\n (decf br))\n ((> b 0)\n (mulfmod res b)\n (decf b)\n (incf gb))\n ((> r 0)\n (mulfmod res r)\n (decf r)\n (incf rg))\n (t (incf g))))\n (#\\B (cond ((> rg 0)\n (mulfmod res rg)\n (decf rg))\n ((> r 0)\n (mulfmod res r)\n (decf r)\n (incf br))\n ((> g 0)\n (mulfmod res g)\n (decf g)\n (incf gb))\n (t (incf b))))))\n (loop for i from 1 to n\n do (mulfmod res i))\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 \"216\n\"\n (run \"3\nRRRGGGBBB\n\" nil)))\n (it.bese.fiveam:is\n (equal \"960\n\"\n (run \"5\nBBRGRRGRGGRBBGB\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1596690518, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02940.html", "problem_id": "p02940", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02940/input.txt", "sample_output_relpath": "derived/input_output/data/p02940/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02940/Lisp/s899469490.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s899469490", "user_id": "u352600849"}, "prompt_components": {"gold_output": "216\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;;; Arithmetic operations with static modulus\n;;;\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\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(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+ 998244353)\n\n;;;\n;;; Body\n;;;\n\n(define-mod-operations +mod+)\n(defun main ()\n (let* ((n (read))\n (s (read-line))\n (r 0)\n (g 0)\n (b 0)\n (rg 0)\n (gb 0)\n (br 0)\n (res 1))\n (declare (uint31 r g b rg gb br res))\n (dotimes (i (* 3 n))\n (ecase (aref s i)\n (#\\R (cond ((> gb 0)\n (mulfmod res gb)\n (decf gb))\n ((> g 0)\n (mulfmod res g)\n (decf g)\n (incf rg))\n ((> b 0)\n (mulfmod res b)\n (decf b)\n (incf br))\n (t (incf r))))\n (#\\G (cond ((> br 0)\n (mulfmod res br)\n (decf br))\n ((> b 0)\n (mulfmod res b)\n (decf b)\n (incf gb))\n ((> r 0)\n (mulfmod res r)\n (decf r)\n (incf rg))\n (t (incf g))))\n (#\\B (cond ((> rg 0)\n (mulfmod res rg)\n (decf rg))\n ((> r 0)\n (mulfmod res r)\n (decf r)\n (incf br))\n ((> g 0)\n (mulfmod res g)\n (decf g)\n (incf gb))\n (t (incf b))))))\n (loop for i from 1 to n\n do (mulfmod res i))\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 \"216\n\"\n (run \"3\nRRRGGGBBB\n\" nil)))\n (it.bese.fiveam:is\n (equal \"960\n\"\n (run \"5\nBBRGRRGRGGRBBGB\n\" nil))))\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nWe have 3N colored balls with IDs from 1 to 3N.\nA string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is R, green if S_i is G, and blue if S_i is B. There are N red balls, N green balls, and N blue balls.\n\nTakahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball.\nThe people want balls with IDs close to each other, so he will additionally satisfy the following condition:\n\nLet a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order.\n\nThen, \\sum_j (c_j-a_j) should be as small as possible.\n\nFind the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353.\nWe consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n|S|=3N\n\nS consists of R, G, and B, and each of these characters occurs N times in S.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the number of ways in which Takahashi can distribute the balls, modulo 998244353.\n\nSample Input 1\n\n3\nRRRGGGBBB\n\nSample Output 1\n\n216\n\nThe minimum value of \\sum_j (c_j-a_j) is 18 when the balls are, for example, distributed as follows:\n\nThe first person gets Ball 1, 5, and 9.\n\nThe second person gets Ball 2, 4, and 8.\n\nThe third person gets Ball 3, 6, and 7.\n\nSample Input 2\n\n5\nBBRGRRGRGGRBBGB\n\nSample Output 2\n\n960", "sample_input": "3\nRRRGGGBBB\n"}, "reference_outputs": ["216\n"], "source_document_id": "p02940", "source_text": "Score : 800 points\n\nProblem Statement\n\nWe have 3N colored balls with IDs from 1 to 3N.\nA string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is R, green if S_i is G, and blue if S_i is B. There are N red balls, N green balls, and N blue balls.\n\nTakahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball.\nThe people want balls with IDs close to each other, so he will additionally satisfy the following condition:\n\nLet a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order.\n\nThen, \\sum_j (c_j-a_j) should be as small as possible.\n\nFind the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353.\nWe consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n|S|=3N\n\nS consists of R, G, and B, and each of these characters occurs N times in S.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the number of ways in which Takahashi can distribute the balls, modulo 998244353.\n\nSample Input 1\n\n3\nRRRGGGBBB\n\nSample Output 1\n\n216\n\nThe minimum value of \\sum_j (c_j-a_j) is 18 when the balls are, for example, distributed as follows:\n\nThe first person gets Ball 1, 5, and 9.\n\nThe second person gets Ball 2, 4, and 8.\n\nThe third person gets Ball 3, 6, and 7.\n\nSample Input 2\n\n5\nBBRGRRGRGGRBBGB\n\nSample Output 2\n\n960", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5728, "cpu_time_ms": 44, "memory_kb": 27380}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s433463965", "group_id": "codeNet:p02941", "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;;;\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;; Body\n\n;; value . index\n(define-binary-heap heap\n :order (lambda (x y)\n (> (car x) (car y)))\n :element-type (cons uint32 uint32))\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 (q (make-heap n))\n (res 0))\n (declare (uint62 n res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (let ((b (read-fixnum)))\n (setf (aref bs i) b)\n (cond ((> b (aref as i))\n (heap-push (cons b i) q))\n ((< b (aref as i))\n (println -1)\n (return-from main)))))\n (loop\n (when (heap-empty-p q)\n (return))\n (destructuring-bind (max-value . index) (heap-pop q)\n (declare (uint31 max-value index))\n (let* ((prev-value (aref bs (mod (- index 1) n)))\n (next-value (aref bs (mod (+ index 1) n)))\n (new-value (- max-value prev-value next-value)))\n (declare (uint31 prev-value next-value))\n (incf res)\n (cond ((= new-value (aref as index))\n (setf (aref bs index) new-value)\n )\n ((< new-value (aref as index))\n (println -1)\n (return-from main))\n (t\n (let* ((count (floor (- new-value (aref as index))\n (+ prev-value next-value)))\n (newnew-value (- new-value (* count (+ prev-value next-value)))))\n (declare (uint31 count newnew-value))\n (incf res count)\n (setf (aref bs index) newnew-value)\n (unless (= newnew-value (aref as index))\n (heap-push (cons newnew-value index) q))))))))\n (println res)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566098542, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02941.html", "problem_id": "p02941", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02941/input.txt", "sample_output_relpath": "derived/input_output/data/p02941/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02941/Lisp/s433463965.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s433463965", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\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;;;\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;; Body\n\n;; value . index\n(define-binary-heap heap\n :order (lambda (x y)\n (> (car x) (car y)))\n :element-type (cons uint32 uint32))\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 (q (make-heap n))\n (res 0))\n (declare (uint62 n res))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (dotimes (i n)\n (let ((b (read-fixnum)))\n (setf (aref bs i) b)\n (cond ((> b (aref as i))\n (heap-push (cons b i) q))\n ((< b (aref as i))\n (println -1)\n (return-from main)))))\n (loop\n (when (heap-empty-p q)\n (return))\n (destructuring-bind (max-value . index) (heap-pop q)\n (declare (uint31 max-value index))\n (let* ((prev-value (aref bs (mod (- index 1) n)))\n (next-value (aref bs (mod (+ index 1) n)))\n (new-value (- max-value prev-value next-value)))\n (declare (uint31 prev-value next-value))\n (incf res)\n (cond ((= new-value (aref as index))\n (setf (aref bs index) new-value)\n )\n ((< new-value (aref as index))\n (println -1)\n (return-from main))\n (t\n (let* ((count (floor (- new-value (aref as index))\n (+ prev-value next-value)))\n (newnew-value (- new-value (* count (+ prev-value next-value)))))\n (declare (uint31 count newnew-value))\n (incf res count)\n (setf (aref bs index) newnew-value)\n (unless (= newnew-value (aref as index))\n (heap-push (cons newnew-value index) q))))))))\n (println res)))\n\n#-swank (main)\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nThere are N positive integers arranged in a circle.\n\nNow, the i-th number is A_i. Takahashi wants the i-th number to be B_i. For this objective, he will repeatedly perform the following operation:\n\nChoose an integer i such that 1 \\leq i \\leq N.\n\nLet a, b, c be the (i-1)-th, i-th, and (i+1)-th numbers, respectively. Replace the i-th number with a+b+c.\n\nHere the 0-th number is the N-th number, and the (N+1)-th number is the 1-st number.\n\nDetermine if Takahashi can achieve his objective.\nIf the answer is yes, find the minimum number of operations required.\n\nConstraints\n\n3 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i, B_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\nB_1 B_2 ... B_N\n\nOutput\n\nPrint the minimum number of operations required, or -1 if the objective cannot be achieved.\n\nSample Input 1\n\n3\n1 1 1\n13 5 7\n\nSample Output 1\n\n4\n\nTakahashi can achieve his objective by, for example, performing the following operations:\n\nReplace the second number with 3.\n\nReplace the second number with 5.\n\nReplace the third number with 7.\n\nReplace the first number with 13.\n\nSample Input 2\n\n4\n1 2 3 4\n2 3 4 5\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n5\n5 6 5 2 1\n9817 1108 6890 4343 8704\n\nSample Output 3\n\n25", "sample_input": "3\n1 1 1\n13 5 7\n"}, "reference_outputs": ["4\n"], "source_document_id": "p02941", "source_text": "Score : 800 points\n\nProblem Statement\n\nThere are N positive integers arranged in a circle.\n\nNow, the i-th number is A_i. Takahashi wants the i-th number to be B_i. For this objective, he will repeatedly perform the following operation:\n\nChoose an integer i such that 1 \\leq i \\leq N.\n\nLet a, b, c be the (i-1)-th, i-th, and (i+1)-th numbers, respectively. Replace the i-th number with a+b+c.\n\nHere the 0-th number is the N-th number, and the (N+1)-th number is the 1-st number.\n\nDetermine if Takahashi can achieve his objective.\nIf the answer is yes, find the minimum number of operations required.\n\nConstraints\n\n3 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq A_i, B_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\nB_1 B_2 ... B_N\n\nOutput\n\nPrint the minimum number of operations required, or -1 if the objective cannot be achieved.\n\nSample Input 1\n\n3\n1 1 1\n13 5 7\n\nSample Output 1\n\n4\n\nTakahashi can achieve his objective by, for example, performing the following operations:\n\nReplace the second number with 3.\n\nReplace the second number with 5.\n\nReplace the third number with 7.\n\nReplace the first number with 13.\n\nSample Input 2\n\n4\n1 2 3 4\n2 3 4 5\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n5\n5 6 5 2 1\n9817 1108 6890 4343 8704\n\nSample Output 3\n\n25", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9995, "cpu_time_ms": 516, "memory_kb": 47844}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s784356056", "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* ((x1 (random m))\n (x2 (random m)))\n (unless (= x1 x2)\n (let* ((y (random n))\n (a1 (floor (aref as y x1) m))\n (a2 (floor (aref as y x2) m)))\n (unless (= a1 a2)\n (let ((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 (+ 1 (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 (+ 1 (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": 1596619852, "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/s784356056.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s784356056", "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* ((x1 (random m))\n (x2 (random m)))\n (unless (= x1 x2)\n (let* ((y (random n))\n (a1 (floor (aref as y x1) m))\n (a2 (floor (aref as y x2) m)))\n (unless (= a1 a2)\n (let ((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 (+ 1 (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 (+ 1 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7178, "cpu_time_ms": 2206, "memory_kb": 25392}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s906816726", "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 (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 (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;;;\n;;; Maximum bipartite matching (Hopcroft-Karp, O(E sqrt(V)))\n;;;\n\n;; NOTE: The number of elements in the graph must be less than 2^32-1 as we use\n;; (UNSIGNED-BYTE 32) here for efficiency.\n\n;; NOTE: Pay attention to the stack size!\n\n(defconstant +graph-inf-distance+ #xffffffff)\n\n(defstruct (bipartite-graph\n (:constructor make-bgraph\n (size1\n size2\n &aux\n (graph1 (make-array size1 :element-type 'list :initial-element nil))\n (matching1 (make-array size1 :element-type 'fixnum :initial-element -1))\n (matching2 (make-array size2 :element-type 'fixnum :initial-element -1))))\n (:conc-name bgraph-))\n (size1 0 :type (unsigned-byte 32))\n (size2 0 :type (unsigned-byte 32))\n (graph1 nil :type (simple-array list (*)))\n (matching1 nil :type (simple-array fixnum (*)))\n (matching2 nil :type (simple-array fixnum (*))))\n\n(declaim (inline bgraph-add-edge!))\n(defun bgraph-add-edge! (bgraph vertex1 vertex2)\n (push vertex2 (aref (bgraph-graph1 bgraph) vertex1))\n bgraph)\n\n(defun %fill-levels (bgraph levels1 levels2 queue)\n \"Does BFS and fills LEVELS.\"\n (declare (optimize (speed 3) (safety 0))\n ((simple-array (unsigned-byte 32) (*)) levels1 levels2 queue))\n (let ((graph1 (bgraph-graph1 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (q-front 0)\n (q-end 0)\n (found nil))\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 levels1 +graph-inf-distance+)\n (fill levels2 +graph-inf-distance+)\n (dotimes (i (bgraph-size1 bgraph))\n (when (= -1 (aref matching1 i))\n (setf (aref levels1 i) 0)\n (enqueue i)))\n (loop until (= q-front q-end)\n for vertex = (dequeue)\n do (dolist (next (aref graph1 vertex))\n (when (= +graph-inf-distance+ (aref levels2 next))\n (setf (aref levels2 next) (+ 1 (aref levels1 vertex)))\n (let ((partner (aref matching2 next)))\n (when (= -1 partner)\n (setq found t)\n (return))\n (setf (aref levels1 partner) (+ 1 (aref levels2 next)))\n (enqueue partner))))))\n found))\n\n(defun %find-matching (bgraph src levels1 levels2)\n \"Does DFS and makes matching greedily on the residual network.\"\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) src)\n ((simple-array (unsigned-byte 32) (*)) levels1 levels2))\n (let ((matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (graph1 (bgraph-graph1 bgraph)))\n (labels ((dfs (v)\n (declare ((integer 0 #.most-positive-fixnum) v))\n (dolist (next (aref graph1 v))\n (when (= (aref levels2 next) (+ 1 (aref levels1 v)))\n (setf (aref levels2 next) +graph-inf-distance+) ; mark visited\n (let ((partner (aref matching2 next)))\n (when (or (= -1 partner) (dfs partner))\n (setf (aref matching1 v) next\n (aref matching2 next) v\n (aref levels1 v) +graph-inf-distance+ ; mark visited\n )\n (return-from dfs t)))))\n (setf (aref levels1 v) +graph-inf-distance+) ; mark visited\n nil ; not matched\n ))\n (dfs src))))\n\n(declaim (ftype (function * (values (unsigned-byte 32) &optional)) bgraph-build-matching!))\n(defun bgraph-build-matching! (bgraph)\n \"Makes a maximum bipartite matching and returns two vectors: correspondence\nfrom group 1 to group 2, and correspondence from group 2 to group 1. At an\nunmatched vertex, -1 is stored.\"\n (declare (optimize (speed 3)))\n (let* ((size1 (bgraph-size1 bgraph))\n (size2 (bgraph-size2 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (levels1 (make-array size1 :element-type '(unsigned-byte 32)))\n (levels2 (make-array size2 :element-type '(unsigned-byte 32)))\n (queue (make-array (+ size1 size2) :element-type '(unsigned-byte 32)))\n (count 0))\n (declare ((integer 0 #.most-positive-fixnum) count))\n (loop while (%fill-levels bgraph levels1 levels2 queue)\n do (dotimes (v size1)\n (when (and (= -1 (aref matching1 v))\n (%find-matching bgraph v levels1 levels2))\n (incf count))))\n count))\n\n;; not tested\n(defun coerce-to-bgraph (graph)\n \"Converts adjacency lists representation of undirected graph to\nBIPARTITE-GRAPH.\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 (nums (make-array n :element-type 'fixnum))\n (size0 0)\n (size1 0))\n (declare ((integer 0 #.most-positive-fixnum) size0 size1))\n (labels ((dfs (vertex color)\n (cond ((zerop (aref visited vertex))\n (setf (aref visited vertex) 1\n (aref colors vertex) color)\n (if (zerop color)\n (setf (aref nums vertex) size0\n size0 (+ size0 1))\n (setf (aref nums vertex) size1\n size1 (+ size1 1)))\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 (error \"Not bipartite.\")))))\n (dotimes (i n)\n (when (zerop (aref visited i))\n (dfs i 1)))\n (let ((bgraph (make-bgraph size0 size1)))\n (dotimes (i n)\n (when (zerop (aref colors i))\n (let ((i-num (aref nums i)))\n (dolist (j (aref graph i))\n (let ((j-num (aref nums j)))\n (bgraph-add-edge! bgraph i-num j-num))))))\n bgraph))))\n\n;; not tested\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n (simple-array (integer 0 #.most-positive-fixnum) (*))\n &optional))\n bgraph-decompose!))\n(defun bgraph-decompose (bgraph)\n \"Decomposes a residual network to strongly connected components by Tarjan's\nalgorithm. BGRAPH-BUILD-MATCHING! must be called beforehand.\"\n (declare (optimize (speed 3)))\n (let* ((size1 (bgraph-size1 bgraph))\n (size2 (bgraph-size2 bgraph))\n (total-size (+ size1 size2 2))\n (source (+ size1 size2))\n (sink (+ size1 size2 1))\n (graph1 (bgraph-graph1 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (ord 0) ; in-order\n (ords (make-array total-size :element-type 'fixnum :initial-element -1))\n (lowlinks (make-array total-size :element-type 'fixnum))\n (components (make-array total-size\n :element-type '(integer 0 #.most-positive-fixnum)))\n (comp-index 0) ; index number of component\n (sizes (make-array total-size\n :element-type '(integer 0 #.most-positive-fixnum)\n :initial-element 0))\n (stack (make-array total-size :element-type '(integer 0 #.most-positive-fixnum)))\n (end 0) ; stack pointer\n (in-stack (make-array total-size :element-type 'bit :initial-element 0)))\n (declare ((integer 0 #.most-positive-fixnum) ord end comp-index source sink total-size))\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 (frob (v next)\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 (visit (v)\n (setf (aref ords v) ord\n (aref lowlinks v) ord)\n (incf ord)\n (%push v)\n (cond ((= v source)\n (loop for next below size1\n when (= -1 (aref matching1 next))\n do (frob v next)))\n ((= v sink)\n (loop for next below size2\n unless (= -1 (aref matching2 next))\n do (frob v (+ size1 next))))\n ((and (< v size1) (= -1 (aref matching1 v)))\n (dolist (next (aref graph1 v))\n (declare ((integer 0 #.most-positive-fixnum) next))\n (frob v (+ next size1))))\n ((and (< v size1) (/= -1 (aref matching1 v)))\n (frob v source)\n (dolist (next (aref graph1 v))\n (declare ((integer 0 #.most-positive-fixnum) next))\n (unless (= next (aref matching1 v))\n (frob v (+ next size1)))))\n ((= -1 (aref matching2 (- v size1)))\n (frob v sink))\n (t\n ;; (assert (/= -1 (aref matching2 (- v size1))))\n (frob v (aref matching2 (- v size1)))))\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 total-size)\n (when (= -1 (aref ords v))\n (visit v)))\n (values (subseq components 0 size1)\n (subseq components size1 (+ size1 size2))))))\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(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 match (tmp store counts target-col)\n (declare ((simple-array uint31 (* *)) tmp counts)\n (uint31 target-col))\n (destructuring-bind (n m) (array-dimensions tmp)\n (declare (uint8 n m))\n (let ((bgraph (make-bgraph m m))\n (lbase 0))\n (dotimes (y n)\n (dotimes (rnode m)\n (when (= +nan+ (aref tmp y rnode))\n (dotimes (loffset (aref counts y target-col))\n (bgraph-add-edge! bgraph (+ lbase loffset) rnode))))\n (incf lbase (aref counts y target-col)))\n (assert (= m (bgraph-build-matching! bgraph)))\n (let ((matching (bgraph-matching1 bgraph))\n (idx 0))\n (dotimes (y n)\n (dotimes (_ (aref counts y target-col))\n (setf (aref tmp y (aref matching idx))\n (pop (aref store y target-col)))\n (incf idx)))))))\n\n\n(defun solve (as)\n (declare ((simple-array uint31 (* *)) as))\n (destructuring-bind (n m) (array-dimensions as)\n (let ((tmp (make-array (list n m) :element-type 'uint31 :initial-element +nan+))\n (store (make-array (list n n) :element-type 'list :initial-element nil))\n (counts (make-array (list n n) :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 i (floor a m)))\n (push a (aref store i (floor a m))))))\n (dotimes (col (array-dimension tmp 0))\n (match tmp store counts col))\n tmp)))\n\n(defconstant +nan+ #x7fffffff)\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (list n m) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (dotimes (j m)\n (setf (aref as i j) (- (read-fixnum) 1))))\n (let ((res (solve as)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (println-matrix res :key #'1+)\n (dotimes (j m)\n (dotimes (i1 n)\n (loop for i2 from (+ i1 1) below n\n when (> (aref res i1 j) (aref res i2 j))\n do (rotatef (aref res i1 j) (aref res i2 j)))))\n (println-matrix res :key #'1+))))))\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": 1596616109, "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/s906816726.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s906816726", "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 (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 (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;;;\n;;; Maximum bipartite matching (Hopcroft-Karp, O(E sqrt(V)))\n;;;\n\n;; NOTE: The number of elements in the graph must be less than 2^32-1 as we use\n;; (UNSIGNED-BYTE 32) here for efficiency.\n\n;; NOTE: Pay attention to the stack size!\n\n(defconstant +graph-inf-distance+ #xffffffff)\n\n(defstruct (bipartite-graph\n (:constructor make-bgraph\n (size1\n size2\n &aux\n (graph1 (make-array size1 :element-type 'list :initial-element nil))\n (matching1 (make-array size1 :element-type 'fixnum :initial-element -1))\n (matching2 (make-array size2 :element-type 'fixnum :initial-element -1))))\n (:conc-name bgraph-))\n (size1 0 :type (unsigned-byte 32))\n (size2 0 :type (unsigned-byte 32))\n (graph1 nil :type (simple-array list (*)))\n (matching1 nil :type (simple-array fixnum (*)))\n (matching2 nil :type (simple-array fixnum (*))))\n\n(declaim (inline bgraph-add-edge!))\n(defun bgraph-add-edge! (bgraph vertex1 vertex2)\n (push vertex2 (aref (bgraph-graph1 bgraph) vertex1))\n bgraph)\n\n(defun %fill-levels (bgraph levels1 levels2 queue)\n \"Does BFS and fills LEVELS.\"\n (declare (optimize (speed 3) (safety 0))\n ((simple-array (unsigned-byte 32) (*)) levels1 levels2 queue))\n (let ((graph1 (bgraph-graph1 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (q-front 0)\n (q-end 0)\n (found nil))\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 levels1 +graph-inf-distance+)\n (fill levels2 +graph-inf-distance+)\n (dotimes (i (bgraph-size1 bgraph))\n (when (= -1 (aref matching1 i))\n (setf (aref levels1 i) 0)\n (enqueue i)))\n (loop until (= q-front q-end)\n for vertex = (dequeue)\n do (dolist (next (aref graph1 vertex))\n (when (= +graph-inf-distance+ (aref levels2 next))\n (setf (aref levels2 next) (+ 1 (aref levels1 vertex)))\n (let ((partner (aref matching2 next)))\n (when (= -1 partner)\n (setq found t)\n (return))\n (setf (aref levels1 partner) (+ 1 (aref levels2 next)))\n (enqueue partner))))))\n found))\n\n(defun %find-matching (bgraph src levels1 levels2)\n \"Does DFS and makes matching greedily on the residual network.\"\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) src)\n ((simple-array (unsigned-byte 32) (*)) levels1 levels2))\n (let ((matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (graph1 (bgraph-graph1 bgraph)))\n (labels ((dfs (v)\n (declare ((integer 0 #.most-positive-fixnum) v))\n (dolist (next (aref graph1 v))\n (when (= (aref levels2 next) (+ 1 (aref levels1 v)))\n (setf (aref levels2 next) +graph-inf-distance+) ; mark visited\n (let ((partner (aref matching2 next)))\n (when (or (= -1 partner) (dfs partner))\n (setf (aref matching1 v) next\n (aref matching2 next) v\n (aref levels1 v) +graph-inf-distance+ ; mark visited\n )\n (return-from dfs t)))))\n (setf (aref levels1 v) +graph-inf-distance+) ; mark visited\n nil ; not matched\n ))\n (dfs src))))\n\n(declaim (ftype (function * (values (unsigned-byte 32) &optional)) bgraph-build-matching!))\n(defun bgraph-build-matching! (bgraph)\n \"Makes a maximum bipartite matching and returns two vectors: correspondence\nfrom group 1 to group 2, and correspondence from group 2 to group 1. At an\nunmatched vertex, -1 is stored.\"\n (declare (optimize (speed 3)))\n (let* ((size1 (bgraph-size1 bgraph))\n (size2 (bgraph-size2 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (levels1 (make-array size1 :element-type '(unsigned-byte 32)))\n (levels2 (make-array size2 :element-type '(unsigned-byte 32)))\n (queue (make-array (+ size1 size2) :element-type '(unsigned-byte 32)))\n (count 0))\n (declare ((integer 0 #.most-positive-fixnum) count))\n (loop while (%fill-levels bgraph levels1 levels2 queue)\n do (dotimes (v size1)\n (when (and (= -1 (aref matching1 v))\n (%find-matching bgraph v levels1 levels2))\n (incf count))))\n count))\n\n;; not tested\n(defun coerce-to-bgraph (graph)\n \"Converts adjacency lists representation of undirected graph to\nBIPARTITE-GRAPH.\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 (nums (make-array n :element-type 'fixnum))\n (size0 0)\n (size1 0))\n (declare ((integer 0 #.most-positive-fixnum) size0 size1))\n (labels ((dfs (vertex color)\n (cond ((zerop (aref visited vertex))\n (setf (aref visited vertex) 1\n (aref colors vertex) color)\n (if (zerop color)\n (setf (aref nums vertex) size0\n size0 (+ size0 1))\n (setf (aref nums vertex) size1\n size1 (+ size1 1)))\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 (error \"Not bipartite.\")))))\n (dotimes (i n)\n (when (zerop (aref visited i))\n (dfs i 1)))\n (let ((bgraph (make-bgraph size0 size1)))\n (dotimes (i n)\n (when (zerop (aref colors i))\n (let ((i-num (aref nums i)))\n (dolist (j (aref graph i))\n (let ((j-num (aref nums j)))\n (bgraph-add-edge! bgraph i-num j-num))))))\n bgraph))))\n\n;; not tested\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n (simple-array (integer 0 #.most-positive-fixnum) (*))\n &optional))\n bgraph-decompose!))\n(defun bgraph-decompose (bgraph)\n \"Decomposes a residual network to strongly connected components by Tarjan's\nalgorithm. BGRAPH-BUILD-MATCHING! must be called beforehand.\"\n (declare (optimize (speed 3)))\n (let* ((size1 (bgraph-size1 bgraph))\n (size2 (bgraph-size2 bgraph))\n (total-size (+ size1 size2 2))\n (source (+ size1 size2))\n (sink (+ size1 size2 1))\n (graph1 (bgraph-graph1 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (ord 0) ; in-order\n (ords (make-array total-size :element-type 'fixnum :initial-element -1))\n (lowlinks (make-array total-size :element-type 'fixnum))\n (components (make-array total-size\n :element-type '(integer 0 #.most-positive-fixnum)))\n (comp-index 0) ; index number of component\n (sizes (make-array total-size\n :element-type '(integer 0 #.most-positive-fixnum)\n :initial-element 0))\n (stack (make-array total-size :element-type '(integer 0 #.most-positive-fixnum)))\n (end 0) ; stack pointer\n (in-stack (make-array total-size :element-type 'bit :initial-element 0)))\n (declare ((integer 0 #.most-positive-fixnum) ord end comp-index source sink total-size))\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 (frob (v next)\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 (visit (v)\n (setf (aref ords v) ord\n (aref lowlinks v) ord)\n (incf ord)\n (%push v)\n (cond ((= v source)\n (loop for next below size1\n when (= -1 (aref matching1 next))\n do (frob v next)))\n ((= v sink)\n (loop for next below size2\n unless (= -1 (aref matching2 next))\n do (frob v (+ size1 next))))\n ((and (< v size1) (= -1 (aref matching1 v)))\n (dolist (next (aref graph1 v))\n (declare ((integer 0 #.most-positive-fixnum) next))\n (frob v (+ next size1))))\n ((and (< v size1) (/= -1 (aref matching1 v)))\n (frob v source)\n (dolist (next (aref graph1 v))\n (declare ((integer 0 #.most-positive-fixnum) next))\n (unless (= next (aref matching1 v))\n (frob v (+ next size1)))))\n ((= -1 (aref matching2 (- v size1)))\n (frob v sink))\n (t\n ;; (assert (/= -1 (aref matching2 (- v size1))))\n (frob v (aref matching2 (- v size1)))))\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 total-size)\n (when (= -1 (aref ords v))\n (visit v)))\n (values (subseq components 0 size1)\n (subseq components size1 (+ size1 size2))))))\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(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 match (tmp store counts target-col)\n (declare ((simple-array uint31 (* *)) tmp counts)\n (uint31 target-col))\n (destructuring-bind (n m) (array-dimensions tmp)\n (declare (uint8 n m))\n (let ((bgraph (make-bgraph m m))\n (lbase 0))\n (dotimes (y n)\n (dotimes (rnode m)\n (when (= +nan+ (aref tmp y rnode))\n (dotimes (loffset (aref counts y target-col))\n (bgraph-add-edge! bgraph (+ lbase loffset) rnode))))\n (incf lbase (aref counts y target-col)))\n (assert (= m (bgraph-build-matching! bgraph)))\n (let ((matching (bgraph-matching1 bgraph))\n (idx 0))\n (dotimes (y n)\n (dotimes (_ (aref counts y target-col))\n (setf (aref tmp y (aref matching idx))\n (pop (aref store y target-col)))\n (incf idx)))))))\n\n\n(defun solve (as)\n (declare ((simple-array uint31 (* *)) as))\n (destructuring-bind (n m) (array-dimensions as)\n (let ((tmp (make-array (list n m) :element-type 'uint31 :initial-element +nan+))\n (store (make-array (list n n) :element-type 'list :initial-element nil))\n (counts (make-array (list n n) :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 i (floor a m)))\n (push a (aref store i (floor a m))))))\n (dotimes (col (array-dimension tmp 0))\n (match tmp store counts col))\n tmp)))\n\n(defconstant +nan+ #x7fffffff)\n(defun main ()\n (let* ((n (read))\n (m (read))\n (as (make-array (list n m) :element-type 'uint31 :initial-element 0)))\n (dotimes (i n)\n (dotimes (j m)\n (setf (aref as i j) (- (read-fixnum) 1))))\n (let ((res (solve as)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (println-matrix res :key #'1+)\n (dotimes (j m)\n (dotimes (i1 n)\n (loop for i2 from (+ i1 1) below n\n when (> (aref res i1 j) (aref res i2 j))\n do (rotatef (aref res i1 j) (aref res i2 j)))))\n (println-matrix res :key #'1+))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 18884, "cpu_time_ms": 44, "memory_kb": 36220}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s671568618", "group_id": "codeNet:p02945", "input_text": "(defun ans (a b)\n (max (+ a b) (- a b) (* a b))\n )\n\n(format t \"~a~%\" (ans (read) (read)))", "language": "Lisp", "metadata": {"date": 1569009783, "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/s671568618.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s671568618", "user_id": "u358554431"}, "prompt_components": {"gold_output": "-10\n", "input_to_evaluate": "(defun ans (a b)\n (max (+ a b) (- a b) (* a b))\n )\n\n(format t \"~a~%\" (ans (read) (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 121, "memory_kb": 11748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s596981607", "group_id": "codeNet:p02946", "input_text": "(defun make-range (n x)\n (loop :as i\n :from (- x (- n 1))\n :to (+ x (- n 1))\n :collect i))\n \n(defun insert-delimiter (delimiter list)\n (cons (car list)\n (if (null (cdr list))\n nil\n (cons delimiter\n (insert-delimiter delimiter (cdr list))))))\n\n(defun join (delimiter list)\n (apply #'concatenate (cons 'string (insert-delimiter delimiter list))))\n\n\n\n(let ((n (read))\n (x (read)))\n (princ (join \" \" (mapcar #'princ-to-string (make-range n x)))))\n", "language": "Lisp", "metadata": {"date": 1586659615, "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/s596981607.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s596981607", "user_id": "u606976120"}, "prompt_components": {"gold_output": "5 6 7 8 9\n", "input_to_evaluate": "(defun make-range (n x)\n (loop :as i\n :from (- x (- n 1))\n :to (+ x (- n 1))\n :collect i))\n \n(defun insert-delimiter (delimiter list)\n (cons (car list)\n (if (null (cdr list))\n nil\n (cons delimiter\n (insert-delimiter delimiter (cdr list))))))\n\n(defun join (delimiter list)\n (apply #'concatenate (cons 'string (insert-delimiter delimiter list))))\n\n\n\n(let ((n (read))\n (x (read)))\n (princ (join \" \" (mapcar #'princ-to-string (make-range n x)))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 22, "memory_kb": 4580}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s249935437", "group_id": "codeNet:p02946", "input_text": "(let ((k (read))\n (x (read)))\n (loop for i from (- x k -1) to (+ x k -1)\n do (format t \"~a~^ \" i)))\n", "language": "Lisp", "metadata": {"date": 1565485606, "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/s249935437.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s249935437", "user_id": "u956039157"}, "prompt_components": {"gold_output": "5 6 7 8 9\n", "input_to_evaluate": "(let ((k (read))\n (x (read)))\n (loop for i from (- x k -1) to (+ x k -1)\n do (format t \"~a~^ \" i)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 135, "memory_kb": 12520}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s794683040", "group_id": "codeNet:p02947", "input_text": "(let* ((n (read))\n (lst (concatenate 'vector (loop :repeat n :collect (sort (read-line) #'char<)))))\n (princ (loop :for k :from 1 :upto (1- n)\n :sum (loop :for j :from 0 :upto (1- k)\n :count (string= (aref lst k) (aref lst j))))))", "language": "Lisp", "metadata": {"date": 1591101599, "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/s794683040.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s794683040", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (lst (concatenate 'vector (loop :repeat n :collect (sort (read-line) #'char<)))))\n (princ (loop :for k :from 1 :upto (1- n)\n :sum (loop :for j :from 0 :upto (1- k)\n :count (string= (aref lst k) (aref lst j))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2104, "memory_kb": 43364}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s850403507", "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\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 #'equalp :size n))\n (res 0))\n (dotimes (i n)\n (read-line-into line)\n (let ((histo (make-array 26 :element-type 'uint8 :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 (gethash histo table))\n (setf (gethash histo table) 1))))\n (loop for value 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": 1565485872, "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/s850403507.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s850403507", "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\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 #'equalp :size n))\n (res 0))\n (dotimes (i n)\n (read-line-into line)\n (let ((histo (make-array 26 :element-type 'uint8 :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 (gethash histo table))\n (setf (gethash histo table) 1))))\n (loop for value 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2788, "cpu_time_ms": 231, "memory_kb": 29536}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s945832351", "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;;; 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(declaim (ftype (function * (values (unsigned-byte 16) &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 ;; m := deg(u), n := deg(v)\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 ;; FIXME: Is it better to signal an error in non-coprime case?\n (inv (%mod-inverse (aref v n) modulus)))\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)) inv) modulus))\n (loop for j from (+ n k -1) downto k\n do (setf (aref u j)\n (mod (- (aref u j)\n (* (aref quot k) (aref v (- j k))))\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 (copied-base (make-array (+ p 1) :element-type 'uint16))\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 (dotimes (i (ceiling (+ p 1) 4))\n (setf (sb-kernel:%vector-raw-bits copied-base i)\n (sb-kernel:%vector-raw-bits base i)))\n (poly-floor! copied-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": 1565726663, "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/s945832351.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s945832351", "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;;; 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(declaim (ftype (function * (values (unsigned-byte 16) &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 ;; m := deg(u), n := deg(v)\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 ;; FIXME: Is it better to signal an error in non-coprime case?\n (inv (%mod-inverse (aref v n) modulus)))\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)) inv) modulus))\n (loop for j from (+ n k -1) downto k\n do (setf (aref u j)\n (mod (- (aref u j)\n (* (aref quot k) (aref v (- j k))))\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 (copied-base (make-array (+ p 1) :element-type 'uint16))\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 (dotimes (i (ceiling (+ p 1) 4))\n (setf (sb-kernel:%vector-raw-bits copied-base i)\n (sb-kernel:%vector-raw-bits base i)))\n (poly-floor! copied-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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8252, "cpu_time_ms": 817, "memory_kb": 37480}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s946934292", "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;; 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;;;\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 ;; 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 (with-buffered-stdout\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": 1565572606, "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/s946934292.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s946934292", "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;; 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;;;\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 ;; 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 (with-buffered-stdout\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4431, "cpu_time_ms": 718, "memory_kb": 26728}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s245532948", "group_id": "codeNet:p02951", "input_text": "(defparmeter a (read))\n(defparmeter b (read))\n(defparmeter c (read))\n\n(let ((value (- c (- a b))))\n (if (< value 0)\n (format t \"~a\" 0)\n (format t \"~a\" value)))", "language": "Lisp", "metadata": {"date": 1565057391, "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/s245532948.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s245532948", "user_id": "u425317134"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defparmeter a (read))\n(defparmeter b (read))\n(defparmeter c (read))\n\n(let ((value (- c (- a b))))\n (if (< value 0)\n (format t \"~a\" 0)\n (format t \"~a\" value)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 179, "cpu_time_ms": 108, "memory_kb": 10084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s848123463", "group_id": "codeNet:p02952", "input_text": "(defun digitsp (n r)\n (and (<= (expt 10 (- r 1)) n)\n (< n (expt 10 r))))\n\n(defun odd-digitsp (n)\n (or (digitsp n 1)\n (digitsp n 3)\n (digitsp n 5)))\n\n(let ((n (read)))\n (princ (loop :as i\n :below n\n :when (odd-digitsp (+ 1 i))\n :count i)))", "language": "Lisp", "metadata": {"date": 1587344927, "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/s848123463.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s848123463", "user_id": "u606976120"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun digitsp (n r)\n (and (<= (expt 10 (- r 1)) n)\n (< n (expt 10 r))))\n\n(defun odd-digitsp (n)\n (or (digitsp n 1)\n (digitsp n 3)\n (digitsp n 5)))\n\n(let ((n (read)))\n (princ (loop :as i\n :below n\n :when (odd-digitsp (+ 1 i))\n :count i)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 299, "cpu_time_ms": 179, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s341381196", "group_id": "codeNet:p02952", "input_text": "(defun solve (N)\n (let ((digits (length (write-to-string N))))\n (cond\n ((= digits 5) (- N 9090))\n ((= digits 4) 909)\n ((= digits 3) (- N 90) )\n ((= digits 2) 9)\n ((= digits 1) N)\n (t 90909))\n ))\n(princ (solve (read)))", "language": "Lisp", "metadata": {"date": 1584799357, "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/s341381196.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s341381196", "user_id": "u334552723"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun solve (N)\n (let ((digits (length (write-to-string N))))\n (cond\n ((= digits 5) (- N 9090))\n ((= digits 4) 909)\n ((= digits 3) (- N 90) )\n ((= digits 2) 9)\n ((= digits 1) N)\n (t 90909))\n ))\n(princ (solve (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 14, "memory_kb": 3556}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s871387766", "group_id": "codeNet:p02952", "input_text": "(let ((n (read))\n (ans 0))\n (loop for i from 1 upto n\n do (if (or (and (< 0 i) (< i 10)) (and (< 99 i) (< i 1000)) (and (< 9999 i) (< i 100000))) (incf ans)))\n (princ ans))", "language": "Lisp", "metadata": {"date": 1566095725, "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/s871387766.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s871387766", "user_id": "u994767958"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(let ((n (read))\n (ans 0))\n (loop for i from 1 upto n\n do (if (or (and (< 0 i) (< i 10)) (and (< 99 i) (< i 1000)) (and (< 9999 i) (< i 100000))) (incf ans)))\n (princ ans))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 122, "memory_kb": 10856}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s758744831", "group_id": "codeNet:p02952", "input_text": "(defparameter N (read))\n\n(defun get-order (num)\n (length (write-to-string num)))\n\n(defun max-order-num (num)\n (- num \n (1- (expt 10 \n (1- (get-order num))))))\n\n(defun count-up (num)\n (labels ((f (n ord)\n (if (<= ord (get-order n))\n 0\n (+ (* 9 (expt 10 (1- ord)))\n (f n (+ ord 2))))))\n (f num 1)))\n\n(format t \"~a\" (+ (max-order-num N)\n (count-up N)))\n ", "language": "Lisp", "metadata": {"date": 1565058962, "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/s758744831.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s758744831", "user_id": "u425317134"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defparameter N (read))\n\n(defun get-order (num)\n (length (write-to-string num)))\n\n(defun max-order-num (num)\n (- num \n (1- (expt 10 \n (1- (get-order num))))))\n\n(defun count-up (num)\n (labels ((f (n ord)\n (if (<= ord (get-order n))\n 0\n (+ (* 9 (expt 10 (1- ord)))\n (f n (+ ord 2))))))\n (f num 1)))\n\n(format t \"~a\" (+ (max-order-num N)\n (count-up N)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 482, "cpu_time_ms": 142, "memory_kb": 13412}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s872925665", "group_id": "codeNet:p02952", "input_text": "(let* ((n (read)))\n (cond ((<= 1 n 9) (princ n))\n ((<= 10 n 99) (princ 9))\n ((<= 100 n 999) (princ (+ 9 (- n 99))))\n ((<= 1000 n 9999) (princ 909))\n ((<= 10000 n 99999) (princ (+ 909 (- n 999))))\n (t (princ 90909))))", "language": "Lisp", "metadata": {"date": 1564967801, "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/s872925665.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s872925665", "user_id": "u610490393"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(let* ((n (read)))\n (cond ((<= 1 n 9) (princ n))\n ((<= 10 n 99) (princ 9))\n ((<= 100 n 999) (princ (+ 9 (- n 99))))\n ((<= 1000 n 9999) (princ 909))\n ((<= 10000 n 99999) (princ (+ 909 (- n 999))))\n (t (princ 90909))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 252, "cpu_time_ms": 119, "memory_kb": 11748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s719140147", "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 #.OPT\n ((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": 1565031894, "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/s719140147.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s719140147", "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 #.OPT\n ((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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4558, "cpu_time_ms": 521, "memory_kb": 29284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s284607186", "group_id": "codeNet:p02956", "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))\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;;; 2D range tree with fractional cascading\n;;;\n;;; build: O(nlog(n))\n;;; query: O(log(n))\n;;;\n\n;; TODO: map all the points in a given rectangle\n;; TODO: introduce abelian group\n\n(defstruct (ynode (:constructor make-ynode (xkeys ykeys lpointers rpointers))\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\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 #.OPT)\n (let* ((xkeys1 (%ynode-xkeys ynode1))\n (ykeys1 (%ynode-ykeys ynode1))\n (xkeys2 (%ynode-xkeys ynode2))\n (ykeys2 (%ynode-ykeys 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 (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 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 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 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 lpointers new-pos) pos1\n (aref rpointers new-pos) pos2\n pos2 (+ pos2 1)))\n (incf new-pos))\n (setf (aref lpointers new-len) len1\n (aref rpointers new-len) len2)\n (make-ynode new-xkeys new-ykeys lpointers rpointers)))\n\n(declaim (inline make-range-tree))\n(defun make-range-tree (points &key (xkey #'car) (ykey #'cdr))\n \"points := vector of poins\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 (xkeys (make-array 1 :element-type 'fixnum :initial-element x))\n (ykeys (make-array 1 :element-type 'fixnum :initial-element y)))\n (make-xnode x (make-ynode xkeys ykeys\n pointers-for-leaf\n pointers-for-leaf)\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 #.OPT\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(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+ 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 +mod+)\n\n(defun main ()\n (declare #.OPT\n (inline sort)\n (muffle-conditions style-warning))\n (let* ((n (read))\n (powers (make-array 200001 :element-type 'uint32))\n (xs (make-array n :element-type 'int32))\n (ys (make-array n :element-type 'int32))\n (ords (make-array n :element-type 'uint32))\n (res 0))\n (declare (uint32 n)\n (uint62 res)\n ((simple-array uint32 (*)) powers ords))\n ;; construct table of 2^n\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 (setf (aref ys i) (read-fixnum))\n (setf (aref ords i) i))\n (setf ords (sort ords (lambda (i j) (< (aref xs i) (aref xs j)))))\n (let ((rtree (make-range-tree ords\n :xkey (lambda (i) (aref xs i))\n :ykey (lambda (i) (aref ys i)))))\n ;; L R U D\n (incfmod res (mod* (- n 4) (- (aref powers n) 1)) +mod+)\n ;; LU LD RU RD\n (dotimes (i n)\n (let* ((x (aref xs i))\n (y (aref ys i))\n (ld (rt-count rtree nil nil x y))\n (lu (rt-count rtree nil (+ y 1) x nil))\n (rd (rt-count rtree (+ x 1) (+ y 1) nil nil))\n (ru (rt-count rtree (+ x 1) nil nil y)))\n (declare (int32 x y))\n (incf res (+ (aref powers ld) (aref powers lu) (aref powers rd) (aref powers ru))))))\n (println (mod res +mod+))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1577786510, "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/s284607186.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s284607186", "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))\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;;; 2D range tree with fractional cascading\n;;;\n;;; build: O(nlog(n))\n;;; query: O(log(n))\n;;;\n\n;; TODO: map all the points in a given rectangle\n;; TODO: introduce abelian group\n\n(defstruct (ynode (:constructor make-ynode (xkeys ykeys lpointers rpointers))\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\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 #.OPT)\n (let* ((xkeys1 (%ynode-xkeys ynode1))\n (ykeys1 (%ynode-ykeys ynode1))\n (xkeys2 (%ynode-xkeys ynode2))\n (ykeys2 (%ynode-ykeys 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 (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 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 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 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 lpointers new-pos) pos1\n (aref rpointers new-pos) pos2\n pos2 (+ pos2 1)))\n (incf new-pos))\n (setf (aref lpointers new-len) len1\n (aref rpointers new-len) len2)\n (make-ynode new-xkeys new-ykeys lpointers rpointers)))\n\n(declaim (inline make-range-tree))\n(defun make-range-tree (points &key (xkey #'car) (ykey #'cdr))\n \"points := vector of poins\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 (xkeys (make-array 1 :element-type 'fixnum :initial-element x))\n (ykeys (make-array 1 :element-type 'fixnum :initial-element y)))\n (make-xnode x (make-ynode xkeys ykeys\n pointers-for-leaf\n pointers-for-leaf)\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 #.OPT\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(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+ 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 +mod+)\n\n(defun main ()\n (declare #.OPT\n (inline sort)\n (muffle-conditions style-warning))\n (let* ((n (read))\n (powers (make-array 200001 :element-type 'uint32))\n (xs (make-array n :element-type 'int32))\n (ys (make-array n :element-type 'int32))\n (ords (make-array n :element-type 'uint32))\n (res 0))\n (declare (uint32 n)\n (uint62 res)\n ((simple-array uint32 (*)) powers ords))\n ;; construct table of 2^n\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 (setf (aref ys i) (read-fixnum))\n (setf (aref ords i) i))\n (setf ords (sort ords (lambda (i j) (< (aref xs i) (aref xs j)))))\n (let ((rtree (make-range-tree ords\n :xkey (lambda (i) (aref xs i))\n :ykey (lambda (i) (aref ys i)))))\n ;; L R U D\n (incfmod res (mod* (- n 4) (- (aref powers n) 1)) +mod+)\n ;; LU LD RU RD\n (dotimes (i n)\n (let* ((x (aref xs i))\n (y (aref ys i))\n (ld (rt-count rtree nil nil x y))\n (lu (rt-count rtree nil (+ y 1) x nil))\n (rd (rt-count rtree (+ x 1) (+ y 1) nil nil))\n (ru (rt-count rtree (+ x 1) nil nil y)))\n (declare (int32 x y))\n (incf res (+ (aref powers ld) (aref powers lu) (aref powers rd) (aref powers ru))))))\n (println (mod res +mod+))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13442, "cpu_time_ms": 1292, "memory_kb": 238564}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s525446547", "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;;;\n;;; 2D Range tree (unfinished)\n;;;\n;;; build: O(nlog^2(n))\n;;; query: O(log^2(n))\n;;;\n;;; Reference:\n;;; https://www.cse.wustl.edu/~taoju/cse546/lectures/Lecture21_rangequery_2d.pdf\n;;;\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\n left right)\n\n(defstruct (ynode (:constructor make-ynode (ykey left right &key (count 1)))\n (:conc-name %ynode-)\n (:copier nil))\n (ykey 0 :type fixnum)\n left\n right\n (count 1 :type (integer 0 #.most-positive-fixnum)))\n\n(declaim (inline ynode-count))\n(defun ynode-count (ynode)\n \"Returns the number of the elements.\"\n (if (null ynode)\n 0\n (%ynode-count ynode)))\n\n(declaim (inline ynode-update-count))\n(defun ynode-update-count (ynode)\n (setf (%ynode-count ynode)\n (+ 1\n (ynode-count (%ynode-left ynode))\n (ynode-count (%ynode-right ynode)))))\n\n;;\n;; Merging w.r.t. Y-axis in O(n) time:\n;; 1. transform two trees to two pathes (with copying);\n;; 2. merge the two pathes into a path (destructively);\n;; 3. transform the path to a tree (destructively);\n;;\n\n(defun %ynode-to-path (ynode)\n \"Returns a path that is equivalent to YNODE but in reverse order.\"\n (declare #.OPT\n (inline make-ynode))\n (let ((res nil))\n (labels ((recur (node)\n (when node\n (recur (%ynode-left node))\n (setq res (make-ynode (%ynode-ykey node) nil res))\n (recur (%ynode-right node)))))\n (recur ynode)\n res)))\n\n(declaim (inline %ynode-merge-path!))\n(defun %ynode-merge-path! (ypath1 ypath2)\n \"Destructively merges two pathes in reverse order.\"\n (let ((res nil))\n (macrolet ((%push (y)\n `(let ((rest (%ynode-right ,y)))\n (setf (%ynode-right ,y) res\n res ,y\n ,y rest))))\n (loop (unless ypath1\n (loop while ypath2 do (%push ypath2))\n (return))\n (unless ypath2\n (loop while ypath1 do (%push ypath1))\n (return))\n ;; I use only #'< here for abstraction in the future\n (if (< (%ynode-ykey ypath1) (%ynode-ykey ypath2))\n (%push ypath2)\n (%push ypath1)))\n res)))\n\n(defun %path-to-ynode! (ypath length)\n \"Destructively transforms a path to a balanced binary tree.\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) length))\n (let* ((max-depth (- (integer-length length) 1)))\n (macrolet ((%pop ()\n `(let ((rest (%ynode-right ypath))\n (first ypath))\n (setf (%ynode-right first) nil\n ypath rest)\n first)))\n (labels ((build (depth)\n (declare ((integer 0 #.most-positive-fixnum) depth))\n (when ypath\n (if (= depth max-depth)\n (%pop)\n (let ((left (build (+ 1 depth))))\n (if (null ypath)\n left\n (let* ((node (%pop))\n (right (build (+ 1 depth))))\n (setf (%ynode-left node) left)\n (setf (%ynode-right node) right)\n (ynode-update-count node)\n node)))))))\n (build 0)))))\n\n(declaim (inline ynode-merge))\n(defun ynode-merge (ynode1 ynode2)\n \"Merges two YNODEs non-destructively.\"\n (let* ((length (+ (ynode-count ynode1) (ynode-count ynode2))))\n (declare (fixnum length))\n (%path-to-ynode!\n (%ynode-merge-path! (%ynode-to-path ynode1)\n (%ynode-to-path ynode2))\n length)))\n\n(declaim (inline make-range-tree))\n(defun make-range-tree (size xs ys)\n \"XS, YS := (FUNCTION (FIXNUM) FIXNUM)\n\nPoints must be sorted w.r.t. lexicographical order and must not contain\nduplicate points. (Duplicate coordinates are allowed.) E.g. (-1, 3), (-1,\n4), (-1, 7) (0, 1) (0, 3) (2, -1) (2, 1)).\"\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= (- r l) 1)\n (let ((x (funcall xs l))\n (y (funcall ys l)))\n (make-xnode x (make-ynode y nil nil)\n nil nil))\n (let* ((mid (ash (+ l r) -1))\n (left (build l mid))\n (right (build mid r)))\n (make-xnode (funcall xs mid)\n (ynode-merge (%xnode-ynode left)\n (%xnode-ynode right))\n left right)))))\n (build 0 size)))\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 in the rectangle [x1, y1)*[x2, y2). A part or\nall of these coordinates can be NIL: then they are regarded as the negative or\npositive infinity.\"\n (declare #.OPT\n (fixnum x1 y1 x2 y2))\n (labels ((xrecur (xnode x1 x2)\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 (yrecur (%xnode-ynode xnode) y1 y2))\n (t\n (let ((xkey (%xnode-xkey xnode)))\n (if (<= x1 xkey)\n (if (< xkey x2)\n ;; XKEY is in [X1, X2)\n (if (xleaf-p xnode)\n (yrecur (%xnode-ynode xnode) y1 y2)\n (+ (xrecur (%xnode-left xnode) x1 +pos-inf+)\n (xrecur (%xnode-right xnode) +neg-inf+ x2)))\n ;; XKEY is in [X2, +inf)\n (xrecur (%xnode-left xnode) x1 x2))\n ;; XKEY is in (-inf, X1)\n (xrecur (%xnode-right xnode) x1 x2))))))\n (yrecur (ynode y1 y2)\n (declare ((or null ynode) ynode)\n (fixnum y1 y2)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((null ynode) 0)\n ((and (= y1 +neg-inf+) (= y2 +pos-inf+))\n (%ynode-count ynode))\n (t\n (let ((key (%ynode-ykey ynode)))\n (if (<= y1 key)\n (if (< key y2)\n (+ 1\n (yrecur (%ynode-left ynode) y1 +pos-inf+)\n (yrecur (%ynode-right ynode) +neg-inf+ y2))\n (yrecur (%ynode-left ynode) y1 y2))\n (yrecur (%ynode-right ynode) y1 y2)))))))\n ;; (declare (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) xrecur yrecur))\n (xrecur range-tree x1 x2)))\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+ 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 +mod+)\n\n(defun main ()\n (declare #.OPT\n (inline sort)\n (muffle-conditions style-warning))\n (let* ((n (read))\n (powers (make-array 200001 :element-type 'uint32))\n (xs (make-array n :element-type 'int32))\n (ys (make-array n :element-type 'int32))\n (ords (make-array n :element-type 'uint32))\n (res 0))\n (declare (uint32 n res)\n ((simple-array uint32 (*)) powers ords))\n ;; construct table of 2^n\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 (setf (aref ys i) (read-fixnum))\n (setf (aref ords i) i))\n (setf ords (sort ords (lambda (i j)\n (< (aref xs i) (aref xs j)))))\n (let ((rtree (make-range-tree n\n (lambda (i) (aref xs (aref ords i)))\n (lambda (i) (aref ys (aref ords i))))))\n ;; L R U D\n (incfmod res (mod* (- n 4) (- (aref powers n) 1)) +mod+)\n ;; LU LD RU RD\n (dotimes (i n)\n (let* ((x (aref xs i))\n (y (aref ys i))\n (ld (rt-count rtree +neg-inf+ +neg-inf+ x y))\n (lu (rt-count rtree +neg-inf+ (+ y 1) x +pos-inf+))\n (rd (rt-count rtree (+ x 1) (+ y 1) +pos-inf+ +pos-inf+))\n (ru (rt-count rtree (+ x 1) +neg-inf+ +pos-inf+ y)))\n (declare (int32 x y))\n (incfmod res (aref powers ld) +mod+)\n (incfmod res (aref powers lu) +mod+)\n (incfmod res (aref powers rd) +mod+)\n (incfmod res (aref powers ru) +mod+))))\n (println res)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565938418, "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/s525446547.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s525446547", "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;;;\n;;; 2D Range tree (unfinished)\n;;;\n;;; build: O(nlog^2(n))\n;;; query: O(log^2(n))\n;;;\n;;; Reference:\n;;; https://www.cse.wustl.edu/~taoju/cse546/lectures/Lecture21_rangequery_2d.pdf\n;;;\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\n left right)\n\n(defstruct (ynode (:constructor make-ynode (ykey left right &key (count 1)))\n (:conc-name %ynode-)\n (:copier nil))\n (ykey 0 :type fixnum)\n left\n right\n (count 1 :type (integer 0 #.most-positive-fixnum)))\n\n(declaim (inline ynode-count))\n(defun ynode-count (ynode)\n \"Returns the number of the elements.\"\n (if (null ynode)\n 0\n (%ynode-count ynode)))\n\n(declaim (inline ynode-update-count))\n(defun ynode-update-count (ynode)\n (setf (%ynode-count ynode)\n (+ 1\n (ynode-count (%ynode-left ynode))\n (ynode-count (%ynode-right ynode)))))\n\n;;\n;; Merging w.r.t. Y-axis in O(n) time:\n;; 1. transform two trees to two pathes (with copying);\n;; 2. merge the two pathes into a path (destructively);\n;; 3. transform the path to a tree (destructively);\n;;\n\n(defun %ynode-to-path (ynode)\n \"Returns a path that is equivalent to YNODE but in reverse order.\"\n (declare #.OPT\n (inline make-ynode))\n (let ((res nil))\n (labels ((recur (node)\n (when node\n (recur (%ynode-left node))\n (setq res (make-ynode (%ynode-ykey node) nil res))\n (recur (%ynode-right node)))))\n (recur ynode)\n res)))\n\n(declaim (inline %ynode-merge-path!))\n(defun %ynode-merge-path! (ypath1 ypath2)\n \"Destructively merges two pathes in reverse order.\"\n (let ((res nil))\n (macrolet ((%push (y)\n `(let ((rest (%ynode-right ,y)))\n (setf (%ynode-right ,y) res\n res ,y\n ,y rest))))\n (loop (unless ypath1\n (loop while ypath2 do (%push ypath2))\n (return))\n (unless ypath2\n (loop while ypath1 do (%push ypath1))\n (return))\n ;; I use only #'< here for abstraction in the future\n (if (< (%ynode-ykey ypath1) (%ynode-ykey ypath2))\n (%push ypath2)\n (%push ypath1)))\n res)))\n\n(defun %path-to-ynode! (ypath length)\n \"Destructively transforms a path to a balanced binary tree.\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) length))\n (let* ((max-depth (- (integer-length length) 1)))\n (macrolet ((%pop ()\n `(let ((rest (%ynode-right ypath))\n (first ypath))\n (setf (%ynode-right first) nil\n ypath rest)\n first)))\n (labels ((build (depth)\n (declare ((integer 0 #.most-positive-fixnum) depth))\n (when ypath\n (if (= depth max-depth)\n (%pop)\n (let ((left (build (+ 1 depth))))\n (if (null ypath)\n left\n (let* ((node (%pop))\n (right (build (+ 1 depth))))\n (setf (%ynode-left node) left)\n (setf (%ynode-right node) right)\n (ynode-update-count node)\n node)))))))\n (build 0)))))\n\n(declaim (inline ynode-merge))\n(defun ynode-merge (ynode1 ynode2)\n \"Merges two YNODEs non-destructively.\"\n (let* ((length (+ (ynode-count ynode1) (ynode-count ynode2))))\n (declare (fixnum length))\n (%path-to-ynode!\n (%ynode-merge-path! (%ynode-to-path ynode1)\n (%ynode-to-path ynode2))\n length)))\n\n(declaim (inline make-range-tree))\n(defun make-range-tree (size xs ys)\n \"XS, YS := (FUNCTION (FIXNUM) FIXNUM)\n\nPoints must be sorted w.r.t. lexicographical order and must not contain\nduplicate points. (Duplicate coordinates are allowed.) E.g. (-1, 3), (-1,\n4), (-1, 7) (0, 1) (0, 3) (2, -1) (2, 1)).\"\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= (- r l) 1)\n (let ((x (funcall xs l))\n (y (funcall ys l)))\n (make-xnode x (make-ynode y nil nil)\n nil nil))\n (let* ((mid (ash (+ l r) -1))\n (left (build l mid))\n (right (build mid r)))\n (make-xnode (funcall xs mid)\n (ynode-merge (%xnode-ynode left)\n (%xnode-ynode right))\n left right)))))\n (build 0 size)))\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 in the rectangle [x1, y1)*[x2, y2). A part or\nall of these coordinates can be NIL: then they are regarded as the negative or\npositive infinity.\"\n (declare #.OPT\n (fixnum x1 y1 x2 y2))\n (labels ((xrecur (xnode x1 x2)\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 (yrecur (%xnode-ynode xnode) y1 y2))\n (t\n (let ((xkey (%xnode-xkey xnode)))\n (if (<= x1 xkey)\n (if (< xkey x2)\n ;; XKEY is in [X1, X2)\n (if (xleaf-p xnode)\n (yrecur (%xnode-ynode xnode) y1 y2)\n (+ (xrecur (%xnode-left xnode) x1 +pos-inf+)\n (xrecur (%xnode-right xnode) +neg-inf+ x2)))\n ;; XKEY is in [X2, +inf)\n (xrecur (%xnode-left xnode) x1 x2))\n ;; XKEY is in (-inf, X1)\n (xrecur (%xnode-right xnode) x1 x2))))))\n (yrecur (ynode y1 y2)\n (declare ((or null ynode) ynode)\n (fixnum y1 y2)\n #+sbcl (values (integer 0 #.most-positive-fixnum)))\n (cond ((null ynode) 0)\n ((and (= y1 +neg-inf+) (= y2 +pos-inf+))\n (%ynode-count ynode))\n (t\n (let ((key (%ynode-ykey ynode)))\n (if (<= y1 key)\n (if (< key y2)\n (+ 1\n (yrecur (%ynode-left ynode) y1 +pos-inf+)\n (yrecur (%ynode-right ynode) +neg-inf+ y2))\n (yrecur (%ynode-left ynode) y1 y2))\n (yrecur (%ynode-right ynode) y1 y2)))))))\n ;; (declare (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) xrecur yrecur))\n (xrecur range-tree x1 x2)))\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+ 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 +mod+)\n\n(defun main ()\n (declare #.OPT\n (inline sort)\n (muffle-conditions style-warning))\n (let* ((n (read))\n (powers (make-array 200001 :element-type 'uint32))\n (xs (make-array n :element-type 'int32))\n (ys (make-array n :element-type 'int32))\n (ords (make-array n :element-type 'uint32))\n (res 0))\n (declare (uint32 n res)\n ((simple-array uint32 (*)) powers ords))\n ;; construct table of 2^n\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 (setf (aref ys i) (read-fixnum))\n (setf (aref ords i) i))\n (setf ords (sort ords (lambda (i j)\n (< (aref xs i) (aref xs j)))))\n (let ((rtree (make-range-tree n\n (lambda (i) (aref xs (aref ords i)))\n (lambda (i) (aref ys (aref ords i))))))\n ;; L R U D\n (incfmod res (mod* (- n 4) (- (aref powers n) 1)) +mod+)\n ;; LU LD RU RD\n (dotimes (i n)\n (let* ((x (aref xs i))\n (y (aref ys i))\n (ld (rt-count rtree +neg-inf+ +neg-inf+ x y))\n (lu (rt-count rtree +neg-inf+ (+ y 1) x +pos-inf+))\n (rd (rt-count rtree (+ x 1) (+ y 1) +pos-inf+ +pos-inf+))\n (ru (rt-count rtree (+ x 1) +neg-inf+ +pos-inf+ y)))\n (declare (int32 x y))\n (incfmod res (aref powers ld) +mod+)\n (incfmod res (aref powers lu) +mod+)\n (incfmod res (aref powers rd) +mod+)\n (incfmod res (aref powers ru) +mod+))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 12456, "cpu_time_ms": 2107, "memory_kb": 234344}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s135539206", "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(defstruct (xnode (:constructor make-xnode (key ynode left right))\n (:conc-name %xnode-)\n (:copier nil))\n (key 0 :type fixnum) ynode left right)\n\n(defstruct (ynode (:constructor make-ynode (key left right &optional (count 1)))\n (:conc-name %ynode-)\n (:copier nil))\n (key 0 :type fixnum)\n left\n right\n (count 1 :type (integer 0 #.most-positive-fixnum)))\n\n(declaim (inline ynode-count))\n(defun ynode-count (ynode)\n (if (null ynode)\n 0\n (%ynode-count ynode)))\n\n(declaim (inline ynode-update-count))\n(defun ynode-update-count (ynode)\n (setf (%ynode-count ynode)\n (+ 1\n (ynode-count (%ynode-left ynode))\n (ynode-count (%ynode-right ynode)))))\n\n(defun %ynode-to-path (ynode)\n \"Returns a path that is equivalent to YNODE but in reverse order.\"\n (declare #.OPT\n (inline make-ynode))\n (let ((res nil))\n (labels ((recur (node)\n (when node\n (recur (%ynode-left node))\n (setq res (make-ynode (%ynode-key node) nil res))\n (recur (%ynode-right node)))))\n (recur ynode)\n res)))\n\n(declaim (inline %ynode-merge-path!))\n(defun %ynode-merge-path! (ypath1 ypath2 &key (order #'<))\n \"Destructively merges two pathes in reverse order.\"\n (let ((res nil))\n (macrolet ((%push (y)\n `(setq res (make-ynode (%ynode-key ,y) nil res)\n ,y (%ynode-right ,y))))\n (loop (unless ypath1\n (loop while ypath2 do (%push ypath2))\n (return))\n (unless ypath2\n (loop while ypath1 do (%push ypath1))\n (return))\n (if (funcall order (%ynode-key ypath1) (%ynode-key ypath2))\n (%push ypath2)\n (%push ypath1)))\n res)))\n\n(defun %path-to-ynode! (ypath length)\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) length))\n (let* ((max-depth (- (integer-length length) 1)))\n (labels\n ((%pop ()\n (prog1 ypath\n (setq ypath (%ynode-right ypath))))\n (build (depth)\n (declare ((integer 0 #.most-positive-fixnum) depth))\n (when ypath\n (if (= depth max-depth)\n (let ((node (%pop)))\n (make-ynode (%ynode-key node) nil nil))\n (let ((left (build (+ 1 depth))))\n (if (null ypath)\n left\n (let* ((med (%pop))\n (right (build (+ 1 depth)))\n (node (make-ynode (%ynode-key med) left right)))\n (ynode-update-count node)\n node)))))))\n (build 0))))\n\n(declaim (inline ynode-merge))\n(defun ynode-merge (ynode1 ynode2 &key (order #'<))\n \"Merges two ynodes non-destructively.\"\n (let* ((length (+ (ynode-count ynode1) (ynode-count ynode2))))\n (%path-to-ynode!\n (%ynode-merge-path! (%ynode-to-path ynode1)\n (%ynode-to-path ynode2)\n :order order)\n (the fixnum length))))\n\n(defun make-range-tree (vector)\n (declare #.OPT\n ((simple-array list (*)) vector))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= (- r l) 1)\n (let ((cell (aref vector l)))\n (make-xnode (car cell)\n (make-ynode (cdr cell) nil nil)\n nil nil))\n (let* ((mid (ash (+ l r) -1))\n (med (car (aref vector mid)))\n (left (build l mid))\n (right (build mid r)))\n (make-xnode med\n (ynode-merge (%xnode-ynode left)\n (%xnode-ynode right))\n left right)))))\n (build 0 (length vector))))\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 in the rectangle [x1, y1)*[x2, y2)\"\n (declare #.OPT)\n (labels ((xrecur (xnode x1 x2)\n (declare ((or null xnode) xnode)\n (fixnum x1 x2)\n (values (integer 0 #.most-positive-fixnum)))\n (cond ((null xnode) 0)\n ((and (= x1 +neg-inf+) (= x2 +pos-inf+))\n (yrecur (%xnode-ynode xnode) y1 y2))\n (t\n (let ((key (%xnode-key xnode)))\n (if (<= x1 key)\n (if (< key x2)\n (if (xleaf-p xnode)\n (yrecur (%xnode-ynode xnode) y1 y2)\n (+ (xrecur (%xnode-left xnode) x1 +pos-inf+)\n (xrecur (%xnode-right xnode) +neg-inf+ x2)))\n (xrecur (%xnode-left xnode) x1 x2))\n (xrecur (%xnode-right xnode) x1 x2))))))\n (yrecur (ynode y1 y2)\n (declare ((or null ynode) ynode)\n (fixnum y1 y2)\n (values (integer 0 #.most-positive-fixnum)))\n (cond ((null ynode) 0)\n ((and (= y1 +neg-inf+) (= y2 +pos-inf+))\n (%ynode-count ynode))\n (t\n (let ((key (%ynode-key ynode)))\n (if (<= y1 key)\n (if (< key y2)\n (+ 1\n (yrecur (%ynode-left ynode) y1 +pos-inf+)\n (yrecur (%ynode-right ynode) +neg-inf+ y2))\n (yrecur (%ynode-left ynode) y1 y2))\n (yrecur (%ynode-right ynode) y1 y2)))))))\n (declare (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) xrecur yrecur))\n (xrecur range-tree x1 x2)))\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+ 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 (muffle-conditions style-warning))\n (let* ((n (read))\n (powers (make-array 200001 :element-type 'uint32))\n (points (make-array n :element-type 'list))\n (res 0))\n (declare (uint32 n res)\n ((simple-array list (*)) points)\n ((simple-array uint32 (*)) powers))\n ;; construct table of 2^n\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 (let ((x (read-fixnum))\n (y (read-fixnum)))\n (setf (aref points i) (cons x y))))\n (setf points (sort points (lambda (i j)\n (< (the int32 (car i))\n (the int32 (car j))))))\n (let ((rtree (make-range-tree points)))\n ;; L R U D\n (incfmod res (mod* (- n 4) (- (aref powers n) 1)) +mod+)\n ;; LU LD RU RD\n (dotimes (i n)\n (let* ((point (aref points i))\n (x (car point))\n (y (cdr point))\n (ld (rt-count rtree +neg-inf+ +neg-inf+ x y))\n (lu (rt-count rtree +neg-inf+ (+ y 1) x +pos-inf+))\n (rd (rt-count rtree (+ x 1) (+ y 1) +pos-inf+ +pos-inf+))\n (ru (rt-count rtree (+ x 1) +neg-inf+ +pos-inf+ y)))\n (declare (int32 x y))\n (incfmod res (aref powers ld) +mod+)\n (incfmod res (aref powers lu) +mod+)\n (incfmod res (aref powers rd) +mod+)\n (incfmod res (aref powers ru) +mod+))))\n (println res)))\n\n#-swank (main)\n\n", "language": "Lisp", "metadata": {"date": 1565483405, "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/s135539206.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s135539206", "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(defstruct (xnode (:constructor make-xnode (key ynode left right))\n (:conc-name %xnode-)\n (:copier nil))\n (key 0 :type fixnum) ynode left right)\n\n(defstruct (ynode (:constructor make-ynode (key left right &optional (count 1)))\n (:conc-name %ynode-)\n (:copier nil))\n (key 0 :type fixnum)\n left\n right\n (count 1 :type (integer 0 #.most-positive-fixnum)))\n\n(declaim (inline ynode-count))\n(defun ynode-count (ynode)\n (if (null ynode)\n 0\n (%ynode-count ynode)))\n\n(declaim (inline ynode-update-count))\n(defun ynode-update-count (ynode)\n (setf (%ynode-count ynode)\n (+ 1\n (ynode-count (%ynode-left ynode))\n (ynode-count (%ynode-right ynode)))))\n\n(defun %ynode-to-path (ynode)\n \"Returns a path that is equivalent to YNODE but in reverse order.\"\n (declare #.OPT\n (inline make-ynode))\n (let ((res nil))\n (labels ((recur (node)\n (when node\n (recur (%ynode-left node))\n (setq res (make-ynode (%ynode-key node) nil res))\n (recur (%ynode-right node)))))\n (recur ynode)\n res)))\n\n(declaim (inline %ynode-merge-path!))\n(defun %ynode-merge-path! (ypath1 ypath2 &key (order #'<))\n \"Destructively merges two pathes in reverse order.\"\n (let ((res nil))\n (macrolet ((%push (y)\n `(setq res (make-ynode (%ynode-key ,y) nil res)\n ,y (%ynode-right ,y))))\n (loop (unless ypath1\n (loop while ypath2 do (%push ypath2))\n (return))\n (unless ypath2\n (loop while ypath1 do (%push ypath1))\n (return))\n (if (funcall order (%ynode-key ypath1) (%ynode-key ypath2))\n (%push ypath2)\n (%push ypath1)))\n res)))\n\n(defun %path-to-ynode! (ypath length)\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) length))\n (let* ((max-depth (- (integer-length length) 1)))\n (labels\n ((%pop ()\n (prog1 ypath\n (setq ypath (%ynode-right ypath))))\n (build (depth)\n (declare ((integer 0 #.most-positive-fixnum) depth))\n (when ypath\n (if (= depth max-depth)\n (let ((node (%pop)))\n (make-ynode (%ynode-key node) nil nil))\n (let ((left (build (+ 1 depth))))\n (if (null ypath)\n left\n (let* ((med (%pop))\n (right (build (+ 1 depth)))\n (node (make-ynode (%ynode-key med) left right)))\n (ynode-update-count node)\n node)))))))\n (build 0))))\n\n(declaim (inline ynode-merge))\n(defun ynode-merge (ynode1 ynode2 &key (order #'<))\n \"Merges two ynodes non-destructively.\"\n (let* ((length (+ (ynode-count ynode1) (ynode-count ynode2))))\n (%path-to-ynode!\n (%ynode-merge-path! (%ynode-to-path ynode1)\n (%ynode-to-path ynode2)\n :order order)\n (the fixnum length))))\n\n(defun make-range-tree (vector)\n (declare #.OPT\n ((simple-array list (*)) vector))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= (- r l) 1)\n (let ((cell (aref vector l)))\n (make-xnode (car cell)\n (make-ynode (cdr cell) nil nil)\n nil nil))\n (let* ((mid (ash (+ l r) -1))\n (med (car (aref vector mid)))\n (left (build l mid))\n (right (build mid r)))\n (make-xnode med\n (ynode-merge (%xnode-ynode left)\n (%xnode-ynode right))\n left right)))))\n (build 0 (length vector))))\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 in the rectangle [x1, y1)*[x2, y2)\"\n (declare #.OPT)\n (labels ((xrecur (xnode x1 x2)\n (declare ((or null xnode) xnode)\n (fixnum x1 x2)\n (values (integer 0 #.most-positive-fixnum)))\n (cond ((null xnode) 0)\n ((and (= x1 +neg-inf+) (= x2 +pos-inf+))\n (yrecur (%xnode-ynode xnode) y1 y2))\n (t\n (let ((key (%xnode-key xnode)))\n (if (<= x1 key)\n (if (< key x2)\n (if (xleaf-p xnode)\n (yrecur (%xnode-ynode xnode) y1 y2)\n (+ (xrecur (%xnode-left xnode) x1 +pos-inf+)\n (xrecur (%xnode-right xnode) +neg-inf+ x2)))\n (xrecur (%xnode-left xnode) x1 x2))\n (xrecur (%xnode-right xnode) x1 x2))))))\n (yrecur (ynode y1 y2)\n (declare ((or null ynode) ynode)\n (fixnum y1 y2)\n (values (integer 0 #.most-positive-fixnum)))\n (cond ((null ynode) 0)\n ((and (= y1 +neg-inf+) (= y2 +pos-inf+))\n (%ynode-count ynode))\n (t\n (let ((key (%ynode-key ynode)))\n (if (<= y1 key)\n (if (< key y2)\n (+ 1\n (yrecur (%ynode-left ynode) y1 +pos-inf+)\n (yrecur (%ynode-right ynode) +neg-inf+ y2))\n (yrecur (%ynode-left ynode) y1 y2))\n (yrecur (%ynode-right ynode) y1 y2)))))))\n (declare (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) xrecur yrecur))\n (xrecur range-tree x1 x2)))\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+ 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 (muffle-conditions style-warning))\n (let* ((n (read))\n (powers (make-array 200001 :element-type 'uint32))\n (points (make-array n :element-type 'list))\n (res 0))\n (declare (uint32 n res)\n ((simple-array list (*)) points)\n ((simple-array uint32 (*)) powers))\n ;; construct table of 2^n\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 (let ((x (read-fixnum))\n (y (read-fixnum)))\n (setf (aref points i) (cons x y))))\n (setf points (sort points (lambda (i j)\n (< (the int32 (car i))\n (the int32 (car j))))))\n (let ((rtree (make-range-tree points)))\n ;; L R U D\n (incfmod res (mod* (- n 4) (- (aref powers n) 1)) +mod+)\n ;; LU LD RU RD\n (dotimes (i n)\n (let* ((point (aref points i))\n (x (car point))\n (y (cdr point))\n (ld (rt-count rtree +neg-inf+ +neg-inf+ x y))\n (lu (rt-count rtree +neg-inf+ (+ y 1) x +pos-inf+))\n (rd (rt-count rtree (+ x 1) (+ y 1) +pos-inf+ +pos-inf+))\n (ru (rt-count rtree (+ x 1) +neg-inf+ +pos-inf+ y)))\n (declare (int32 x y))\n (incfmod res (aref powers ld) +mod+)\n (incfmod res (aref powers lu) +mod+)\n (incfmod res (aref powers rd) +mod+)\n (incfmod res (aref powers ru) +mod+))))\n (println res)))\n\n#-swank (main)\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11019, "cpu_time_ms": 2109, "memory_kb": 357280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s197698296", "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(defstruct (xnode (:constructor make-xnode (key ynode left right))\n (:conc-name %xnode-)\n (:copier nil))\n (key 0 :type fixnum) ynode left right)\n\n(defstruct (ynode (:constructor make-ynode (key left right &optional (count 1)))\n (:conc-name %ynode-)\n (:copier nil))\n (key 0 :type fixnum)\n left\n right\n (count 1 :type (integer 0 #.most-positive-fixnum)))\n\n(declaim (inline ynode-count))\n(defun ynode-count (ynode)\n (if (null ynode)\n 0\n (%ynode-count ynode)))\n\n(declaim (inline ynode-update-count))\n(defun ynode-update-count (ynode)\n (setf (%ynode-count ynode)\n (+ 1\n (ynode-count (%ynode-left ynode))\n (ynode-count (%ynode-right ynode)))))\n\n(defun %ynode-to-path (ynode)\n \"Returns a path that is equivalent to YNODE but in reverse order.\"\n (declare (optimize (speed 3))\n (inline make-ynode))\n (let ((res nil))\n (labels ((recur (node)\n (when node\n (recur (%ynode-left node))\n (setq res (make-ynode (%ynode-key node) nil res))\n (recur (%ynode-right node)))))\n (recur ynode)\n res)))\n\n(declaim (inline %ynode-merge-path!))\n(defun %ynode-merge-path! (ypath1 ypath2 &key (order #'<))\n \"Destructively merges two pathes in reverse order.\"\n (let ((res nil))\n (macrolet ((%push (y)\n `(setq res (make-ynode (%ynode-key ,y) nil res)\n ,y (%ynode-right ,y))))\n (loop (unless ypath1\n (loop while ypath2 do (%push ypath2))\n (return))\n (unless ypath2\n (loop while ypath1 do (%push ypath1))\n (return))\n (if (funcall order (%ynode-key ypath1) (%ynode-key ypath2))\n (%push ypath2)\n (%push ypath1)))\n res)))\n\n(defun %path-to-ynode! (ypath length)\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) length))\n (let* ((max-depth (- (integer-length length) 1)))\n (labels\n ((%pop ()\n (prog1 ypath\n (setq ypath (%ynode-right ypath))))\n (build (depth)\n (declare ((integer 0 #.most-positive-fixnum) depth))\n (when ypath\n (if (= depth max-depth)\n (let ((node (%pop)))\n (make-ynode (%ynode-key node) nil nil))\n (let ((left (build (+ 1 depth))))\n (if (null ypath)\n left\n (let* ((med (%pop))\n (right (build (+ 1 depth)))\n (node (make-ynode (%ynode-key med) left right)))\n (ynode-update-count node)\n node)))))))\n (build 0))))\n\n(declaim (inline ynode-merge))\n(defun ynode-merge (ynode1 ynode2 &key (order #'<))\n \"Merges two ynodes non-destructively.\"\n (let* ((length (+ (ynode-count ynode1) (ynode-count ynode2))))\n (%path-to-ynode!\n (%ynode-merge-path! (%ynode-to-path ynode1)\n (%ynode-to-path ynode2)\n :order order)\n (the fixnum length))))\n\n(defun make-range-tree (vector)\n (declare (optimize (speed 3))\n ((simple-array list (*)) vector))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= (- r l) 1)\n (let ((cell (aref vector l)))\n (make-xnode (car cell)\n (make-ynode (cdr cell) nil nil)\n nil nil))\n (let* ((mid (ash (+ l r) -1))\n (med (car (aref vector mid)))\n (left (build l mid))\n (right (build mid r)))\n (make-xnode med\n (ynode-merge (%xnode-ynode left)\n (%xnode-ynode right))\n left right)))))\n (build 0 (length vector))))\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 in the rectangle [x1, y1)*[x2, y2)\"\n (declare (optimize (speed 3)))\n (labels ((xrecur (xnode x1 x2)\n (declare ((or null xnode) xnode)\n (fixnum x1 x2))\n (cond ((null xnode) 0)\n ((and (= x1 +neg-inf+) (= x2 +pos-inf+))\n (yrecur (%xnode-ynode xnode) y1 y2))\n (t\n (let ((key (%xnode-key xnode)))\n (if (<= x1 key)\n (if (< key x2)\n (if (xleaf-p xnode)\n (yrecur (%xnode-ynode xnode) y1 y2)\n (+ (xrecur (%xnode-left xnode) x1 +pos-inf+)\n (xrecur (%xnode-right xnode) +neg-inf+ x2)))\n (xrecur (%xnode-left xnode) x1 x2))\n (xrecur (%xnode-right xnode) x1 x2))))))\n (yrecur (ynode y1 y2)\n (declare ((or null ynode) ynode)\n (fixnum y1 y2))\n (cond ((null ynode) 0)\n ((and (= y1 +neg-inf+) (= y2 +pos-inf+))\n (%ynode-count ynode))\n (t\n (let ((key (%ynode-key ynode)))\n (if (<= y1 key)\n (if (< key y2)\n (+ 1\n (yrecur (%ynode-left ynode) y1 +pos-inf+)\n (yrecur (%ynode-right ynode) +neg-inf+ y2))\n (yrecur (%ynode-left ynode) y1 y2))\n (yrecur (%ynode-right ynode) y1 y2)))))))\n (declare (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) xrecur yrecur))\n (xrecur range-tree x1 x2)))\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+ 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 (powers (make-array 200001 :element-type 'uint32))\n (points (make-array n :element-type 'list))\n (res 0))\n (declare (uint32 n res)\n ((simple-array list (*)) points))\n ;; construct table of 2^n\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 (let ((x (read-fixnum))\n (y (read-fixnum)))\n (setf (aref points i) (cons x y))))\n (setf points (sort points (lambda (i j)\n (< (the int32 (car i))\n (the int32 (car j))))))\n (let ((rtree (make-range-tree points)))\n ;; L R U D\n (incfmod res (mod* (- n 4) (- (aref powers n) 1)) +mod+)\n ;; LU LD RU RD\n (dotimes (i n)\n (let* ((point (aref points i))\n (x (car point))\n (y (cdr point))\n (ld (rt-count rtree +neg-inf+ +neg-inf+ x y))\n (lu (rt-count rtree +neg-inf+ (+ y 1) x +pos-inf+))\n (rd (rt-count rtree (+ x 1) (+ y 1) +pos-inf+ +pos-inf+))\n (ru (rt-count rtree (+ x 1) +neg-inf+ +pos-inf+ y)))\n (declare (int32 x y))\n (incfmod res (aref powers ld) +mod+)\n (incfmod res (aref powers lu) +mod+)\n (incfmod res (aref powers rd) +mod+)\n (incfmod res (aref powers ru) +mod+))))\n (println res)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565482676, "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/s197698296.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s197698296", "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(defstruct (xnode (:constructor make-xnode (key ynode left right))\n (:conc-name %xnode-)\n (:copier nil))\n (key 0 :type fixnum) ynode left right)\n\n(defstruct (ynode (:constructor make-ynode (key left right &optional (count 1)))\n (:conc-name %ynode-)\n (:copier nil))\n (key 0 :type fixnum)\n left\n right\n (count 1 :type (integer 0 #.most-positive-fixnum)))\n\n(declaim (inline ynode-count))\n(defun ynode-count (ynode)\n (if (null ynode)\n 0\n (%ynode-count ynode)))\n\n(declaim (inline ynode-update-count))\n(defun ynode-update-count (ynode)\n (setf (%ynode-count ynode)\n (+ 1\n (ynode-count (%ynode-left ynode))\n (ynode-count (%ynode-right ynode)))))\n\n(defun %ynode-to-path (ynode)\n \"Returns a path that is equivalent to YNODE but in reverse order.\"\n (declare (optimize (speed 3))\n (inline make-ynode))\n (let ((res nil))\n (labels ((recur (node)\n (when node\n (recur (%ynode-left node))\n (setq res (make-ynode (%ynode-key node) nil res))\n (recur (%ynode-right node)))))\n (recur ynode)\n res)))\n\n(declaim (inline %ynode-merge-path!))\n(defun %ynode-merge-path! (ypath1 ypath2 &key (order #'<))\n \"Destructively merges two pathes in reverse order.\"\n (let ((res nil))\n (macrolet ((%push (y)\n `(setq res (make-ynode (%ynode-key ,y) nil res)\n ,y (%ynode-right ,y))))\n (loop (unless ypath1\n (loop while ypath2 do (%push ypath2))\n (return))\n (unless ypath2\n (loop while ypath1 do (%push ypath1))\n (return))\n (if (funcall order (%ynode-key ypath1) (%ynode-key ypath2))\n (%push ypath2)\n (%push ypath1)))\n res)))\n\n(defun %path-to-ynode! (ypath length)\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) length))\n (let* ((max-depth (- (integer-length length) 1)))\n (labels\n ((%pop ()\n (prog1 ypath\n (setq ypath (%ynode-right ypath))))\n (build (depth)\n (declare ((integer 0 #.most-positive-fixnum) depth))\n (when ypath\n (if (= depth max-depth)\n (let ((node (%pop)))\n (make-ynode (%ynode-key node) nil nil))\n (let ((left (build (+ 1 depth))))\n (if (null ypath)\n left\n (let* ((med (%pop))\n (right (build (+ 1 depth)))\n (node (make-ynode (%ynode-key med) left right)))\n (ynode-update-count node)\n node)))))))\n (build 0))))\n\n(declaim (inline ynode-merge))\n(defun ynode-merge (ynode1 ynode2 &key (order #'<))\n \"Merges two ynodes non-destructively.\"\n (let* ((length (+ (ynode-count ynode1) (ynode-count ynode2))))\n (%path-to-ynode!\n (%ynode-merge-path! (%ynode-to-path ynode1)\n (%ynode-to-path ynode2)\n :order order)\n (the fixnum length))))\n\n(defun make-range-tree (vector)\n (declare (optimize (speed 3))\n ((simple-array list (*)) vector))\n (labels ((build (l r)\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (if (= (- r l) 1)\n (let ((cell (aref vector l)))\n (make-xnode (car cell)\n (make-ynode (cdr cell) nil nil)\n nil nil))\n (let* ((mid (ash (+ l r) -1))\n (med (car (aref vector mid)))\n (left (build l mid))\n (right (build mid r)))\n (make-xnode med\n (ynode-merge (%xnode-ynode left)\n (%xnode-ynode right))\n left right)))))\n (build 0 (length vector))))\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 in the rectangle [x1, y1)*[x2, y2)\"\n (declare (optimize (speed 3)))\n (labels ((xrecur (xnode x1 x2)\n (declare ((or null xnode) xnode)\n (fixnum x1 x2))\n (cond ((null xnode) 0)\n ((and (= x1 +neg-inf+) (= x2 +pos-inf+))\n (yrecur (%xnode-ynode xnode) y1 y2))\n (t\n (let ((key (%xnode-key xnode)))\n (if (<= x1 key)\n (if (< key x2)\n (if (xleaf-p xnode)\n (yrecur (%xnode-ynode xnode) y1 y2)\n (+ (xrecur (%xnode-left xnode) x1 +pos-inf+)\n (xrecur (%xnode-right xnode) +neg-inf+ x2)))\n (xrecur (%xnode-left xnode) x1 x2))\n (xrecur (%xnode-right xnode) x1 x2))))))\n (yrecur (ynode y1 y2)\n (declare ((or null ynode) ynode)\n (fixnum y1 y2))\n (cond ((null ynode) 0)\n ((and (= y1 +neg-inf+) (= y2 +pos-inf+))\n (%ynode-count ynode))\n (t\n (let ((key (%ynode-key ynode)))\n (if (<= y1 key)\n (if (< key y2)\n (+ 1\n (yrecur (%ynode-left ynode) y1 +pos-inf+)\n (yrecur (%ynode-right ynode) +neg-inf+ y2))\n (yrecur (%ynode-left ynode) y1 y2))\n (yrecur (%ynode-right ynode) y1 y2)))))))\n (declare (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) xrecur yrecur))\n (xrecur range-tree x1 x2)))\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+ 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 (powers (make-array 200001 :element-type 'uint32))\n (points (make-array n :element-type 'list))\n (res 0))\n (declare (uint32 n res)\n ((simple-array list (*)) points))\n ;; construct table of 2^n\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 (let ((x (read-fixnum))\n (y (read-fixnum)))\n (setf (aref points i) (cons x y))))\n (setf points (sort points (lambda (i j)\n (< (the int32 (car i))\n (the int32 (car j))))))\n (let ((rtree (make-range-tree points)))\n ;; L R U D\n (incfmod res (mod* (- n 4) (- (aref powers n) 1)) +mod+)\n ;; LU LD RU RD\n (dotimes (i n)\n (let* ((point (aref points i))\n (x (car point))\n (y (cdr point))\n (ld (rt-count rtree +neg-inf+ +neg-inf+ x y))\n (lu (rt-count rtree +neg-inf+ (+ y 1) x +pos-inf+))\n (rd (rt-count rtree (+ x 1) (+ y 1) +pos-inf+ +pos-inf+))\n (ru (rt-count rtree (+ x 1) +neg-inf+ +pos-inf+ y)))\n (declare (int32 x y))\n (incfmod res (aref powers ld) +mod+)\n (incfmod res (aref powers lu) +mod+)\n (incfmod res (aref powers rd) +mod+)\n (incfmod res (aref powers ru) +mod+))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10853, "cpu_time_ms": 2109, "memory_kb": 353192}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s347072184", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (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 200001 :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 ;; construct table of 2^n\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 ;; L R U D\n (incfmod res (mod* (- n 4) (- (aref powers n) 1)) +mod+)\n ;; LU LD\n (let (treap)\n (loop for i from 0 below n\n do (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": 1565028117, "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/s347072184.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s347072184", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (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 200001 :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 ;; construct table of 2^n\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 ;; L R U D\n (incfmod res (mod* (- n 4) (- (aref powers n) 1)) +mod+)\n ;; LU LD\n (let (treap)\n (loop for i from 0 below n\n do (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10610, "cpu_time_ms": 700, "memory_kb": 66660}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s724655726", "group_id": "codeNet:p02957", "input_text": " (let ((a (read))\n (b (read)))\n (if (oddp (- a b))\n (princ \"IMPOSSIBLE\")\n (princ (/ (+ a b) 2))\n ))", "language": "Lisp", "metadata": {"date": 1584923752, "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/s724655726.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s724655726", "user_id": "u765865533"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": " (let ((a (read))\n (b (read)))\n (if (oddp (- a b))\n (princ \"IMPOSSIBLE\")\n (princ (/ (+ a b) 2))\n ))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 132, "cpu_time_ms": 367, "memory_kb": 12132}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s207462021", "group_id": "codeNet:p02958", "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* ((n (read))\n (dif 0))\n (dotimes (i n)\n (let ((p (read)))\n (unless (= p (+ i 1))\n (incf dif))))\n (write-line (if (<= dif 2)\n \"YES\"\n \"NO\"))))\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": 1564275851, "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/s207462021.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s207462021", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *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 (dif 0))\n (dotimes (i n)\n (let ((p (read)))\n (unless (= p (+ i 1))\n (incf dif))))\n (write-line (if (<= dif 2)\n \"YES\"\n \"NO\"))))\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 : 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3257, "cpu_time_ms": 214, "memory_kb": 15588}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s372018967", "group_id": "codeNet:p02960", "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;;; 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)\n\n(declaim (inline %))\n(defun % (x divisor)\n (if (>= x divisor) (- x divisor) x))\n\n(defun main ()\n (declare #.OPT\n (inline digit-char-p))\n (let* ((s (read-line))\n (n (length s)) \n (dp (make-array (list (+ n 1) 13) :element-type 'uint32 :initial-element 0)))\n (declare (simple-string s)\n (uint31 n))\n (setf (aref dp 0 0) 1)\n (do ((pos 0 (+ pos 1))\n (base 1 (mod (* base 10) 13)))\n ((= pos n))\n (declare (uint32 pos base))\n (if (char= #\\? (aref s (- n pos 1)))\n (dotimes (d 10)\n (let ((num (mod (* d base) 13)))\n (dotimes (m 13)\n (incfmod (aref dp (+ pos 1) (% (+ m num) 13))\n (aref dp pos m)\n +mod+))))\n (let* ((d (- (char-code (aref s (- n pos 1))) 48))\n (num (mod (* d base) 13)))\n (declare (uint8 d))\n (dotimes (m 13)\n (setf (aref dp (+ pos 1) (% (+ m num) 13))\n (aref dp pos m))))))\n (println (aref dp n 5))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1564289871, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02960.html", "problem_id": "p02960", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02960/input.txt", "sample_output_relpath": "derived/input_output/data/p02960/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02960/Lisp/s372018967.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s372018967", "user_id": "u352600849"}, "prompt_components": {"gold_output": "768\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;;; 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)\n\n(declaim (inline %))\n(defun % (x divisor)\n (if (>= x divisor) (- x divisor) x))\n\n(defun main ()\n (declare #.OPT\n (inline digit-char-p))\n (let* ((s (read-line))\n (n (length s)) \n (dp (make-array (list (+ n 1) 13) :element-type 'uint32 :initial-element 0)))\n (declare (simple-string s)\n (uint31 n))\n (setf (aref dp 0 0) 1)\n (do ((pos 0 (+ pos 1))\n (base 1 (mod (* base 10) 13)))\n ((= pos n))\n (declare (uint32 pos base))\n (if (char= #\\? (aref s (- n pos 1)))\n (dotimes (d 10)\n (let ((num (mod (* d base) 13)))\n (dotimes (m 13)\n (incfmod (aref dp (+ pos 1) (% (+ m num) 13))\n (aref dp pos m)\n +mod+))))\n (let* ((d (- (char-code (aref s (- n pos 1))) 48))\n (num (mod (* d base) 13)))\n (declare (uint8 d))\n (dotimes (m 13)\n (setf (aref dp (+ pos 1) (% (+ m num) 13))\n (aref dp pos m))))))\n (println (aref dp n 5))))\n\n#-swank (main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nGiven is a string S. Each character in S is either a digit (0, ..., 9) or ?.\n\nAmong the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.\n\nSince the answer can be enormous, print the count modulo 10^9+7.\n\nConstraints\n\nS is a string consisting of digits (0, ..., 9) and ?.\n\n1 \\leq |S| \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the number of integers satisfying the condition, modulo 10^9+7.\n\nSample Input 1\n\n??2??5\n\nSample Output 1\n\n768\n\nFor example, 482305, 002865, and 972665 satisfy the condition.\n\nSample Input 2\n\n?44\n\nSample Output 2\n\n1\n\nOnly 044 satisfies the condition.\n\nSample Input 3\n\n7?4\n\nSample Output 3\n\n0\n\nWe may not be able to produce an integer satisfying the condition.\n\nSample Input 4\n\n?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???\n\nSample Output 4\n\n153716888", "sample_input": "??2??5\n"}, "reference_outputs": ["768\n"], "source_document_id": "p02960", "source_text": "Score : 400 points\n\nProblem Statement\n\nGiven is a string S. Each character in S is either a digit (0, ..., 9) or ?.\n\nAmong the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.\n\nSince the answer can be enormous, print the count modulo 10^9+7.\n\nConstraints\n\nS is a string consisting of digits (0, ..., 9) and ?.\n\n1 \\leq |S| \\leq 10^5\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the number of integers satisfying the condition, modulo 10^9+7.\n\nSample Input 1\n\n??2??5\n\nSample Output 1\n\n768\n\nFor example, 482305, 002865, and 972665 satisfy the condition.\n\nSample Input 2\n\n?44\n\nSample Output 2\n\n1\n\nOnly 044 satisfies the condition.\n\nSample Input 3\n\n7?4\n\nSample Output 3\n\n0\n\nWe may not be able to produce an integer satisfying the condition.\n\nSample Input 4\n\n?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???\n\nSample Output 4\n\n153716888", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3219, "cpu_time_ms": 244, "memory_kb": 27236}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s595183083", "group_id": "codeNet:p02962", "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 (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 (32-bit)\n;;; Use 62-bit version instead. I leave it just for my reference.\n;;;\n\n(defstruct (rhash (:constructor %make-rhash (modulus base cumul powers)))\n (modulus 4294967291 :type (unsigned-byte 32))\n (base 2095716802 :type (unsigned-byte 32))\n (cumul nil :type (simple-array (unsigned-byte 32) (*)))\n (powers nil :type (simple-array (unsigned-byte 32) (*))))\n\n(declaim (inline make-rhash))\n(defun make-rhash (vector modulus &key (key #'char-code) base)\n \"Returns the table of rolling-hash of VECTOR modulo MODULUS. KEY is applied to\n each element of VECTOR prior to computing the hash value.\n\nMODULUS := unsigned 32-bit prime number\nBASE := 1 | 2 | ... | MODULUS - 1\nKEY := function returning FIXNUM\"\n (declare (vector vector)\n ((unsigned-byte 32) modulus)\n ((or null (unsigned-byte 32)) base)\n (function key))\n (assert (sb-int:positive-primep modulus))\n (let* ((base (or base (+ 1 (random (- modulus 1)))))\n (size (length vector))\n (cumul (make-array (+ 1 size) :element-type '(unsigned-byte 32)))\n (powers (make-array (+ 1 size) :element-type '(unsigned-byte 32))))\n (assert (<= 1 base (- modulus 1)))\n (setf (aref powers 0) 1)\n (dotimes (i size)\n (setf (aref powers (+ i 1))\n (mod (* (aref powers i) base) modulus))\n (let ((sum (+ (mod (* (aref cumul i) base) modulus)\n (mod (the fixnum (funcall key (aref vector i))) modulus))))\n (setf (aref cumul (+ i 1))\n (if (> sum modulus)\n (- sum modulus)\n sum))))\n (%make-rhash modulus base cumul powers)))\n\n(declaim (inline rhash-query)\n (ftype (function * (values (unsigned-byte 32) &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 (let ((cumul (rhash-cumul rhash))\n (powers (rhash-powers rhash))\n (modulus (rhash-modulus rhash)))\n (let ((res (+ (aref cumul r)\n (- modulus (mod (* (aref cumul l) (aref powers (- r l))) modulus)))))\n (if (> res modulus)\n (- res modulus)\n res))))\n\n(declaim (ftype (function * (values (unsigned-byte 32) &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 (vector vector))\n (let* ((mod (rhash-modulus rhash))\n (base (rhash-base rhash))\n (size (length vector))\n (result 0))\n (declare ((unsigned-byte 32) result))\n (dotimes (i size)\n ;; (2^32-1) * (2^32-1) + (2^32-1) < 2^64\n (setq result (mod (+ (* base result)\n (the (unsigned-byte 32)\n (mod (the fixnum (funcall key (aref vector i))) mod)))\n mod)))\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(defun forest-p (vec)\n (declare (vector vec))\n (let* ((n (length vec))\n (visited (make-array n :element-type 'bit :initial-element 0))\n (dp (make-array n :element-type 'int32 :initial-element -1))\n (res 0))\n (declare ((integer 0 #.most-positive-fixnum) res))\n (labels ((recur (pos)\n (dbg pos)\n (if (= -1 (aref dp pos))\n (if (= 1 (aref visited pos))\n (return-from forest-p nil)\n (setf (aref visited pos) 1\n (aref dp pos)\n (if (= -1 (aref vec pos))\n 0\n (+ 1 (recur (aref vec pos))))))\n (aref dp pos))))\n (dotimes (i n)\n (when (zerop (aref visited i))\n (setf res (max res (recur i)))))\n res)))\n\n(defun main ()\n (let* ((ss (coerce (the (simple-array character (*)) (read-line)) 'simple-base-string))\n (ts (coerce (the (simple-array character (*)) (read-line)) 'simple-base-string))\n (slen (length ss))\n (tlen (length ts))\n (snum (ceiling (+ slen tlen) slen))\n (total-len (* snum slen))\n (ex-ss (make-string total-len :element-type 'base-char)))\n (declare (uint31 slen tlen snum))\n #>snum\n (dotimes (i slen)\n (dotimes (lap snum)\n (setf (aref ex-ss (+ i (* lap slen)))\n (aref ss i))))\n (let* ((rhash (make-rhash ex-ss 4294967291 :base 2095716802))\n (tvalue (rhash-vector-hash rhash ts))\n (graph (make-array slen :element-type 'int32 :initial-element -1)))\n (dotimes (pos slen)\n (when (= tvalue (rhash-query rhash pos (+ pos tlen)))\n (setf (aref graph pos) (mod (+ pos tlen) slen))))\n (println (or (forest-p graph) -1)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1564351336, "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/s595183083.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s595183083", "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;; -*- 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 (32-bit)\n;;; Use 62-bit version instead. I leave it just for my reference.\n;;;\n\n(defstruct (rhash (:constructor %make-rhash (modulus base cumul powers)))\n (modulus 4294967291 :type (unsigned-byte 32))\n (base 2095716802 :type (unsigned-byte 32))\n (cumul nil :type (simple-array (unsigned-byte 32) (*)))\n (powers nil :type (simple-array (unsigned-byte 32) (*))))\n\n(declaim (inline make-rhash))\n(defun make-rhash (vector modulus &key (key #'char-code) base)\n \"Returns the table of rolling-hash of VECTOR modulo MODULUS. KEY is applied to\n each element of VECTOR prior to computing the hash value.\n\nMODULUS := unsigned 32-bit prime number\nBASE := 1 | 2 | ... | MODULUS - 1\nKEY := function returning FIXNUM\"\n (declare (vector vector)\n ((unsigned-byte 32) modulus)\n ((or null (unsigned-byte 32)) base)\n (function key))\n (assert (sb-int:positive-primep modulus))\n (let* ((base (or base (+ 1 (random (- modulus 1)))))\n (size (length vector))\n (cumul (make-array (+ 1 size) :element-type '(unsigned-byte 32)))\n (powers (make-array (+ 1 size) :element-type '(unsigned-byte 32))))\n (assert (<= 1 base (- modulus 1)))\n (setf (aref powers 0) 1)\n (dotimes (i size)\n (setf (aref powers (+ i 1))\n (mod (* (aref powers i) base) modulus))\n (let ((sum (+ (mod (* (aref cumul i) base) modulus)\n (mod (the fixnum (funcall key (aref vector i))) modulus))))\n (setf (aref cumul (+ i 1))\n (if (> sum modulus)\n (- sum modulus)\n sum))))\n (%make-rhash modulus base cumul powers)))\n\n(declaim (inline rhash-query)\n (ftype (function * (values (unsigned-byte 32) &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 (let ((cumul (rhash-cumul rhash))\n (powers (rhash-powers rhash))\n (modulus (rhash-modulus rhash)))\n (let ((res (+ (aref cumul r)\n (- modulus (mod (* (aref cumul l) (aref powers (- r l))) modulus)))))\n (if (> res modulus)\n (- res modulus)\n res))))\n\n(declaim (ftype (function * (values (unsigned-byte 32) &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 (vector vector))\n (let* ((mod (rhash-modulus rhash))\n (base (rhash-base rhash))\n (size (length vector))\n (result 0))\n (declare ((unsigned-byte 32) result))\n (dotimes (i size)\n ;; (2^32-1) * (2^32-1) + (2^32-1) < 2^64\n (setq result (mod (+ (* base result)\n (the (unsigned-byte 32)\n (mod (the fixnum (funcall key (aref vector i))) mod)))\n mod)))\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(defun forest-p (vec)\n (declare (vector vec))\n (let* ((n (length vec))\n (visited (make-array n :element-type 'bit :initial-element 0))\n (dp (make-array n :element-type 'int32 :initial-element -1))\n (res 0))\n (declare ((integer 0 #.most-positive-fixnum) res))\n (labels ((recur (pos)\n (dbg pos)\n (if (= -1 (aref dp pos))\n (if (= 1 (aref visited pos))\n (return-from forest-p nil)\n (setf (aref visited pos) 1\n (aref dp pos)\n (if (= -1 (aref vec pos))\n 0\n (+ 1 (recur (aref vec pos))))))\n (aref dp pos))))\n (dotimes (i n)\n (when (zerop (aref visited i))\n (setf res (max res (recur i)))))\n res)))\n\n(defun main ()\n (let* ((ss (coerce (the (simple-array character (*)) (read-line)) 'simple-base-string))\n (ts (coerce (the (simple-array character (*)) (read-line)) 'simple-base-string))\n (slen (length ss))\n (tlen (length ts))\n (snum (ceiling (+ slen tlen) slen))\n (total-len (* snum slen))\n (ex-ss (make-string total-len :element-type 'base-char)))\n (declare (uint31 slen tlen snum))\n #>snum\n (dotimes (i slen)\n (dotimes (lap snum)\n (setf (aref ex-ss (+ i (* lap slen)))\n (aref ss i))))\n (let* ((rhash (make-rhash ex-ss 4294967291 :base 2095716802))\n (tvalue (rhash-vector-hash rhash ts))\n (graph (make-array slen :element-type 'int32 :initial-element -1)))\n (dotimes (pos slen)\n (when (= tvalue (rhash-query rhash pos (+ pos tlen)))\n (setf (aref graph pos) (mod (+ pos tlen) slen))))\n (println (or (forest-p graph) -1)))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6515, "cpu_time_ms": 358, "memory_kb": 152636}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s337865868", "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 (32-bit)\n;;; Use 62-bit version instead. I leave it just for my reference.\n;;;\n\n(defstruct (rhash (:constructor %make-rhash (modulus base cumul powers)))\n (modulus 4294967291 :type (unsigned-byte 32))\n (base 2095716802 :type (unsigned-byte 32))\n (cumul nil :type (simple-array (unsigned-byte 32) (*)))\n (powers nil :type (simple-array (unsigned-byte 32) (*))))\n\n(declaim (inline make-rhash))\n(defun make-rhash (vector modulus &key (key #'char-code) base)\n \"Returns the table of rolling-hash of VECTOR modulo MODULUS. KEY is applied to\n each element of VECTOR prior to computing the hash value.\n\nMODULUS := unsigned 32-bit prime number\nBASE := 1 | 2 | ... | MODULUS - 1\nKEY := function returning FIXNUM\"\n (declare (vector vector)\n ((unsigned-byte 32) modulus)\n ((or null (unsigned-byte 32)) base)\n (function key))\n (assert (sb-int:positive-primep modulus))\n (let* ((base (or base (+ 1 (random (- modulus 1)))))\n (size (length vector))\n (cumul (make-array (+ 1 size) :element-type '(unsigned-byte 32)))\n (powers (make-array (+ 1 size) :element-type '(unsigned-byte 32))))\n (assert (<= 1 base (- modulus 1)))\n (setf (aref powers 0) 1)\n (dotimes (i size)\n (setf (aref powers (+ i 1))\n (mod (* (aref powers i) base) modulus))\n (let ((sum (+ (mod (* (aref cumul i) base) modulus)\n (mod (the fixnum (funcall key (aref vector i))) modulus))))\n (setf (aref cumul (+ i 1))\n (if (> sum modulus)\n (- sum modulus)\n sum))))\n (%make-rhash modulus base cumul powers)))\n\n(declaim (inline rhash-query)\n (ftype (function * (values (unsigned-byte 32) &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 ((cumul (rhash-cumul rhash))\n (powers (rhash-powers rhash))\n (modulus (rhash-modulus rhash)))\n (let ((res (+ (aref cumul r)\n (- modulus (mod (* (aref cumul l) (aref powers (- r l))) modulus)))))\n (if (> res modulus)\n (- res modulus)\n res))))\n\n(declaim (ftype (function * (values (unsigned-byte 32) &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 (vector vector))\n (let* ((mod (rhash-modulus rhash))\n (base (rhash-base rhash))\n (size (length vector))\n (result 0))\n (declare ((unsigned-byte 32) result))\n (dotimes (i size)\n ;; (2^32-1) * (2^32-1) + (2^32-1) < 2^64\n (setq result (mod (+ (* base result)\n (the (unsigned-byte 32)\n (mod (the fixnum (funcall key (aref vector i))) mod)))\n mod)))\n result))\n\n(declaim (inline rhash-get-lcp))\n(defun rhash-get-lcp (rhash1 start1 rhash2 start2)\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) start1 start2))\n (let ((max-length (min (- (length (rhash-cumul rhash1)) start1 1)\n (- (length (rhash-cumul 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", "language": "Lisp", "metadata": {"date": 1564285556, "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/s337865868.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s337865868", "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 (32-bit)\n;;; Use 62-bit version instead. I leave it just for my reference.\n;;;\n\n(defstruct (rhash (:constructor %make-rhash (modulus base cumul powers)))\n (modulus 4294967291 :type (unsigned-byte 32))\n (base 2095716802 :type (unsigned-byte 32))\n (cumul nil :type (simple-array (unsigned-byte 32) (*)))\n (powers nil :type (simple-array (unsigned-byte 32) (*))))\n\n(declaim (inline make-rhash))\n(defun make-rhash (vector modulus &key (key #'char-code) base)\n \"Returns the table of rolling-hash of VECTOR modulo MODULUS. KEY is applied to\n each element of VECTOR prior to computing the hash value.\n\nMODULUS := unsigned 32-bit prime number\nBASE := 1 | 2 | ... | MODULUS - 1\nKEY := function returning FIXNUM\"\n (declare (vector vector)\n ((unsigned-byte 32) modulus)\n ((or null (unsigned-byte 32)) base)\n (function key))\n (assert (sb-int:positive-primep modulus))\n (let* ((base (or base (+ 1 (random (- modulus 1)))))\n (size (length vector))\n (cumul (make-array (+ 1 size) :element-type '(unsigned-byte 32)))\n (powers (make-array (+ 1 size) :element-type '(unsigned-byte 32))))\n (assert (<= 1 base (- modulus 1)))\n (setf (aref powers 0) 1)\n (dotimes (i size)\n (setf (aref powers (+ i 1))\n (mod (* (aref powers i) base) modulus))\n (let ((sum (+ (mod (* (aref cumul i) base) modulus)\n (mod (the fixnum (funcall key (aref vector i))) modulus))))\n (setf (aref cumul (+ i 1))\n (if (> sum modulus)\n (- sum modulus)\n sum))))\n (%make-rhash modulus base cumul powers)))\n\n(declaim (inline rhash-query)\n (ftype (function * (values (unsigned-byte 32) &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 ((cumul (rhash-cumul rhash))\n (powers (rhash-powers rhash))\n (modulus (rhash-modulus rhash)))\n (let ((res (+ (aref cumul r)\n (- modulus (mod (* (aref cumul l) (aref powers (- r l))) modulus)))))\n (if (> res modulus)\n (- res modulus)\n res))))\n\n(declaim (ftype (function * (values (unsigned-byte 32) &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 (vector vector))\n (let* ((mod (rhash-modulus rhash))\n (base (rhash-base rhash))\n (size (length vector))\n (result 0))\n (declare ((unsigned-byte 32) result))\n (dotimes (i size)\n ;; (2^32-1) * (2^32-1) + (2^32-1) < 2^64\n (setq result (mod (+ (* base result)\n (the (unsigned-byte 32)\n (mod (the fixnum (funcall key (aref vector i))) mod)))\n mod)))\n result))\n\n(declaim (inline rhash-get-lcp))\n(defun rhash-get-lcp (rhash1 start1 rhash2 start2)\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) start1 start2))\n (let ((max-length (min (- (length (rhash-cumul rhash1)) start1 1)\n (- (length (rhash-cumul 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", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4475, "cpu_time_ms": 241, "memory_kb": 27236}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s877403775", "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 (31-bit)\n;;; Use 62-bit version instead. I leave it just for my reference.\n;;;\n\n(defstruct (rhash (:constructor %make-rhash (modulus cumul powers)))\n (modulus 1000000007 :type (unsigned-byte 32))\n (cumul nil :type (simple-array (unsigned-byte 32) (*)))\n (powers nil :type (simple-array (unsigned-byte 32) (*))))\n\n(declaim (inline make-rhash))\n(defun make-rhash (vector modulus &key (key #'char-code) base)\n \"Returns the table of rolling-hash of VECTOR modulo MODULUS. KEY is applied to\n each element of VECTOR prior to computing the hash value.\n\nMODULUS := unsigned 32-bit prime number\nBASE := 1 | 2 | ... | MODULUS - 1\nKEY := function returning FIXNUM\"\n (declare (vector vector)\n ((unsigned-byte 32) modulus)\n ((or null (unsigned-byte 32)) base)\n (function key))\n (assert (sb-int:positive-primep modulus))\n (let* ((base (or base (+ 1 (random (- modulus 1)))))\n (size (length vector))\n (cumul (make-array (+ 1 size) :element-type '(unsigned-byte 32)))\n (powers (make-array (+ 1 size) :element-type '(unsigned-byte 32))))\n (assert (<= 1 base (- modulus 1)))\n (setf (aref powers 0) 1)\n (dotimes (i size)\n (setf (aref powers (+ i 1))\n (mod (* (aref powers i) base) modulus))\n (let ((sum (+ (mod (* (aref cumul i) base) modulus)\n (mod (the fixnum (funcall key (aref vector i))) modulus))))\n (setf (aref cumul (+ i 1))\n (if (> sum modulus)\n (- sum modulus)\n sum))))\n (%make-rhash modulus cumul powers)))\n\n(declaim (inline rhash-query)\n (ftype (function * (values (unsigned-byte 32) &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 ((cumul (rhash-cumul rhash))\n (powers (rhash-powers rhash))\n (modulus (rhash-modulus rhash)))\n (let ((res (+ (aref cumul r)\n (- modulus (mod (* (aref cumul l) (aref powers (- r l))) modulus)))))\n (if (> res modulus)\n (- res modulus)\n res))))\n\n(declaim (inline rhash-concat))\n(defun rhash-concat (rhash hash1 hash2 hash2-length)\n (declare ((unsigned-byte 32) hash1 hash2)\n ((integer 0 #.most-positive-fixnum) hash2-length))\n (let* ((modulus (rhash-modulus rhash)))\n (mod (+ hash2\n (* hash1 (aref (rhash-powers rhash) hash2-length)))\n modulus)))\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* ((mod (rhash-modulus rhash))\n (base (aref (rhash-powers rhash) 1))\n (size (length vector))\n (lower 0))\n (declare ((unsigned-byte 32) lower))\n (dotimes (i size)\n (setf lower (+ (mod (* base lower) mod)\n (mod (the fixnum (funcall key (aref vector i))) mod))))\n lower))\n\n(defun rhash-get-lcp (rhash1 start1 rhash2 start2)\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) start1 start2))\n (assert (= (rhash-modulus rhash1) (rhash-modulus rhash2)))\n (assert (and (< start1 (length (rhash-cumul rhash1)))\n (< start2 (length (rhash-cumul rhash2)))))\n (let ((max-length (min (- (length (rhash-cumul rhash1)) start1 1)\n (- (length (rhash-cumul 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 3) 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 4294967291 :base 2095716802))\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 ((res 0)\n (rhash2 (make-rhash ex-ts 4294967291 :base 2095716802)))\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": 1564281276, "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/s877403775.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s877403775", "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 (31-bit)\n;;; Use 62-bit version instead. I leave it just for my reference.\n;;;\n\n(defstruct (rhash (:constructor %make-rhash (modulus cumul powers)))\n (modulus 1000000007 :type (unsigned-byte 32))\n (cumul nil :type (simple-array (unsigned-byte 32) (*)))\n (powers nil :type (simple-array (unsigned-byte 32) (*))))\n\n(declaim (inline make-rhash))\n(defun make-rhash (vector modulus &key (key #'char-code) base)\n \"Returns the table of rolling-hash of VECTOR modulo MODULUS. KEY is applied to\n each element of VECTOR prior to computing the hash value.\n\nMODULUS := unsigned 32-bit prime number\nBASE := 1 | 2 | ... | MODULUS - 1\nKEY := function returning FIXNUM\"\n (declare (vector vector)\n ((unsigned-byte 32) modulus)\n ((or null (unsigned-byte 32)) base)\n (function key))\n (assert (sb-int:positive-primep modulus))\n (let* ((base (or base (+ 1 (random (- modulus 1)))))\n (size (length vector))\n (cumul (make-array (+ 1 size) :element-type '(unsigned-byte 32)))\n (powers (make-array (+ 1 size) :element-type '(unsigned-byte 32))))\n (assert (<= 1 base (- modulus 1)))\n (setf (aref powers 0) 1)\n (dotimes (i size)\n (setf (aref powers (+ i 1))\n (mod (* (aref powers i) base) modulus))\n (let ((sum (+ (mod (* (aref cumul i) base) modulus)\n (mod (the fixnum (funcall key (aref vector i))) modulus))))\n (setf (aref cumul (+ i 1))\n (if (> sum modulus)\n (- sum modulus)\n sum))))\n (%make-rhash modulus cumul powers)))\n\n(declaim (inline rhash-query)\n (ftype (function * (values (unsigned-byte 32) &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 ((cumul (rhash-cumul rhash))\n (powers (rhash-powers rhash))\n (modulus (rhash-modulus rhash)))\n (let ((res (+ (aref cumul r)\n (- modulus (mod (* (aref cumul l) (aref powers (- r l))) modulus)))))\n (if (> res modulus)\n (- res modulus)\n res))))\n\n(declaim (inline rhash-concat))\n(defun rhash-concat (rhash hash1 hash2 hash2-length)\n (declare ((unsigned-byte 32) hash1 hash2)\n ((integer 0 #.most-positive-fixnum) hash2-length))\n (let* ((modulus (rhash-modulus rhash)))\n (mod (+ hash2\n (* hash1 (aref (rhash-powers rhash) hash2-length)))\n modulus)))\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* ((mod (rhash-modulus rhash))\n (base (aref (rhash-powers rhash) 1))\n (size (length vector))\n (lower 0))\n (declare ((unsigned-byte 32) lower))\n (dotimes (i size)\n (setf lower (+ (mod (* base lower) mod)\n (mod (the fixnum (funcall key (aref vector i))) mod))))\n lower))\n\n(defun rhash-get-lcp (rhash1 start1 rhash2 start2)\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) start1 start2))\n (assert (= (rhash-modulus rhash1) (rhash-modulus rhash2)))\n (assert (and (< start1 (length (rhash-cumul rhash1)))\n (< start2 (length (rhash-cumul rhash2)))))\n (let ((max-length (min (- (length (rhash-cumul rhash1)) start1 1)\n (- (length (rhash-cumul 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 3) 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 4294967291 :base 2095716802))\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 ((res 0)\n (rhash2 (make-rhash ex-ts 4294967291 :base 2095716802)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7720, "cpu_time_ms": 1866, "memory_kb": 72296}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s117885689", "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 (error 'simple-error)\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 ;; (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\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": 1564280297, "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/s117885689.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s117885689", "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 (error 'simple-error)\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 ;; (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\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 16979, "cpu_time_ms": 680, "memory_kb": 80616}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s824291424", "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 ((= 0 p) identity)\n ((= 1 p) x)\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 calc (x y)\n (dbg x y)\n (let* ((n (length x))\n (new (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (if (= n (aref x i))\n (setf (aref new i) 0)\n (setf (aref new i) (aref y (aref x i)))))\n #>new\n new))\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 1) :element-type 'uint32 :initial-element 0))\n (iden (make-array (+ n 1) :element-type 'uint32 :initial-element 0)))\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 (setf (aref perm n) 0)\n (dotimes (i n)\n (setf (aref perm i)\n (if (>= (aref perm i) n)\n (- (aref perm i) n)\n (aref perm i))))\n (let* ((final-perm\n (power perm (- k 1)\n (lambda (x y)\n (dbg 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 (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": 1563779990, "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/s824291424.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s824291424", "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 ((= 0 p) identity)\n ((= 1 p) x)\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 calc (x y)\n (dbg x y)\n (let* ((n (length x))\n (new (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (if (= n (aref x i))\n (setf (aref new i) 0)\n (setf (aref new i) (aref y (aref x i)))))\n #>new\n new))\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 1) :element-type 'uint32 :initial-element 0))\n (iden (make-array (+ n 1) :element-type 'uint32 :initial-element 0)))\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 (setf (aref perm n) 0)\n (dotimes (i n)\n (setf (aref perm i)\n (if (>= (aref perm i) n)\n (- (aref perm i) n)\n (aref perm i))))\n (let* ((final-perm\n (power perm (- k 1)\n (lambda (x y)\n (dbg 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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5669, "cpu_time_ms": 472, "memory_kb": 64996}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s938476487", "group_id": "codeNet:p02964", "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 (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 calc (x y)\n (dbg x y)\n (let* ((n (length x))\n (new (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (if (= n (aref x i))\n (setf (aref new i) 0)\n (setf (aref new i) (aref y (aref x i)))))\n #>new\n new))\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)\n (if (>= (aref perm i) n)\n (- (aref perm i) n)\n (aref perm i))))\n #>perm\n (let* ((final-perm\n (power perm (- k 1)\n (sb-int:named-lambda calc (x y)\n (cond ((eql iden x) (copy-seq y))\n ((eql iden y) (copy-seq x))\n (t\n (let ((new (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (if (= n (aref x i))\n (setf (aref new i) 0)\n (setf (aref new i) (aref y (aref x i)))))\n #>new\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": 1563775406, "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/s938476487.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s938476487", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2 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 (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 calc (x y)\n (dbg x y)\n (let* ((n (length x))\n (new (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (if (= n (aref x i))\n (setf (aref new i) 0)\n (setf (aref new i) (aref y (aref x i)))))\n #>new\n new))\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)\n (if (>= (aref perm i) n)\n (- (aref perm i) n)\n (aref perm i))))\n #>perm\n (let* ((final-perm\n (power perm (- k 1)\n (sb-int:named-lambda calc (x y)\n (cond ((eql iden x) (copy-seq y))\n ((eql iden y) (copy-seq x))\n (t\n (let ((new (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (if (= n (aref x i))\n (setf (aref new i) 0)\n (setf (aref new i) (aref y (aref x i)))))\n #>new\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5871, "cpu_time_ms": 520, "memory_kb": 64992}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s489199758", "group_id": "codeNet:p02965", "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(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+ 5010000)\n(defconstant +binom-mod+ +mod+)\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(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 stirling2))\n(defun stirling2 (n k)\n \"Returns the stirling number of the second kind S2(n, k). Time complexity is\nO(klog(n)).\"\n (declare ((integer 0 #.most-positive-fixnum) n k))\n (labels ((mod-power (base exp)\n (declare ((integer 0 #.most-positive-fixnum) base exp))\n (loop with res of-type (integer 0 #.most-positive-fixnum) = 1\n while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) +binom-mod+))\n do (setq base (mod (* base base) +binom-mod+)\n exp (ash exp -1))\n finally (return res))))\n (loop with result of-type fixnum = 0\n for i from 0 to k\n for delta = (mod (* (binom k i) (mod-power i n)) +binom-mod+)\n when (evenp (- k i))\n do (incf result delta)\n (when (>= result +binom-mod+)\n (decf result +binom-mod+))\n else\n do (decf result delta)\n (when (< result 0)\n (incf result +binom-mod+))\n finally (return (mod (* result (aref *fact-inv* k)) +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;;;\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(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;;;\n;;; Body\n;;;\n\n;; 和はちょうど3Mでなければならない\n;; 最大値は2M以下でなければならない\n;; 奇数セルはM個以下でなければならない\n\n(defun test (n m)\n (let ((xs (make-array n :element-type 'uint31 :initial-element 0))\n (table (make-hash-table :test #'equalp)))\n (sb-int:named-let dfs ((depth 0))\n (if (= depth m)\n (setf (gethash (copy-seq xs) table) t)\n (dotimes (i n)\n (dotimes (j n)\n (unless (= i j)\n (incf (aref xs i) 2)\n (incf (aref xs j) 1)\n (dfs (+ depth 1))\n (decf (aref xs i) 2)\n (decf (aref xs j) 1))))))\n table))\n\n(defun feasible-p (m xs)\n (and (= (reduce #'+ xs) (* 3 m))\n (<= (reduce #'max xs) (* 2 m))\n (<= (count-if #'oddp xs) m)))\n\n(defun test2 (n m)\n (let ((xs (make-array n :element-type 'uint31 :initial-element 0))\n (table (make-hash-table :test #'equalp)))\n (sb-int:named-let dfs ((pos 0) (sum 0))\n (if (= pos n)\n (when (feasible-p m xs)\n (setf (gethash (copy-seq xs) table) t))\n (loop for x from 0 to (- (* 3 m) sum)\n do (setf (aref xs pos) x)\n (dfs (+ pos 1) (+ sum x)))))\n table))\n\n(define-mod-operations +mod+)\n(declaim (inline multichoose))\n(defun multichoose (n k)\n (binom (+ n (- k 1)) (- k 1)))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (res (multichoose (* 3 m) n)))\n (declare (uint31 n m res))\n (loop for y from (+ 1 (* 2 m)) to (* 3 m)\n do (decfmod res (mod* n (multichoose (- (* 3 m) y) (- n 1)))))\n (loop for y from (+ m 1) to n\n when (evenp (- (* 3 m) y))\n do (decfmod res (mod* (binom n y)\n (multichoose (floor (- (* 3 m) y) 2) 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 #+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 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 2\n\"\n \"19\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n\"\n \"211428932\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100000 50000\n\"\n \"3463133\n\")))\n", "language": "Lisp", "metadata": {"date": 1596000070, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02965.html", "problem_id": "p02965", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02965/input.txt", "sample_output_relpath": "derived/input_output/data/p02965/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02965/Lisp/s489199758.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s489199758", "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(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+ 5010000)\n(defconstant +binom-mod+ +mod+)\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(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 stirling2))\n(defun stirling2 (n k)\n \"Returns the stirling number of the second kind S2(n, k). Time complexity is\nO(klog(n)).\"\n (declare ((integer 0 #.most-positive-fixnum) n k))\n (labels ((mod-power (base exp)\n (declare ((integer 0 #.most-positive-fixnum) base exp))\n (loop with res of-type (integer 0 #.most-positive-fixnum) = 1\n while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) +binom-mod+))\n do (setq base (mod (* base base) +binom-mod+)\n exp (ash exp -1))\n finally (return res))))\n (loop with result of-type fixnum = 0\n for i from 0 to k\n for delta = (mod (* (binom k i) (mod-power i n)) +binom-mod+)\n when (evenp (- k i))\n do (incf result delta)\n (when (>= result +binom-mod+)\n (decf result +binom-mod+))\n else\n do (decf result delta)\n (when (< result 0)\n (incf result +binom-mod+))\n finally (return (mod (* result (aref *fact-inv* k)) +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;;;\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(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;;;\n;;; Body\n;;;\n\n;; 和はちょうど3Mでなければならない\n;; 最大値は2M以下でなければならない\n;; 奇数セルはM個以下でなければならない\n\n(defun test (n m)\n (let ((xs (make-array n :element-type 'uint31 :initial-element 0))\n (table (make-hash-table :test #'equalp)))\n (sb-int:named-let dfs ((depth 0))\n (if (= depth m)\n (setf (gethash (copy-seq xs) table) t)\n (dotimes (i n)\n (dotimes (j n)\n (unless (= i j)\n (incf (aref xs i) 2)\n (incf (aref xs j) 1)\n (dfs (+ depth 1))\n (decf (aref xs i) 2)\n (decf (aref xs j) 1))))))\n table))\n\n(defun feasible-p (m xs)\n (and (= (reduce #'+ xs) (* 3 m))\n (<= (reduce #'max xs) (* 2 m))\n (<= (count-if #'oddp xs) m)))\n\n(defun test2 (n m)\n (let ((xs (make-array n :element-type 'uint31 :initial-element 0))\n (table (make-hash-table :test #'equalp)))\n (sb-int:named-let dfs ((pos 0) (sum 0))\n (if (= pos n)\n (when (feasible-p m xs)\n (setf (gethash (copy-seq xs) table) t))\n (loop for x from 0 to (- (* 3 m) sum)\n do (setf (aref xs pos) x)\n (dfs (+ pos 1) (+ sum x)))))\n table))\n\n(define-mod-operations +mod+)\n(declaim (inline multichoose))\n(defun multichoose (n k)\n (binom (+ n (- k 1)) (- k 1)))\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (res (multichoose (* 3 m) n)))\n (declare (uint31 n m res))\n (loop for y from (+ 1 (* 2 m)) to (* 3 m)\n do (decfmod res (mod* n (multichoose (- (* 3 m) y) (- n 1)))))\n (loop for y from (+ m 1) to n\n when (evenp (- (* 3 m) y))\n do (decfmod res (mod* (binom n y)\n (multichoose (floor (- (* 3 m) y) 2) 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 #+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 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 2\n\"\n \"19\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n\"\n \"211428932\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100000 50000\n\"\n \"3463133\n\")))\n", "problem_context": "Score : 900 points\n\nProblem Statement\n\nWe have a sequence of N integers: x=(x_0,x_1,\\cdots,x_{N-1}).\nInitially, x_i=0 for each i (0 \\leq i \\leq N-1).\n\nSnuke will perform the following operation exactly M times:\n\nChoose two distinct indices i, j (0 \\leq i,j \\leq N-1,\\ i \\neq j).\nThen, replace x_i with x_i+2 and x_j with x_j+1.\n\nFind the number of different sequences that can result after M operations.\nSince it can be enormous, compute the count modulo 998244353.\n\nConstraints\n\n2 \\leq N \\leq 10^6\n\n1 \\leq M \\leq 5 \\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 M\n\nOutput\n\nPrint the number of different sequences that can result after M operations, modulo 998244353.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n3\n\nAfter two operations, there are three possible outcomes:\n\nx=(2,4)\n\nx=(3,3)\n\nx=(4,2)\n\nFor example, x=(3,3) can result after the following sequence of operations:\n\nFirst, choose i=0,j=1, changing x from (0,0) to (2,1).\n\nSecond, choose i=1,j=0, changing x from (2,1) to (3,3).\n\nSample Input 2\n\n3 2\n\nSample Output 2\n\n19\n\nSample Input 3\n\n10 10\n\nSample Output 3\n\n211428932\n\nSample Input 4\n\n100000 50000\n\nSample Output 4\n\n3463133", "sample_input": "2 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p02965", "source_text": "Score : 900 points\n\nProblem Statement\n\nWe have a sequence of N integers: x=(x_0,x_1,\\cdots,x_{N-1}).\nInitially, x_i=0 for each i (0 \\leq i \\leq N-1).\n\nSnuke will perform the following operation exactly M times:\n\nChoose two distinct indices i, j (0 \\leq i,j \\leq N-1,\\ i \\neq j).\nThen, replace x_i with x_i+2 and x_j with x_j+1.\n\nFind the number of different sequences that can result after M operations.\nSince it can be enormous, compute the count modulo 998244353.\n\nConstraints\n\n2 \\leq N \\leq 10^6\n\n1 \\leq M \\leq 5 \\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 M\n\nOutput\n\nPrint the number of different sequences that can result after M operations, modulo 998244353.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n3\n\nAfter two operations, there are three possible outcomes:\n\nx=(2,4)\n\nx=(3,3)\n\nx=(4,2)\n\nFor example, x=(3,3) can result after the following sequence of operations:\n\nFirst, choose i=0,j=1, changing x from (0,0) to (2,1).\n\nSecond, choose i=1,j=0, changing x from (2,1) to (3,3).\n\nSample Input 2\n\n3 2\n\nSample Output 2\n\n19\n\nSample Input 3\n\n10 10\n\nSample Output 3\n\n211428932\n\nSample Input 4\n\n100000 50000\n\nSample Output 4\n\n3463133", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10438, "cpu_time_ms": 335, "memory_kb": 84060}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s277504933", "group_id": "codeNet:p02969", "input_text": "(let ((r (read)))\n (princ (* 3 r r)))", "language": "Lisp", "metadata": {"date": 1564320961, "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/s277504933.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s277504933", "user_id": "u100932207"}, "prompt_components": {"gold_output": "48\n", "input_to_evaluate": "(let ((r (read)))\n (princ (* 3 r r)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 120, "memory_kb": 9960}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s622436782", "group_id": "codeNet:p02970", "input_text": "(princ (ceiling (/ (read) (+ 1 (* 2 (read))))))", "language": "Lisp", "metadata": {"date": 1587609642, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s622436782.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s622436782", "user_id": "u606976120"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ (ceiling (/ (read) (+ 1 (* 2 (read))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 23, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s176326943", "group_id": "codeNet:p02971", "input_text": "(defun c2 ()\n (let* ((n (read))\n (l (loop for i below n collect (read)))\n (ll (loop for x in l collect x))\n (sl))\n (setf sl (sort ll #'>))\n (dolist (x l)\n (format t \"~a~%\"\n (if (= x (first sl))\n (second sl)\n (first sl))))))\n(c2)", "language": "Lisp", "metadata": {"date": 1564399594, "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/s176326943.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s176326943", "user_id": "u100932207"}, "prompt_components": {"gold_output": "4\n3\n4\n", "input_to_evaluate": "(defun c2 ()\n (let* ((n (read))\n (l (loop for i below n collect (read)))\n (ll (loop for x in l collect x))\n (sl))\n (setf sl (sort ll #'>))\n (dolist (x l)\n (format t \"~a~%\"\n (if (= x (first sl))\n (second sl)\n (first sl))))))\n(c2)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 972, "memory_kb": 61284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s965394289", "group_id": "codeNet:p02972", "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 (+ 1 n) :element-type 'bit))\n (res (make-array (+ 1 n) :element-type 'bit)))\n (loop for i from 1 to n do (setf (aref as i) (read-fixnum)))\n (loop for i from n downto 1\n do (loop with xor = (aref as i)\n for j from (* 2 i) to n by i\n do (setf xor (logxor xor (aref res j)))\n finally (setf (aref res i) xor)))\n (let ((count (count 1 res)))\n (println count)\n (loop for i from 1 to n\n when (= (aref res i) 1)\n do (println i)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563671928, "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/s965394289.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s965394289", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\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 (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 (+ 1 n) :element-type 'bit))\n (res (make-array (+ 1 n) :element-type 'bit)))\n (loop for i from 1 to n do (setf (aref as i) (read-fixnum)))\n (loop for i from n downto 1\n do (loop with xor = (aref as i)\n for j from (* 2 i) to n by i\n do (setf xor (logxor xor (aref res j)))\n finally (setf (aref res i) xor)))\n (let ((count (count 1 res)))\n (println count)\n (loop for i from 1 to n\n when (= (aref res i) 1)\n do (println i)))))\n\n#-swank (main)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2959, "cpu_time_ms": 403, "memory_kb": 27496}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s246521597", "group_id": "codeNet:p02973", "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(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (predicate #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nPREDICATE := strict order\n\nAnalogy of upper_bound of C++ or bisect_right of Python: Returns the smallest\nindex (or input) i that fulfills TARGET[i] > VALUE. TARGET must be monotonically\nnon-decreasing with respect to PREDICATE. This function returns END if VALUE\nexceeds TARGET[END-1]. Note that the range [START, END) is half-open. END must\nbe explicitly specified if TARGET is function. KEY is applied to each element of\nTARGET before comparison.\"\n (declare (function key predicate)\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 predicate value (funcall key (,accessor target left)))\n left\n ok)\n (if (funcall predicate 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *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 (dp (make-array n :element-type 'int32 :initial-element -1)))\n (dotimes (i n)\n (let* ((a (read-fixnum))\n (pos (bisect-right dp a :predicate #'>)))\n (setf (aref dp pos) a)))\n (println (count-if (complement #'minusp) dp))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563693564, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02973.html", "problem_id": "p02973", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02973/input.txt", "sample_output_relpath": "derived/input_output/data/p02973/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02973/Lisp/s246521597.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s246521597", "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(declaim (inline bisect-right))\n(defun bisect-right (target value &key (start 0) end (predicate #'<) (key #'identity))\n \"TARGET := vector | function (taking an integer argument)\nPREDICATE := strict order\n\nAnalogy of upper_bound of C++ or bisect_right of Python: Returns the smallest\nindex (or input) i that fulfills TARGET[i] > VALUE. TARGET must be monotonically\nnon-decreasing with respect to PREDICATE. This function returns END if VALUE\nexceeds TARGET[END-1]. Note that the range [START, END) is half-open. END must\nbe explicitly specified if TARGET is function. KEY is applied to each element of\nTARGET before comparison.\"\n (declare (function key predicate)\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 predicate value (funcall key (,accessor target left)))\n left\n ok)\n (if (funcall predicate 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *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 (dp (make-array n :element-type 'int32 :initial-element -1)))\n (dotimes (i n)\n (let* ((a (read-fixnum))\n (pos (bisect-right dp a :predicate #'>)))\n (setf (aref dp pos) a)))\n (println (count-if (complement #'minusp) dp))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou are given a sequence with N integers: A = \\{ A_1, A_2, \\cdots, A_N \\}.\nFor each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:\n\nIf A_i and A_j (i < j) are painted with the same color, A_i < A_j.\n\nFind the minimum number of colors required to satisfy the condition.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n0 \\leq A_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint the minimum number of colors required to satisfy the condition.\n\nSample Input 1\n\n5\n2\n1\n4\n5\n3\n\nSample Output 1\n\n2\n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1, 4, and 5 blue.\n\nSample Input 2\n\n4\n0\n0\n0\n0\n\nSample Output 2\n\n4\n\nWe have to paint all the integers with distinct colors.", "sample_input": "5\n2\n1\n4\n5\n3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02973", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou are given a sequence with N integers: A = \\{ A_1, A_2, \\cdots, A_N \\}.\nFor each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:\n\nIf A_i and A_j (i < j) are painted with the same color, A_i < A_j.\n\nFind the minimum number of colors required to satisfy the condition.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n0 \\leq A_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_1\n:\nA_N\n\nOutput\n\nPrint the minimum number of colors required to satisfy the condition.\n\nSample Input 1\n\n5\n2\n1\n4\n5\n3\n\nSample Output 1\n\n2\n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1, 4, and 5 blue.\n\nSample Input 2\n\n4\n0\n0\n0\n0\n\nSample Output 2\n\n4\n\nWe have to paint all the integers with distinct colors.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4658, "cpu_time_ms": 270, "memory_kb": 26468}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s092969144", "group_id": "codeNet:p02975", "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\t (lst0 (mapcar #'parse-integer (splitat #\\space (read-line nil nil))))\n\t (lst (cons (car lst0) (reverse lst0))))\n (labels ((rec (lst)\n\t\t\t\t(if (null (cdddr lst))\n\t\t\t\t t\n\t\t\t\t (if (= (cadr lst) (logxor (car lst) (caddr lst)))\n\t\t\t\t\t(rec (cdr lst))\n\t\t\t\t\t nil))))\n\t(format t \"~A~%\" (if (rec lst) \"Yes\" \"No\"))))", "language": "Lisp", "metadata": {"date": 1563155229, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02975.html", "problem_id": "p02975", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02975/input.txt", "sample_output_relpath": "derived/input_output/data/p02975/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02975/Lisp/s092969144.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s092969144", "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(let* ((n (parse-integer(read-line nil nil)))\n\t (lst0 (mapcar #'parse-integer (splitat #\\space (read-line nil nil))))\n\t (lst (cons (car lst0) (reverse lst0))))\n (labels ((rec (lst)\n\t\t\t\t(if (null (cdddr lst))\n\t\t\t\t t\n\t\t\t\t (if (= (cadr lst) (logxor (car lst) (caddr lst)))\n\t\t\t\t\t(rec (cdr lst))\n\t\t\t\t\t nil))))\n\t(format t \"~A~%\" (if (rec lst) \"Yes\" \"No\"))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke has N hats. The i-th hat has an integer a_i written on it.\n\nThere are N camels standing in a circle.\nSnuke will put one of his hats on each of these camels.\n\nIf there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print Yes; otherwise, print No.\n\nThe bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself.\n\nWhat is XOR?\n\nThe bitwise 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\n- When 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\n3 \\leq N \\leq 10^{5}\n\n0 \\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 answer.\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\nYes\n\nIf we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is Yes.\n\nSample Input 2\n\n4\n1 2 4 8\n\nSample Output 2\n\nNo\n\nThere is no such way to distribute the hats; the answer is No.", "sample_input": "3\n1 2 3\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02975", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke has N hats. The i-th hat has an integer a_i written on it.\n\nThere are N camels standing in a circle.\nSnuke will put one of his hats on each of these camels.\n\nIf there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print Yes; otherwise, print No.\n\nThe bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself.\n\nWhat is XOR?\n\nThe bitwise 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\n- When 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\n3 \\leq N \\leq 10^{5}\n\n0 \\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 answer.\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\nYes\n\nIf we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is Yes.\n\nSample Input 2\n\n4\n1 2 4 8\n\nSample Output 2\n\nNo\n\nThere is no such way to distribute the hats; the answer is No.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 606, "cpu_time_ms": 2105, "memory_kb": 107648}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s104268518", "group_id": "codeNet:p02981", "input_text": "(defun minfee (n a b)\n (if (< b (* n a))\n\t\tb\n\t\t(* n a)\n )\n)\n\n(format t \"~A~%\" (minfee (read) (read) (read)))", "language": "Lisp", "metadata": {"date": 1563037867, "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/s104268518.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s104268518", "user_id": "u606976120"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(defun minfee (n a b)\n (if (< b (* n a))\n\t\tb\n\t\t(* n a)\n )\n)\n\n(format t \"~A~%\" (minfee (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 9, "memory_kb": 3176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s363745918", "group_id": "codeNet:p02981", "input_text": "(let* ((n (read))\n (a (read))\n (b (read)))\n (princ (min (* a n) b )))", "language": "Lisp", "metadata": {"date": 1562547712, "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/s363745918.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s363745918", "user_id": "u610490393"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(let* ((n (read))\n (a (read))\n (b (read)))\n (princ (min (* a n) b )))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 161, "memory_kb": 11108}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s792738756", "group_id": "codeNet:p02986", "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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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(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;;; Mo's algorithm\n;;;\n\n(deftype mo-integer () 'uint31)\n\n(defstruct (mo (:constructor %make-mo\n (lefts rights order width))\n (:conc-name %mo-)\n (:copier nil)\n (:predicate nil))\n (lefts nil :type (simple-array mo-integer (*)))\n (rights nil :type (simple-array mo-integer (*)))\n (order nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (width 0 :type (integer 0 #.most-positive-fixnum))\n (index 0 :type (integer 0 #.most-positive-fixnum))\n (posl 0 :type mo-integer)\n (posr 0 :type mo-integer))\n\n(defun make-mo (bucket-width lefts rights)\n \"LEFTS := vector of indices of left-end of queries (inclusive)\nRIGHTS := vector of indices of right-end of queries (exclusive)\n\nBUCKET-WIDTH would be better set to N/sqrt(Q) where N is the width of the\nuniverse and Q is the number of queries.\"\n (declare (optimize (speed 3))\n ((simple-array mo-integer (*)) lefts rights)\n ((integer 0 #.most-positive-fixnum) bucket-width)\n (inline sort))\n (let* ((q (length lefts))\n (order (make-array q :element-type '(integer 0 #.most-positive-fixnum))))\n (assert (= q (length rights)))\n (dotimes (i q) (setf (aref order i) i))\n (setf order (sort order\n (lambda (x y)\n (if (= (floor (aref lefts x) bucket-width)\n (floor (aref lefts y) bucket-width))\n ;; Even-number [Odd-number] block is in ascending\n ;; [descending] order w.r.t. the right end.\n (if (evenp (floor (aref lefts x) bucket-width))\n (< (aref rights x) (aref rights y))\n (> (aref rights x) (aref rights y)))\n (< (aref lefts x) (aref lefts y))))))\n (%make-mo lefts rights order bucket-width)))\n\n(declaim (inline mo-get-current))\n(defun mo-get-current (mo)\n \"Returns the original index of the current (not yet proessed) query.\"\n (aref (%mo-order mo) (%mo-index mo)))\n\n(declaim (inline mo-get-previous))\n(defun mo-get-previous (mo)\n \"Returns the original index of the previous (= last processed) query. Returns\nthe initial index instead when no queries are processed yet.\"\n (aref (%mo-order mo) (max 0 (- (%mo-index mo) 1))))\n\n(declaim (inline mo-process4))\n(defun mo-process4 (mo extend-l extend-r shrink-l shrink-r)\n \"Processes the next query.\"\n (declare (function extend-l extend-r shrink-l shrink-r))\n (let* ((ord (mo-get-current mo))\n (left (aref (%mo-lefts mo) ord))\n (right (aref (%mo-rights mo) ord))\n (posl (%mo-posl mo))\n (posr (%mo-posr mo)))\n (declare ((integer 0 #.most-positive-fixnum) posl posr))\n (loop while (< left posl)\n do (decf posl)\n (funcall extend-l posl))\n (loop while (< posr right)\n do (funcall extend-r posr)\n (incf posr))\n (loop while (< posl left)\n do (funcall shrink-l posl)\n (incf posl))\n (loop while (< right posr)\n do (decf posr)\n (funcall shrink-r posr))\n (setf (%mo-posl mo) posl\n (%mo-posr mo) posr)\n (incf (%mo-index mo))))\n\n;; PAY ATTENTION TO THE STACK SIZE!\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(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 make-euler-tour (tree)\n (declare (vector tree))\n (let* ((n (length tree))\n (tour (make-array (- (* 2 n) 1)\n :element-type 'int32\n :initial-element 0))\n (left-edges (make-array (- (* 2 n) 1) :element-type 'int32 :initial-element -1))\n (right-edges (make-array (- (* 2 n) 1) :element-type 'int32 :initial-element -1))\n (pres (make-array n :element-type 'int32))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n #>tree\n (labels ((dfs (v parent)\n (setf (aref pres v) index)\n (loop for (child . edge-idx) in (aref tree v)\n unless (= child parent)\n do (setf (aref right-edges index) edge-idx)\n (incf index)\n (setf (aref tour index) child)\n (setf (aref left-edges index) edge-idx)\n (dfs child v)\n (setf (aref right-edges index) edge-idx)\n (incf index)\n (setf (aref tour index) v)\n (setf (aref left-edges index) edge-idx))))\n (unless (zerop n)\n (dfs 0 -1))\n (values tour pres left-edges right-edges))))\n\n(defun main ()\n (let* ((n (read))\n (q (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (cs (make-array n :element-type 'uint31 :initial-element 0))\n (ds (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1))\n (c (- (read-fixnum) 1))\n (d (read-fixnum)))\n (push (cons a i) (aref graph b))\n (push (cons b i) (aref graph a))\n (setf (aref cs i) c\n (aref ds i) d)))\n (multiple-value-bind (tour pres ledges redges) (make-euler-tour graph)\n (declare ((simple-array int32 (*)) tour pres ledges redges))\n (let ((xs (make-array q :element-type 'uint31 :initial-element 0))\n (ys (make-array q :element-type 'uint31 :initial-element 0))\n (us (make-array q :element-type 'uint31 :initial-element 0))\n (vs (make-array q :element-type 'uint31 :initial-element 0)))\n (dotimes (i q)\n (setf (aref xs i) (- (read-fixnum) 1)\n (aref ys i) (read-fixnum)\n (aref us i) (aref pres (- (read-fixnum) 1))\n (aref vs i) (+ 1 (aref pres (- (read-fixnum) 1)))))\n (dbg tour us vs)\n (let ((mo (make-mo 632 us vs))\n (res (make-array q :element-type 'uint31 :initial-element 0))\n (bits (make-array (- n 1) :element-type 'bit :initial-element 0))\n (nums (make-array n :element-type 'uint31 :initial-element 0))\n (dists (make-array n :element-type 'uint31 :initial-element 0))\n (dist 0))\n (declare (uint62 dist))\n (labels ((flip (eidx)\n (unless (= -1 eidx)\n (let ((c (aref cs eidx))\n (d (aref ds eidx)))\n (if (zerop (aref bits eidx))\n (progn\n (incf (aref nums c))\n (incf (aref dists c) d)\n (incf dist d))\n (progn\n (decf (aref nums c))\n (decf (aref dists c) d)\n (decf dist d)))\n (xorf (aref bits eidx) 1)))))\n (dotimes (_ q)\n (let ((qidx (mo-get-current mo)))\n (mo-process4\n mo\n (lambda (pos) (flip (aref redges pos)))\n (lambda (pos) (flip (aref ledges pos)))\n (lambda (pos) (flip (aref redges pos)))\n (lambda (pos) (flip (aref ledges pos))))\n (let* ((x (aref xs qidx))\n (y (aref ys qidx))\n (value (+ (- dist (aref dists x)) (* (aref nums x) y))))\n (setf (aref res qidx) 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 \"5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\"\n \"130\n200\n60\n\")))\n", "language": "Lisp", "metadata": {"date": 1593943599, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p02986.html", "problem_id": "p02986", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02986/input.txt", "sample_output_relpath": "derived/input_output/data/p02986/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02986/Lisp/s792738756.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s792738756", "user_id": "u352600849"}, "prompt_components": {"gold_output": "130\n200\n60\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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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(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;;; Mo's algorithm\n;;;\n\n(deftype mo-integer () 'uint31)\n\n(defstruct (mo (:constructor %make-mo\n (lefts rights order width))\n (:conc-name %mo-)\n (:copier nil)\n (:predicate nil))\n (lefts nil :type (simple-array mo-integer (*)))\n (rights nil :type (simple-array mo-integer (*)))\n (order nil :type (simple-array (integer 0 #.most-positive-fixnum) (*)))\n (width 0 :type (integer 0 #.most-positive-fixnum))\n (index 0 :type (integer 0 #.most-positive-fixnum))\n (posl 0 :type mo-integer)\n (posr 0 :type mo-integer))\n\n(defun make-mo (bucket-width lefts rights)\n \"LEFTS := vector of indices of left-end of queries (inclusive)\nRIGHTS := vector of indices of right-end of queries (exclusive)\n\nBUCKET-WIDTH would be better set to N/sqrt(Q) where N is the width of the\nuniverse and Q is the number of queries.\"\n (declare (optimize (speed 3))\n ((simple-array mo-integer (*)) lefts rights)\n ((integer 0 #.most-positive-fixnum) bucket-width)\n (inline sort))\n (let* ((q (length lefts))\n (order (make-array q :element-type '(integer 0 #.most-positive-fixnum))))\n (assert (= q (length rights)))\n (dotimes (i q) (setf (aref order i) i))\n (setf order (sort order\n (lambda (x y)\n (if (= (floor (aref lefts x) bucket-width)\n (floor (aref lefts y) bucket-width))\n ;; Even-number [Odd-number] block is in ascending\n ;; [descending] order w.r.t. the right end.\n (if (evenp (floor (aref lefts x) bucket-width))\n (< (aref rights x) (aref rights y))\n (> (aref rights x) (aref rights y)))\n (< (aref lefts x) (aref lefts y))))))\n (%make-mo lefts rights order bucket-width)))\n\n(declaim (inline mo-get-current))\n(defun mo-get-current (mo)\n \"Returns the original index of the current (not yet proessed) query.\"\n (aref (%mo-order mo) (%mo-index mo)))\n\n(declaim (inline mo-get-previous))\n(defun mo-get-previous (mo)\n \"Returns the original index of the previous (= last processed) query. Returns\nthe initial index instead when no queries are processed yet.\"\n (aref (%mo-order mo) (max 0 (- (%mo-index mo) 1))))\n\n(declaim (inline mo-process4))\n(defun mo-process4 (mo extend-l extend-r shrink-l shrink-r)\n \"Processes the next query.\"\n (declare (function extend-l extend-r shrink-l shrink-r))\n (let* ((ord (mo-get-current mo))\n (left (aref (%mo-lefts mo) ord))\n (right (aref (%mo-rights mo) ord))\n (posl (%mo-posl mo))\n (posr (%mo-posr mo)))\n (declare ((integer 0 #.most-positive-fixnum) posl posr))\n (loop while (< left posl)\n do (decf posl)\n (funcall extend-l posl))\n (loop while (< posr right)\n do (funcall extend-r posr)\n (incf posr))\n (loop while (< posl left)\n do (funcall shrink-l posl)\n (incf posl))\n (loop while (< right posr)\n do (decf posr)\n (funcall shrink-r posr))\n (setf (%mo-posl mo) posl\n (%mo-posr mo) posr)\n (incf (%mo-index mo))))\n\n;; PAY ATTENTION TO THE STACK SIZE!\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(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 make-euler-tour (tree)\n (declare (vector tree))\n (let* ((n (length tree))\n (tour (make-array (- (* 2 n) 1)\n :element-type 'int32\n :initial-element 0))\n (left-edges (make-array (- (* 2 n) 1) :element-type 'int32 :initial-element -1))\n (right-edges (make-array (- (* 2 n) 1) :element-type 'int32 :initial-element -1))\n (pres (make-array n :element-type 'int32))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n #>tree\n (labels ((dfs (v parent)\n (setf (aref pres v) index)\n (loop for (child . edge-idx) in (aref tree v)\n unless (= child parent)\n do (setf (aref right-edges index) edge-idx)\n (incf index)\n (setf (aref tour index) child)\n (setf (aref left-edges index) edge-idx)\n (dfs child v)\n (setf (aref right-edges index) edge-idx)\n (incf index)\n (setf (aref tour index) v)\n (setf (aref left-edges index) edge-idx))))\n (unless (zerop n)\n (dfs 0 -1))\n (values tour pres left-edges right-edges))))\n\n(defun main ()\n (let* ((n (read))\n (q (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (cs (make-array n :element-type 'uint31 :initial-element 0))\n (ds (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1))\n (c (- (read-fixnum) 1))\n (d (read-fixnum)))\n (push (cons a i) (aref graph b))\n (push (cons b i) (aref graph a))\n (setf (aref cs i) c\n (aref ds i) d)))\n (multiple-value-bind (tour pres ledges redges) (make-euler-tour graph)\n (declare ((simple-array int32 (*)) tour pres ledges redges))\n (let ((xs (make-array q :element-type 'uint31 :initial-element 0))\n (ys (make-array q :element-type 'uint31 :initial-element 0))\n (us (make-array q :element-type 'uint31 :initial-element 0))\n (vs (make-array q :element-type 'uint31 :initial-element 0)))\n (dotimes (i q)\n (setf (aref xs i) (- (read-fixnum) 1)\n (aref ys i) (read-fixnum)\n (aref us i) (aref pres (- (read-fixnum) 1))\n (aref vs i) (+ 1 (aref pres (- (read-fixnum) 1)))))\n (dbg tour us vs)\n (let ((mo (make-mo 632 us vs))\n (res (make-array q :element-type 'uint31 :initial-element 0))\n (bits (make-array (- n 1) :element-type 'bit :initial-element 0))\n (nums (make-array n :element-type 'uint31 :initial-element 0))\n (dists (make-array n :element-type 'uint31 :initial-element 0))\n (dist 0))\n (declare (uint62 dist))\n (labels ((flip (eidx)\n (unless (= -1 eidx)\n (let ((c (aref cs eidx))\n (d (aref ds eidx)))\n (if (zerop (aref bits eidx))\n (progn\n (incf (aref nums c))\n (incf (aref dists c) d)\n (incf dist d))\n (progn\n (decf (aref nums c))\n (decf (aref dists c) d)\n (decf dist d)))\n (xorf (aref bits eidx) 1)))))\n (dotimes (_ q)\n (let ((qidx (mo-get-current mo)))\n (mo-process4\n mo\n (lambda (pos) (flip (aref redges pos)))\n (lambda (pos) (flip (aref ledges pos)))\n (lambda (pos) (flip (aref redges pos)))\n (lambda (pos) (flip (aref ledges pos))))\n (let* ((x (aref xs qidx))\n (y (aref ys qidx))\n (value (+ (- dist (aref dists x)) (* (aref nums x) y))))\n (setf (aref res qidx) 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 \"5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\"\n \"130\n200\n60\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere is a tree with N vertices numbered 1 to N.\nThe i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively.\nHere the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors.\n\nAnswer the following Q queries:\n\nQuery j (1 \\leq j \\leq Q): assuming that the length of every edge whose color is x_j is changed to y_j, find the distance between Vertex u_j and Vertex v_j. (The changes of the lengths of edges do not affect the subsequent queries.)\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq a_i, b_i \\leq N\n\n1 \\leq c_i \\leq N-1\n\n1 \\leq d_i \\leq 10^4\n\n1 \\leq x_j \\leq N-1\n\n1 \\leq y_j \\leq 10^4\n\n1 \\leq u_j < v_j \\leq N\n\nThe given graph is a tree.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\na_1 b_1 c_1 d_1\n:\na_{N-1} b_{N-1} c_{N-1} d_{N-1}\nx_1 y_1 u_1 v_1\n:\nx_Q y_Q u_Q v_Q\n\nOutput\n\nPrint Q lines. The j-th line (1 \\leq j \\leq Q) should contain the answer to Query j.\n\nSample Input 1\n\n5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\nSample Output 1\n\n130\n200\n60\n\nThe graph in this input is as follows:\n\nHere the edges of Color 1 are shown as solid red lines, the edge of Color 2 is shown as a bold green line, and the edge of Color 4 is shown as a blue dashed line.\n\nQuery 1: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 4 is 100 + 30 = 130.\n\nQuery 2: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 5 is 100 + 100 = 200.\n\nQuery 3: Assuming that the length of every edge whose color is 3 is changed to 1000 (there is no such edge), the distance between Vertex 3 and Vertex 4 is 20 + 10 + 30 = 60. Note that the edges of Color 1 now have their original lengths.", "sample_input": "5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n"}, "reference_outputs": ["130\n200\n60\n"], "source_document_id": "p02986", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere is a tree with N vertices numbered 1 to N.\nThe i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively.\nHere the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors.\n\nAnswer the following Q queries:\n\nQuery j (1 \\leq j \\leq Q): assuming that the length of every edge whose color is x_j is changed to y_j, find the distance between Vertex u_j and Vertex v_j. (The changes of the lengths of edges do not affect the subsequent queries.)\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq a_i, b_i \\leq N\n\n1 \\leq c_i \\leq N-1\n\n1 \\leq d_i \\leq 10^4\n\n1 \\leq x_j \\leq N-1\n\n1 \\leq y_j \\leq 10^4\n\n1 \\leq u_j < v_j \\leq N\n\nThe given graph is a tree.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\na_1 b_1 c_1 d_1\n:\na_{N-1} b_{N-1} c_{N-1} d_{N-1}\nx_1 y_1 u_1 v_1\n:\nx_Q y_Q u_Q v_Q\n\nOutput\n\nPrint Q lines. The j-th line (1 \\leq j \\leq Q) should contain the answer to Query j.\n\nSample Input 1\n\n5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\nSample Output 1\n\n130\n200\n60\n\nThe graph in this input is as follows:\n\nHere the edges of Color 1 are shown as solid red lines, the edge of Color 2 is shown as a bold green line, and the edge of Color 4 is shown as a blue dashed line.\n\nQuery 1: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 4 is 100 + 30 = 130.\n\nQuery 2: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 5 is 100 + 100 = 200.\n\nQuery 3: Assuming that the length of every edge whose color is 3 is changed to 1000 (there is no such edge), the distance between Vertex 3 and Vertex 4 is 20 + 10 + 30 = 60. Note that the edges of Color 1 now have their original lengths.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 12917, "cpu_time_ms": 1642, "memory_kb": 52256}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s104084563", "group_id": "codeNet:p02986", "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;;; Lowest common ancestor of tree (or forest) by binary lifting\n;;; build: O(nlog(n))\n;;; query: O(log(n))\n;;;\n\n;; PAY ATTENTION TO THE STACK SIZE! THE CONSTRUCTOR DOES DFS.\n\n(deftype lca-vertex-number () '(signed-byte 32))\n\n(defstruct (lca-table\n (:constructor %make-lca-table\n (size\n &aux\n ;; requires 1 + log_2{size-1}\n (max-level (+ 1 (integer-length (- size 2))))\n (depths (make-array size\n :element-type 'lca-vertex-number\n :initial-element -1))\n (parents (make-array (list size max-level)\n :element-type 'lca-vertex-number))))\n (:conc-name lca-))\n (max-level nil :type (integer 0 #.most-positive-fixnum))\n (depths nil :type (simple-array lca-vertex-number (*)))\n (parents nil :type (simple-array lca-vertex-number (* *))))\n\n(defun make-lca-table (graph &key root (key #'identity))\n \"GRAPH := vector of adjacency lists\nROOT := null | non-negative fixnum\n\nIf ROOT is null, this function traverses each connected component of GRAPH from\nan arbitrarily picked vertex. Otherwise this function traverses GRAPH only from\nROOT; GRAPH must be tree in the latter case.\"\n (declare (optimize (speed 3))\n (vector graph)\n (function key)\n ((or null (integer 0 #.most-positive-fixnum)) root))\n (let* ((size (length graph))\n (lca-table (%make-lca-table size))\n (depths (lca-depths lca-table))\n (parents (lca-parents lca-table))\n (max-level (lca-max-level lca-table)))\n (labels ((dfs (v prev-v depth)\n (declare (lca-vertex-number v prev-v))\n (setf (aref depths v) depth)\n (setf (aref parents v 0) prev-v)\n (dolist (node (aref graph v))\n (let ((dest (funcall key node)))\n (declare (lca-vertex-number dest))\n (unless (= dest prev-v)\n (dfs dest v (+ 1 depth)))))))\n (if root\n (dfs root -1 0)\n (dotimes (v size)\n (when (= (aref depths v) -1)\n (dfs v -1 0))))\n (dotimes (k (- max-level 1))\n (dotimes (v size)\n (if (= -1 (aref parents v k))\n (setf (aref parents v (+ k 1)) -1)\n (setf (aref parents v (+ k 1))\n (aref parents (aref parents v k) k)))))\n lca-table)))\n\n(define-condition two-vertices-disconnected-error (error)\n ((lca-table :initarg :lca-table :accessor two-vertices-disconnected-error-lca-table)\n (vertex1 :initarg :vertex1 :accessor two-vertices-disconnected-error-vertex1)\n (vertex2 :initarg :vertex2 :accessor two-vertices-disconnected-error-vertex2))\n (:report\n (lambda (c s)\n (format s \"~W and ~W are disconnected on lca-table ~W\"\n (two-vertices-disconnected-error-vertex1 c)\n (two-vertices-disconnected-error-vertex2 c)\n (two-vertices-disconnected-error-lca-table c)))))\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional))\n lca-get-lca))\n(defun lca-get-lca (lca-table vertex1 vertex2)\n \"Returns the lowest common ancestor of the vertices VERTEX1 and VERTEX2.\"\n (declare (optimize (speed 3))\n ((and lca-vertex-number (integer 0)) vertex1 vertex2))\n (let* ((u vertex1)\n (v vertex2)\n (depths (lca-depths lca-table))\n (parents (lca-parents lca-table))\n (max-level (lca-max-level lca-table)))\n (declare (lca-vertex-number u v))\n ;; Ensures depth[u] <= depth[v]\n (when (> (aref depths u) (aref depths v))\n (rotatef u v))\n (dotimes (k max-level)\n (when (logbitp k (- (aref depths v) (aref depths u)))\n (setf v (aref parents v k))))\n (if (= u v)\n u\n (loop for k from (- max-level 1) downto 0\n unless (= (aref parents u k) (aref parents v k))\n do (setq u (aref parents u k)\n v (aref parents v k))\n finally (if (= (aref parents u 0) -1)\n (error 'two-vertices-disconnected-error\n :lca-table lca-table\n :vertex1 vertex1\n :vertex2 vertex2)\n (return (aref parents u 0)))))))\n\n(declaim (inline lca-distance))\n(defun lca-distance (lca-table u v)\n \"Returns the distance between two vertices U and V.\"\n (declare (optimize (speed 3)))\n (let ((depths (lca-depths lca-table))\n (lca (lca-get-lca lca-table u v)))\n (+ (- (aref depths u) (aref depths lca))\n (- (aref depths v) (aref depths lca)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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:\n;; - more sane handling of unbounded index\n;; - handy function for initialization\n;; - iteration; map\n;; - abstraction\n;; - printer\n\n(defconstant +persistent-vector-log+ 16)\n\n(declaim (inline %make-persistent-vector))\n(defstruct (persistent-vector (:constructor %make-persistent-vector ())\n (:conc-name %pv-))\n (value 0 :type fixnum)\n (children nil :type (or null (simple-vector #.+persistent-vector-log+))))\n\n(defun pv-assoc (pvector index value)\n (declare #.OPT\n ((or null persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (labels ((recur (pvector index)\n (declare ((or (integer 0 0) persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (let ((res (%make-persistent-vector)))\n (if (eql 0 pvector)\n (setf (%pv-children res)\n (make-array +persistent-vector-log+ :initial-element 0))\n (setf (%pv-children res) (copy-seq (%pv-children pvector))\n (%pv-value res) (%pv-value pvector)))\n (if (zerop index)\n (setf (%pv-value res) value)\n (setf (aref (%pv-children res) (mod index +persistent-vector-log+))\n (recur (aref (%pv-children res) (mod index +persistent-vector-log+))\n (floor index +persistent-vector-log+))))\n res)))\n (recur (or pvector 0) index)))\n\n(defun pv-ref (pvector index)\n (declare #.OPT\n ((or null persistent-vector) pvector))\n (labels ((recur (pvector index)\n (declare ((or (integer 0 0) persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (cond ((eql 0 pvector) 0)\n ((zerop index) (%pv-value pvector))\n (t (recur (aref (%pv-children pvector) (mod index +persistent-vector-log+))\n (floor index +persistent-vector-log+))))))\n (recur (or pvector 0) index)))\n\n(defun main ()\n (let* ((n (read))\n (q (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (wgraph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint31 n q))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1))\n (c (- (read-fixnum) 1))\n (d (read-fixnum)))\n (push a (aref graph b))\n (push b (aref graph a))\n (push (list* a c d) (aref wgraph b))\n (push (list* b c d) (aref wgraph a))))\n (let ((lca-table (make-lca-table graph))\n (dists (make-array n :element-type 'uint32))\n (ccounts (make-array n :initial-element nil))\n (cdists (make-array n :initial-element nil)))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (dolist (node (aref wgraph v))\n (destructuring-bind (child color . cost) node\n (unless (= child parent)\n (setf (aref dists child) (+ (aref dists v) cost))\n (setf (aref ccounts child)\n (pv-assoc (aref ccounts v)\n color\n (+ 1 (pv-ref (aref ccounts v) color))))\n (setf (aref cdists child)\n (pv-assoc (aref cdists v)\n color\n (+ cost (pv-ref (aref cdists v) color))))\n (dfs child v)))))\n (with-buffered-stdout\n (dotimes (_ q)\n (let* ((x (- (read-fixnum) 1))\n (y (read-fixnum))\n (u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (lca (lca-get-lca lca-table u v))\n (base (+ (aref dists u) (aref dists v) (* -2 (aref dists lca))))\n (ccount (+ (pv-ref (aref ccounts u) x)\n (pv-ref (aref ccounts v) x)\n (* -2 (pv-ref (aref ccounts lca) x))))\n (cdist (+ (pv-ref (aref cdists u) x)\n (pv-ref (aref cdists v) x)\n (* -2 (pv-ref (aref cdists lca) x)))))\n (dbg x y u v lca)\n (dbg base ccount cdist)\n (println (+ (- base cdist) (* ccount 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 \"5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\"\n \"130\n200\n60\n\")))\n", "language": "Lisp", "metadata": {"date": 1585380139, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02986.html", "problem_id": "p02986", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02986/input.txt", "sample_output_relpath": "derived/input_output/data/p02986/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02986/Lisp/s104084563.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s104084563", "user_id": "u352600849"}, "prompt_components": {"gold_output": "130\n200\n60\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;;; Lowest common ancestor of tree (or forest) by binary lifting\n;;; build: O(nlog(n))\n;;; query: O(log(n))\n;;;\n\n;; PAY ATTENTION TO THE STACK SIZE! THE CONSTRUCTOR DOES DFS.\n\n(deftype lca-vertex-number () '(signed-byte 32))\n\n(defstruct (lca-table\n (:constructor %make-lca-table\n (size\n &aux\n ;; requires 1 + log_2{size-1}\n (max-level (+ 1 (integer-length (- size 2))))\n (depths (make-array size\n :element-type 'lca-vertex-number\n :initial-element -1))\n (parents (make-array (list size max-level)\n :element-type 'lca-vertex-number))))\n (:conc-name lca-))\n (max-level nil :type (integer 0 #.most-positive-fixnum))\n (depths nil :type (simple-array lca-vertex-number (*)))\n (parents nil :type (simple-array lca-vertex-number (* *))))\n\n(defun make-lca-table (graph &key root (key #'identity))\n \"GRAPH := vector of adjacency lists\nROOT := null | non-negative fixnum\n\nIf ROOT is null, this function traverses each connected component of GRAPH from\nan arbitrarily picked vertex. Otherwise this function traverses GRAPH only from\nROOT; GRAPH must be tree in the latter case.\"\n (declare (optimize (speed 3))\n (vector graph)\n (function key)\n ((or null (integer 0 #.most-positive-fixnum)) root))\n (let* ((size (length graph))\n (lca-table (%make-lca-table size))\n (depths (lca-depths lca-table))\n (parents (lca-parents lca-table))\n (max-level (lca-max-level lca-table)))\n (labels ((dfs (v prev-v depth)\n (declare (lca-vertex-number v prev-v))\n (setf (aref depths v) depth)\n (setf (aref parents v 0) prev-v)\n (dolist (node (aref graph v))\n (let ((dest (funcall key node)))\n (declare (lca-vertex-number dest))\n (unless (= dest prev-v)\n (dfs dest v (+ 1 depth)))))))\n (if root\n (dfs root -1 0)\n (dotimes (v size)\n (when (= (aref depths v) -1)\n (dfs v -1 0))))\n (dotimes (k (- max-level 1))\n (dotimes (v size)\n (if (= -1 (aref parents v k))\n (setf (aref parents v (+ k 1)) -1)\n (setf (aref parents v (+ k 1))\n (aref parents (aref parents v k) k)))))\n lca-table)))\n\n(define-condition two-vertices-disconnected-error (error)\n ((lca-table :initarg :lca-table :accessor two-vertices-disconnected-error-lca-table)\n (vertex1 :initarg :vertex1 :accessor two-vertices-disconnected-error-vertex1)\n (vertex2 :initarg :vertex2 :accessor two-vertices-disconnected-error-vertex2))\n (:report\n (lambda (c s)\n (format s \"~W and ~W are disconnected on lca-table ~W\"\n (two-vertices-disconnected-error-vertex1 c)\n (two-vertices-disconnected-error-vertex2 c)\n (two-vertices-disconnected-error-lca-table c)))))\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional))\n lca-get-lca))\n(defun lca-get-lca (lca-table vertex1 vertex2)\n \"Returns the lowest common ancestor of the vertices VERTEX1 and VERTEX2.\"\n (declare (optimize (speed 3))\n ((and lca-vertex-number (integer 0)) vertex1 vertex2))\n (let* ((u vertex1)\n (v vertex2)\n (depths (lca-depths lca-table))\n (parents (lca-parents lca-table))\n (max-level (lca-max-level lca-table)))\n (declare (lca-vertex-number u v))\n ;; Ensures depth[u] <= depth[v]\n (when (> (aref depths u) (aref depths v))\n (rotatef u v))\n (dotimes (k max-level)\n (when (logbitp k (- (aref depths v) (aref depths u)))\n (setf v (aref parents v k))))\n (if (= u v)\n u\n (loop for k from (- max-level 1) downto 0\n unless (= (aref parents u k) (aref parents v k))\n do (setq u (aref parents u k)\n v (aref parents v k))\n finally (if (= (aref parents u 0) -1)\n (error 'two-vertices-disconnected-error\n :lca-table lca-table\n :vertex1 vertex1\n :vertex2 vertex2)\n (return (aref parents u 0)))))))\n\n(declaim (inline lca-distance))\n(defun lca-distance (lca-table u v)\n \"Returns the distance between two vertices U and V.\"\n (declare (optimize (speed 3)))\n (let ((depths (lca-depths lca-table))\n (lca (lca-get-lca lca-table u v)))\n (+ (- (aref depths u) (aref depths lca))\n (- (aref depths v) (aref depths lca)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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:\n;; - more sane handling of unbounded index\n;; - handy function for initialization\n;; - iteration; map\n;; - abstraction\n;; - printer\n\n(defconstant +persistent-vector-log+ 16)\n\n(declaim (inline %make-persistent-vector))\n(defstruct (persistent-vector (:constructor %make-persistent-vector ())\n (:conc-name %pv-))\n (value 0 :type fixnum)\n (children nil :type (or null (simple-vector #.+persistent-vector-log+))))\n\n(defun pv-assoc (pvector index value)\n (declare #.OPT\n ((or null persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (labels ((recur (pvector index)\n (declare ((or (integer 0 0) persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (let ((res (%make-persistent-vector)))\n (if (eql 0 pvector)\n (setf (%pv-children res)\n (make-array +persistent-vector-log+ :initial-element 0))\n (setf (%pv-children res) (copy-seq (%pv-children pvector))\n (%pv-value res) (%pv-value pvector)))\n (if (zerop index)\n (setf (%pv-value res) value)\n (setf (aref (%pv-children res) (mod index +persistent-vector-log+))\n (recur (aref (%pv-children res) (mod index +persistent-vector-log+))\n (floor index +persistent-vector-log+))))\n res)))\n (recur (or pvector 0) index)))\n\n(defun pv-ref (pvector index)\n (declare #.OPT\n ((or null persistent-vector) pvector))\n (labels ((recur (pvector index)\n (declare ((or (integer 0 0) persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (cond ((eql 0 pvector) 0)\n ((zerop index) (%pv-value pvector))\n (t (recur (aref (%pv-children pvector) (mod index +persistent-vector-log+))\n (floor index +persistent-vector-log+))))))\n (recur (or pvector 0) index)))\n\n(defun main ()\n (let* ((n (read))\n (q (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (wgraph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint31 n q))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1))\n (c (- (read-fixnum) 1))\n (d (read-fixnum)))\n (push a (aref graph b))\n (push b (aref graph a))\n (push (list* a c d) (aref wgraph b))\n (push (list* b c d) (aref wgraph a))))\n (let ((lca-table (make-lca-table graph))\n (dists (make-array n :element-type 'uint32))\n (ccounts (make-array n :initial-element nil))\n (cdists (make-array n :initial-element nil)))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (dolist (node (aref wgraph v))\n (destructuring-bind (child color . cost) node\n (unless (= child parent)\n (setf (aref dists child) (+ (aref dists v) cost))\n (setf (aref ccounts child)\n (pv-assoc (aref ccounts v)\n color\n (+ 1 (pv-ref (aref ccounts v) color))))\n (setf (aref cdists child)\n (pv-assoc (aref cdists v)\n color\n (+ cost (pv-ref (aref cdists v) color))))\n (dfs child v)))))\n (with-buffered-stdout\n (dotimes (_ q)\n (let* ((x (- (read-fixnum) 1))\n (y (read-fixnum))\n (u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (lca (lca-get-lca lca-table u v))\n (base (+ (aref dists u) (aref dists v) (* -2 (aref dists lca))))\n (ccount (+ (pv-ref (aref ccounts u) x)\n (pv-ref (aref ccounts v) x)\n (* -2 (pv-ref (aref ccounts lca) x))))\n (cdist (+ (pv-ref (aref cdists u) x)\n (pv-ref (aref cdists v) x)\n (* -2 (pv-ref (aref cdists lca) x)))))\n (dbg x y u v lca)\n (dbg base ccount cdist)\n (println (+ (- base cdist) (* ccount 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 \"5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\"\n \"130\n200\n60\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere is a tree with N vertices numbered 1 to N.\nThe i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively.\nHere the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors.\n\nAnswer the following Q queries:\n\nQuery j (1 \\leq j \\leq Q): assuming that the length of every edge whose color is x_j is changed to y_j, find the distance between Vertex u_j and Vertex v_j. (The changes of the lengths of edges do not affect the subsequent queries.)\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq a_i, b_i \\leq N\n\n1 \\leq c_i \\leq N-1\n\n1 \\leq d_i \\leq 10^4\n\n1 \\leq x_j \\leq N-1\n\n1 \\leq y_j \\leq 10^4\n\n1 \\leq u_j < v_j \\leq N\n\nThe given graph is a tree.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\na_1 b_1 c_1 d_1\n:\na_{N-1} b_{N-1} c_{N-1} d_{N-1}\nx_1 y_1 u_1 v_1\n:\nx_Q y_Q u_Q v_Q\n\nOutput\n\nPrint Q lines. The j-th line (1 \\leq j \\leq Q) should contain the answer to Query j.\n\nSample Input 1\n\n5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\nSample Output 1\n\n130\n200\n60\n\nThe graph in this input is as follows:\n\nHere the edges of Color 1 are shown as solid red lines, the edge of Color 2 is shown as a bold green line, and the edge of Color 4 is shown as a blue dashed line.\n\nQuery 1: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 4 is 100 + 30 = 130.\n\nQuery 2: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 5 is 100 + 100 = 200.\n\nQuery 3: Assuming that the length of every edge whose color is 3 is changed to 1000 (there is no such edge), the distance between Vertex 3 and Vertex 4 is 20 + 10 + 30 = 60. Note that the edges of Color 1 now have their original lengths.", "sample_input": "5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n"}, "reference_outputs": ["130\n200\n60\n"], "source_document_id": "p02986", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere is a tree with N vertices numbered 1 to N.\nThe i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively.\nHere the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors.\n\nAnswer the following Q queries:\n\nQuery j (1 \\leq j \\leq Q): assuming that the length of every edge whose color is x_j is changed to y_j, find the distance between Vertex u_j and Vertex v_j. (The changes of the lengths of edges do not affect the subsequent queries.)\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq a_i, b_i \\leq N\n\n1 \\leq c_i \\leq N-1\n\n1 \\leq d_i \\leq 10^4\n\n1 \\leq x_j \\leq N-1\n\n1 \\leq y_j \\leq 10^4\n\n1 \\leq u_j < v_j \\leq N\n\nThe given graph is a tree.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\na_1 b_1 c_1 d_1\n:\na_{N-1} b_{N-1} c_{N-1} d_{N-1}\nx_1 y_1 u_1 v_1\n:\nx_Q y_Q u_Q v_Q\n\nOutput\n\nPrint Q lines. The j-th line (1 \\leq j \\leq Q) should contain the answer to Query j.\n\nSample Input 1\n\n5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\nSample Output 1\n\n130\n200\n60\n\nThe graph in this input is as follows:\n\nHere the edges of Color 1 are shown as solid red lines, the edge of Color 2 is shown as a bold green line, and the edge of Color 4 is shown as a blue dashed line.\n\nQuery 1: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 4 is 100 + 30 = 130.\n\nQuery 2: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 5 is 100 + 100 = 200.\n\nQuery 3: Assuming that the length of every edge whose color is 3 is changed to 1000 (there is no such edge), the distance between Vertex 3 and Vertex 4 is 20 + 10 + 30 = 60. Note that the edges of Color 1 now have their original lengths.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14651, "cpu_time_ms": 982, "memory_kb": 254132}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s368284213", "group_id": "codeNet:p02986", "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;;; Lowest common ancestor of tree (or forest) by binary lifting\n;;; build: O(nlog(n))\n;;; query: O(log(n))\n;;;\n\n;; PAY ATTENTION TO THE STACK SIZE! THE CONSTRUCTOR DOES DFS.\n\n(deftype lca-vertex-number () '(signed-byte 32))\n\n(defstruct (lca-table\n (:constructor %make-lca-table\n (size\n &aux\n ;; requires 1 + log_2{size-1}\n (max-level (+ 1 (integer-length (- size 2))))\n (depths (make-array size\n :element-type 'lca-vertex-number\n :initial-element -1))\n (parents (make-array (list size max-level)\n :element-type 'lca-vertex-number))))\n (:conc-name lca-))\n (max-level nil :type (integer 0 #.most-positive-fixnum))\n (depths nil :type (simple-array lca-vertex-number (*)))\n (parents nil :type (simple-array lca-vertex-number (* *))))\n\n(defun make-lca-table (graph &key root (key #'identity))\n \"GRAPH := vector of adjacency lists\nROOT := null | non-negative fixnum\n\nIf ROOT is null, this function traverses each connected component of GRAPH from\nan arbitrarily picked vertex. Otherwise this function traverses GRAPH only from\nROOT; GRAPH must be tree in the latter case.\"\n (declare (optimize (speed 3))\n (vector graph)\n (function key)\n ((or null (integer 0 #.most-positive-fixnum)) root))\n (let* ((size (length graph))\n (lca-table (%make-lca-table size))\n (depths (lca-depths lca-table))\n (parents (lca-parents lca-table))\n (max-level (lca-max-level lca-table)))\n (labels ((dfs (v prev-v depth)\n (declare (lca-vertex-number v prev-v))\n (setf (aref depths v) depth)\n (setf (aref parents v 0) prev-v)\n (dolist (node (aref graph v))\n (let ((dest (funcall key node)))\n (declare (lca-vertex-number dest))\n (unless (= dest prev-v)\n (dfs dest v (+ 1 depth)))))))\n (if root\n (dfs root -1 0)\n (dotimes (v size)\n (when (= (aref depths v) -1)\n (dfs v -1 0))))\n (dotimes (k (- max-level 1))\n (dotimes (v size)\n (if (= -1 (aref parents v k))\n (setf (aref parents v (+ k 1)) -1)\n (setf (aref parents v (+ k 1))\n (aref parents (aref parents v k) k)))))\n lca-table)))\n\n(define-condition two-vertices-disconnected-error (error)\n ((lca-table :initarg :lca-table :accessor two-vertices-disconnected-error-lca-table)\n (vertex1 :initarg :vertex1 :accessor two-vertices-disconnected-error-vertex1)\n (vertex2 :initarg :vertex2 :accessor two-vertices-disconnected-error-vertex2))\n (:report\n (lambda (c s)\n (format s \"~W and ~W are disconnected on lca-table ~W\"\n (two-vertices-disconnected-error-vertex1 c)\n (two-vertices-disconnected-error-vertex2 c)\n (two-vertices-disconnected-error-lca-table c)))))\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional))\n lca-get-lca))\n(defun lca-get-lca (lca-table vertex1 vertex2)\n \"Returns the lowest common ancestor of the vertices VERTEX1 and VERTEX2.\"\n (declare (optimize (speed 3))\n ((and lca-vertex-number (integer 0)) vertex1 vertex2))\n (let* ((u vertex1)\n (v vertex2)\n (depths (lca-depths lca-table))\n (parents (lca-parents lca-table))\n (max-level (lca-max-level lca-table)))\n (declare (lca-vertex-number u v))\n ;; Ensures depth[u] <= depth[v]\n (when (> (aref depths u) (aref depths v))\n (rotatef u v))\n (dotimes (k max-level)\n (when (logbitp k (- (aref depths v) (aref depths u)))\n (setf v (aref parents v k))))\n (if (= u v)\n u\n (loop for k from (- max-level 1) downto 0\n unless (= (aref parents u k) (aref parents v k))\n do (setq u (aref parents u k)\n v (aref parents v k))\n finally (if (= (aref parents u 0) -1)\n (error 'two-vertices-disconnected-error\n :lca-table lca-table\n :vertex1 vertex1\n :vertex2 vertex2)\n (return (aref parents u 0)))))))\n\n(declaim (inline lca-distance))\n(defun lca-distance (lca-table u v)\n \"Returns the distance between two vertices U and V.\"\n (declare (optimize (speed 3)))\n (let ((depths (lca-depths lca-table))\n (lca (lca-get-lca lca-table u v)))\n (+ (- (aref depths u) (aref depths lca))\n (- (aref depths v) (aref depths lca)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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:\n;; - more sane handling of unbounded index\n;; - handy function for initialization\n;; - iteration; map\n;; - abstraction\n;; - printer\n\n(defconstant +persistent-vector-log+ 16)\n\n(declaim (inline %make-persistent-vector))\n(defstruct (persistent-vector (:constructor %make-persistent-vector ())\n (:conc-name %pv-))\n (value 0 :type fixnum)\n (children nil :type (or null (simple-vector #.+persistent-vector-log+))))\n\n(defun pv-assoc (pvector index value)\n (declare ((or null persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (labels ((recur (pvector index)\n (declare ((or (integer 0 0) persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (let ((res (%make-persistent-vector)))\n (if (eql 0 pvector)\n (setf (%pv-children res)\n (make-array +persistent-vector-log+ :initial-element 0))\n (setf (%pv-children res) (copy-seq (%pv-children pvector))\n (%pv-value res) (%pv-value pvector)))\n (if (zerop index)\n (setf (%pv-value res) value)\n (setf (aref (%pv-children res) (mod index +persistent-vector-log+))\n (recur (aref (%pv-children res) (mod index +persistent-vector-log+))\n (floor index +persistent-vector-log+))))\n res)))\n (recur (or pvector 0) index)))\n\n(defun pv-ref (pvector index)\n (declare ((or null persistent-vector) pvector))\n (labels ((recur (pvector index)\n (declare ((or (integer 0 0) persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (cond ((eql 0 pvector) 0)\n ((zerop index) (%pv-value pvector))\n (t (recur (aref (%pv-children pvector) (mod index +persistent-vector-log+))\n (floor index +persistent-vector-log+))))))\n (recur (or pvector 0) index)))\n\n(defun main ()\n (let* ((n (read))\n (q (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (wgraph (make-array n :element-type 'list :initial-element nil)))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1))\n (c (- (read-fixnum) 1))\n (d (read-fixnum)))\n (push a (aref graph b))\n (push b (aref graph a))\n (push (list* a c d) (aref wgraph b))\n (push (list* b c d) (aref wgraph a))))\n (let ((lca-table (make-lca-table graph))\n (dists (make-array n :element-type 'uint32))\n (ccounts (make-array n :initial-element nil))\n (cdists (make-array n :initial-element nil)))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (dolist (node (aref wgraph v))\n (destructuring-bind (child color . cost) node\n (unless (= child parent)\n (setf (aref dists child) (+ (aref dists v) cost))\n (setf (aref ccounts child)\n (pv-assoc (aref ccounts v)\n color\n (+ 1 (pv-ref (aref ccounts v) color))))\n (setf (aref cdists child)\n (pv-assoc (aref cdists v)\n color\n (+ cost (pv-ref (aref cdists v) color))))\n (dfs child v)))))\n (with-buffered-stdout\n (dotimes (_ q)\n (let* ((x (- (read-fixnum) 1))\n (y (read-fixnum))\n (u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (lca (lca-get-lca lca-table u v))\n (base (+ (aref dists u) (aref dists v) (* -2 (aref dists lca))))\n (ccount (+ (pv-ref (aref ccounts u) x)\n (pv-ref (aref ccounts v) x)\n (* -2 (pv-ref (aref ccounts lca) x))))\n (cdist (+ (pv-ref (aref cdists u) x)\n (pv-ref (aref cdists v) x)\n (* -2 (pv-ref (aref cdists lca) x)))))\n (dbg x y u v lca)\n (dbg base ccount cdist)\n (println (+ (- base cdist) (* ccount 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 \"5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\"\n \"130\n200\n60\n\")))\n", "language": "Lisp", "metadata": {"date": 1585380072, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02986.html", "problem_id": "p02986", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02986/input.txt", "sample_output_relpath": "derived/input_output/data/p02986/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02986/Lisp/s368284213.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s368284213", "user_id": "u352600849"}, "prompt_components": {"gold_output": "130\n200\n60\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;;; Lowest common ancestor of tree (or forest) by binary lifting\n;;; build: O(nlog(n))\n;;; query: O(log(n))\n;;;\n\n;; PAY ATTENTION TO THE STACK SIZE! THE CONSTRUCTOR DOES DFS.\n\n(deftype lca-vertex-number () '(signed-byte 32))\n\n(defstruct (lca-table\n (:constructor %make-lca-table\n (size\n &aux\n ;; requires 1 + log_2{size-1}\n (max-level (+ 1 (integer-length (- size 2))))\n (depths (make-array size\n :element-type 'lca-vertex-number\n :initial-element -1))\n (parents (make-array (list size max-level)\n :element-type 'lca-vertex-number))))\n (:conc-name lca-))\n (max-level nil :type (integer 0 #.most-positive-fixnum))\n (depths nil :type (simple-array lca-vertex-number (*)))\n (parents nil :type (simple-array lca-vertex-number (* *))))\n\n(defun make-lca-table (graph &key root (key #'identity))\n \"GRAPH := vector of adjacency lists\nROOT := null | non-negative fixnum\n\nIf ROOT is null, this function traverses each connected component of GRAPH from\nan arbitrarily picked vertex. Otherwise this function traverses GRAPH only from\nROOT; GRAPH must be tree in the latter case.\"\n (declare (optimize (speed 3))\n (vector graph)\n (function key)\n ((or null (integer 0 #.most-positive-fixnum)) root))\n (let* ((size (length graph))\n (lca-table (%make-lca-table size))\n (depths (lca-depths lca-table))\n (parents (lca-parents lca-table))\n (max-level (lca-max-level lca-table)))\n (labels ((dfs (v prev-v depth)\n (declare (lca-vertex-number v prev-v))\n (setf (aref depths v) depth)\n (setf (aref parents v 0) prev-v)\n (dolist (node (aref graph v))\n (let ((dest (funcall key node)))\n (declare (lca-vertex-number dest))\n (unless (= dest prev-v)\n (dfs dest v (+ 1 depth)))))))\n (if root\n (dfs root -1 0)\n (dotimes (v size)\n (when (= (aref depths v) -1)\n (dfs v -1 0))))\n (dotimes (k (- max-level 1))\n (dotimes (v size)\n (if (= -1 (aref parents v k))\n (setf (aref parents v (+ k 1)) -1)\n (setf (aref parents v (+ k 1))\n (aref parents (aref parents v k) k)))))\n lca-table)))\n\n(define-condition two-vertices-disconnected-error (error)\n ((lca-table :initarg :lca-table :accessor two-vertices-disconnected-error-lca-table)\n (vertex1 :initarg :vertex1 :accessor two-vertices-disconnected-error-vertex1)\n (vertex2 :initarg :vertex2 :accessor two-vertices-disconnected-error-vertex2))\n (:report\n (lambda (c s)\n (format s \"~W and ~W are disconnected on lca-table ~W\"\n (two-vertices-disconnected-error-vertex1 c)\n (two-vertices-disconnected-error-vertex2 c)\n (two-vertices-disconnected-error-lca-table c)))))\n\n(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional))\n lca-get-lca))\n(defun lca-get-lca (lca-table vertex1 vertex2)\n \"Returns the lowest common ancestor of the vertices VERTEX1 and VERTEX2.\"\n (declare (optimize (speed 3))\n ((and lca-vertex-number (integer 0)) vertex1 vertex2))\n (let* ((u vertex1)\n (v vertex2)\n (depths (lca-depths lca-table))\n (parents (lca-parents lca-table))\n (max-level (lca-max-level lca-table)))\n (declare (lca-vertex-number u v))\n ;; Ensures depth[u] <= depth[v]\n (when (> (aref depths u) (aref depths v))\n (rotatef u v))\n (dotimes (k max-level)\n (when (logbitp k (- (aref depths v) (aref depths u)))\n (setf v (aref parents v k))))\n (if (= u v)\n u\n (loop for k from (- max-level 1) downto 0\n unless (= (aref parents u k) (aref parents v k))\n do (setq u (aref parents u k)\n v (aref parents v k))\n finally (if (= (aref parents u 0) -1)\n (error 'two-vertices-disconnected-error\n :lca-table lca-table\n :vertex1 vertex1\n :vertex2 vertex2)\n (return (aref parents u 0)))))))\n\n(declaim (inline lca-distance))\n(defun lca-distance (lca-table u v)\n \"Returns the distance between two vertices U and V.\"\n (declare (optimize (speed 3)))\n (let ((depths (lca-depths lca-table))\n (lca (lca-get-lca lca-table u v)))\n (+ (- (aref depths u) (aref depths lca))\n (- (aref depths v) (aref depths lca)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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:\n;; - more sane handling of unbounded index\n;; - handy function for initialization\n;; - iteration; map\n;; - abstraction\n;; - printer\n\n(defconstant +persistent-vector-log+ 16)\n\n(declaim (inline %make-persistent-vector))\n(defstruct (persistent-vector (:constructor %make-persistent-vector ())\n (:conc-name %pv-))\n (value 0 :type fixnum)\n (children nil :type (or null (simple-vector #.+persistent-vector-log+))))\n\n(defun pv-assoc (pvector index value)\n (declare ((or null persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (labels ((recur (pvector index)\n (declare ((or (integer 0 0) persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (let ((res (%make-persistent-vector)))\n (if (eql 0 pvector)\n (setf (%pv-children res)\n (make-array +persistent-vector-log+ :initial-element 0))\n (setf (%pv-children res) (copy-seq (%pv-children pvector))\n (%pv-value res) (%pv-value pvector)))\n (if (zerop index)\n (setf (%pv-value res) value)\n (setf (aref (%pv-children res) (mod index +persistent-vector-log+))\n (recur (aref (%pv-children res) (mod index +persistent-vector-log+))\n (floor index +persistent-vector-log+))))\n res)))\n (recur (or pvector 0) index)))\n\n(defun pv-ref (pvector index)\n (declare ((or null persistent-vector) pvector))\n (labels ((recur (pvector index)\n (declare ((or (integer 0 0) persistent-vector) pvector)\n ((integer 0 #.most-positive-fixnum) index))\n (cond ((eql 0 pvector) 0)\n ((zerop index) (%pv-value pvector))\n (t (recur (aref (%pv-children pvector) (mod index +persistent-vector-log+))\n (floor index +persistent-vector-log+))))))\n (recur (or pvector 0) index)))\n\n(defun main ()\n (let* ((n (read))\n (q (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (wgraph (make-array n :element-type 'list :initial-element nil)))\n (dotimes (i (- n 1))\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1))\n (c (- (read-fixnum) 1))\n (d (read-fixnum)))\n (push a (aref graph b))\n (push b (aref graph a))\n (push (list* a c d) (aref wgraph b))\n (push (list* b c d) (aref wgraph a))))\n (let ((lca-table (make-lca-table graph))\n (dists (make-array n :element-type 'uint32))\n (ccounts (make-array n :initial-element nil))\n (cdists (make-array n :initial-element nil)))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (dolist (node (aref wgraph v))\n (destructuring-bind (child color . cost) node\n (unless (= child parent)\n (setf (aref dists child) (+ (aref dists v) cost))\n (setf (aref ccounts child)\n (pv-assoc (aref ccounts v)\n color\n (+ 1 (pv-ref (aref ccounts v) color))))\n (setf (aref cdists child)\n (pv-assoc (aref cdists v)\n color\n (+ cost (pv-ref (aref cdists v) color))))\n (dfs child v)))))\n (with-buffered-stdout\n (dotimes (_ q)\n (let* ((x (- (read-fixnum) 1))\n (y (read-fixnum))\n (u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (lca (lca-get-lca lca-table u v))\n (base (+ (aref dists u) (aref dists v) (* -2 (aref dists lca))))\n (ccount (+ (pv-ref (aref ccounts u) x)\n (pv-ref (aref ccounts v) x)\n (* -2 (pv-ref (aref ccounts lca) x))))\n (cdist (+ (pv-ref (aref cdists u) x)\n (pv-ref (aref cdists v) x)\n (* -2 (pv-ref (aref cdists lca) x)))))\n (dbg x y u v lca)\n (dbg base ccount cdist)\n (println (+ (- base cdist) (* ccount 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 \"5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\"\n \"130\n200\n60\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere is a tree with N vertices numbered 1 to N.\nThe i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively.\nHere the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors.\n\nAnswer the following Q queries:\n\nQuery j (1 \\leq j \\leq Q): assuming that the length of every edge whose color is x_j is changed to y_j, find the distance between Vertex u_j and Vertex v_j. (The changes of the lengths of edges do not affect the subsequent queries.)\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq a_i, b_i \\leq N\n\n1 \\leq c_i \\leq N-1\n\n1 \\leq d_i \\leq 10^4\n\n1 \\leq x_j \\leq N-1\n\n1 \\leq y_j \\leq 10^4\n\n1 \\leq u_j < v_j \\leq N\n\nThe given graph is a tree.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\na_1 b_1 c_1 d_1\n:\na_{N-1} b_{N-1} c_{N-1} d_{N-1}\nx_1 y_1 u_1 v_1\n:\nx_Q y_Q u_Q v_Q\n\nOutput\n\nPrint Q lines. The j-th line (1 \\leq j \\leq Q) should contain the answer to Query j.\n\nSample Input 1\n\n5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\nSample Output 1\n\n130\n200\n60\n\nThe graph in this input is as follows:\n\nHere the edges of Color 1 are shown as solid red lines, the edge of Color 2 is shown as a bold green line, and the edge of Color 4 is shown as a blue dashed line.\n\nQuery 1: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 4 is 100 + 30 = 130.\n\nQuery 2: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 5 is 100 + 100 = 200.\n\nQuery 3: Assuming that the length of every edge whose color is 3 is changed to 1000 (there is no such edge), the distance between Vertex 3 and Vertex 4 is 20 + 10 + 30 = 60. Note that the edges of Color 1 now have their original lengths.", "sample_input": "5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n"}, "reference_outputs": ["130\n200\n60\n"], "source_document_id": "p02986", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere is a tree with N vertices numbered 1 to N.\nThe i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively.\nHere the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors.\n\nAnswer the following Q queries:\n\nQuery j (1 \\leq j \\leq Q): assuming that the length of every edge whose color is x_j is changed to y_j, find the distance between Vertex u_j and Vertex v_j. (The changes of the lengths of edges do not affect the subsequent queries.)\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq a_i, b_i \\leq N\n\n1 \\leq c_i \\leq N-1\n\n1 \\leq d_i \\leq 10^4\n\n1 \\leq x_j \\leq N-1\n\n1 \\leq y_j \\leq 10^4\n\n1 \\leq u_j < v_j \\leq N\n\nThe given graph is a tree.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\na_1 b_1 c_1 d_1\n:\na_{N-1} b_{N-1} c_{N-1} d_{N-1}\nx_1 y_1 u_1 v_1\n:\nx_Q y_Q u_Q v_Q\n\nOutput\n\nPrint Q lines. The j-th line (1 \\leq j \\leq Q) should contain the answer to Query j.\n\nSample Input 1\n\n5 3\n1 2 1 10\n1 3 2 20\n2 4 4 30\n5 2 1 40\n1 100 1 4\n1 100 1 5\n3 1000 3 4\n\nSample Output 1\n\n130\n200\n60\n\nThe graph in this input is as follows:\n\nHere the edges of Color 1 are shown as solid red lines, the edge of Color 2 is shown as a bold green line, and the edge of Color 4 is shown as a blue dashed line.\n\nQuery 1: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 4 is 100 + 30 = 130.\n\nQuery 2: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 5 is 100 + 100 = 200.\n\nQuery 3: Assuming that the length of every edge whose color is 3 is changed to 1000 (there is no such edge), the distance between Vertex 3 and Vertex 4 is 20 + 10 + 30 = 60. Note that the edges of Color 1 now have their original lengths.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14590, "cpu_time_ms": 1223, "memory_kb": 350132}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s516437348", "group_id": "codeNet:p02987", "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-aaa ()\n (let ((l))\n (dotimes (i 4)\n (let* ((c (read-char))\n\t (old (rassoc c l :test #'char=)))\n\t(push (cons (if old (1+ (car old)) 1)\n\t\t c)\n\t l)))\n (format t \"~:[No~;Yes~]\"\n\t (= 2 (apply #'max\n\t\t (mapcar #'car l))))))\n\n(solution-aaa)", "language": "Lisp", "metadata": {"date": 1561929035, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02987.html", "problem_id": "p02987", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02987/input.txt", "sample_output_relpath": "derived/input_output/data/p02987/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02987/Lisp/s516437348.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s516437348", "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 vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver solution-aaa ()\n (let ((l))\n (dotimes (i 4)\n (let* ((c (read-char))\n\t (old (rassoc c l :test #'char=)))\n\t(push (cons (if old (1+ (car old)) 1)\n\t\t c)\n\t l)))\n (format t \"~:[No~;Yes~]\"\n\t (= 2 (apply #'max\n\t\t (mapcar #'car l))))))\n\n(solution-aaa)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a 4-character string S consisting of uppercase English letters.\nDetermine if S consists of exactly two kinds of characters which both appear twice in S.\n\nConstraints\n\nThe length of S is 4.\n\nS consists of uppercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S consists of exactly two kinds of characters which both appear twice in S, print Yes; otherwise, print No.\n\nSample Input 1\n\nASSA\n\nSample Output 1\n\nYes\n\nS consists of A and S which both appear twice in S.\n\nSample Input 2\n\nSTOP\n\nSample Output 2\n\nNo\n\nSample Input 3\n\nFFEE\n\nSample Output 3\n\nYes\n\nSample Input 4\n\nFREE\n\nSample Output 4\n\nNo", "sample_input": "ASSA\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02987", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a 4-character string S consisting of uppercase English letters.\nDetermine if S consists of exactly two kinds of characters which both appear twice in S.\n\nConstraints\n\nThe length of S is 4.\n\nS consists of uppercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S consists of exactly two kinds of characters which both appear twice in S, print Yes; otherwise, print No.\n\nSample Input 1\n\nASSA\n\nSample Output 1\n\nYes\n\nS consists of A and S which both appear twice in S.\n\nSample Input 2\n\nSTOP\n\nSample Output 2\n\nNo\n\nSample Input 3\n\nFFEE\n\nSample Output 3\n\nYes\n\nSample Input 4\n\nFREE\n\nSample Output 4\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 472, "cpu_time_ms": 132, "memory_kb": 14820}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s848788222", "group_id": "codeNet:p02987", "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-a ()\n (let* ((l (loop repeat 4 collect\n\t\t (read-char))))\n (format t \"~:[No~;Yes~]\"\n\t (or\n\t (and\n\t (eql (nth 0 l) (nth 1 l))\n\t (eql (nth 2 l) (nth 3 l)))\n\t (and\n\t (eql (nth 0 l) (nth 2 l))\n\t (eql (nth 1 l) (nth 3 l)))\n\t (and\n\t (eql (nth 0 l) (nth 3 l))\n\t (eql (nth 1 l) (nth 2 l)))))))\n\n(solution-a)", "language": "Lisp", "metadata": {"date": 1561857472, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02987.html", "problem_id": "p02987", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02987/input.txt", "sample_output_relpath": "derived/input_output/data/p02987/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02987/Lisp/s848788222.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s848788222", "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 vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver solution-a ()\n (let* ((l (loop repeat 4 collect\n\t\t (read-char))))\n (format t \"~:[No~;Yes~]\"\n\t (or\n\t (and\n\t (eql (nth 0 l) (nth 1 l))\n\t (eql (nth 2 l) (nth 3 l)))\n\t (and\n\t (eql (nth 0 l) (nth 2 l))\n\t (eql (nth 1 l) (nth 3 l)))\n\t (and\n\t (eql (nth 0 l) (nth 3 l))\n\t (eql (nth 1 l) (nth 2 l)))))))\n\n(solution-a)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a 4-character string S consisting of uppercase English letters.\nDetermine if S consists of exactly two kinds of characters which both appear twice in S.\n\nConstraints\n\nThe length of S is 4.\n\nS consists of uppercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S consists of exactly two kinds of characters which both appear twice in S, print Yes; otherwise, print No.\n\nSample Input 1\n\nASSA\n\nSample Output 1\n\nYes\n\nS consists of A and S which both appear twice in S.\n\nSample Input 2\n\nSTOP\n\nSample Output 2\n\nNo\n\nSample Input 3\n\nFFEE\n\nSample Output 3\n\nYes\n\nSample Input 4\n\nFREE\n\nSample Output 4\n\nNo", "sample_input": "ASSA\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p02987", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a 4-character string S consisting of uppercase English letters.\nDetermine if S consists of exactly two kinds of characters which both appear twice in S.\n\nConstraints\n\nThe length of S is 4.\n\nS consists of uppercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nIf S consists of exactly two kinds of characters which both appear twice in S, print Yes; otherwise, print No.\n\nSample Input 1\n\nASSA\n\nSample Output 1\n\nYes\n\nS consists of A and S which both appear twice in S.\n\nSample Input 2\n\nSTOP\n\nSample Output 2\n\nNo\n\nSample Input 3\n\nFFEE\n\nSample Output 3\n\nYes\n\nSample Input 4\n\nFREE\n\nSample Output 4\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 100, "memory_kb": 14944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s077822037", "group_id": "codeNet:p02988", "input_text": "(defun readseq (num)\n (loop \n as i \n below num \n collect (read)\n )\n)\n\n(defun ismonoinc (l)\n (or \n (< (first l) (second l) (third l))\n (> (first l) (second l) (third l))\n )\n)\n\n(defun createordinaryseq (n seq)\n (loop \n as i below (- n 2) \n collect (ismonoinc (list (first seq) (second seq) (third seq)))\n do (setq seq (cdr seq))\n )\n)\n \n(let* (\n (n (read))\n (seq (readseq n))\n )\n (princ (count T (createordinaryseq n seq)))\n)", "language": "Lisp", "metadata": {"date": 1583630049, "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/s077822037.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s077822037", "user_id": "u606976120"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun readseq (num)\n (loop \n as i \n below num \n collect (read)\n )\n)\n\n(defun ismonoinc (l)\n (or \n (< (first l) (second l) (third l))\n (> (first l) (second l) (third l))\n )\n)\n\n(defun createordinaryseq (n seq)\n (loop \n as i below (- n 2) \n collect (ismonoinc (list (first seq) (second seq) (third seq)))\n do (setq seq (cdr seq))\n )\n)\n \n(let* (\n (n (read))\n (seq (readseq n))\n )\n (princ (count T (createordinaryseq n seq)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 463, "cpu_time_ms": 131, "memory_kb": 14948}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s503526423", "group_id": "codeNet:p02989", "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 (ds (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref ds i) (read-fixnum)))\n (setf ds (sort ds #'<))\n (let* ((mid2 (floor n 2))\n (mid1 (- mid2 1)))\n (println (- (aref ds mid2) (aref ds mid1))))))\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 \"6\n9 1 4 4 6 7\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n9 1 14 5 5 4 4 14\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"14\n99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1\n\"\n \"42685\n\")))\n", "language": "Lisp", "metadata": {"date": 1561857067, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02989.html", "problem_id": "p02989", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02989/input.txt", "sample_output_relpath": "derived/input_output/data/p02989/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02989/Lisp/s503526423.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s503526423", "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(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 (ds (make-array n :element-type 'uint32)))\n (dotimes (i n) (setf (aref ds i) (read-fixnum)))\n (setf ds (sort ds #'<))\n (let* ((mid2 (floor n 2))\n (mid1 (- mid2 1)))\n (println (- (aref ds mid2) (aref ds mid1))))))\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 \"6\n9 1 4 4 6 7\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n9 1 14 5 5 4 4 14\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"14\n99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1\n\"\n \"42685\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi made N problems for competitive programming.\nThe problems are numbered 1 to N, and the difficulty of Problem i is represented as an integer d_i (the higher, the harder).\n\nHe is dividing the problems into two categories by choosing an integer K, as follows:\n\nA problem with difficulty K or higher will be for ARCs.\n\nA problem with difficulty lower than K will be for ABCs.\n\nHow many choices of the integer K make the number of problems for ARCs and the number of problems for ABCs the same?\n\nProblem Statement\n\n2 \\leq N \\leq 10^5\n\nN is an even number.\n\n1 \\leq d_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\nd_1 d_2 ... d_N\n\nOutput\n\nPrint the number of choices of the integer K that make the number of problems for ARCs and the number of problems for ABCs the same.\n\nSample Input 1\n\n6\n9 1 4 4 6 7\n\nSample Output 1\n\n2\n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and 4 will be for ABCs, and the objective is achieved.\nThus, the answer is 2.\n\nSample Input 2\n\n8\n9 1 14 5 5 4 4 14\n\nSample Output 2\n\n0\n\nThere may be no choice of the integer K that make the number of problems for ARCs and the number of problems for ABCs the same.\n\nSample Input 3\n\n14\n99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1\n\nSample Output 3\n\n42685", "sample_input": "6\n9 1 4 4 6 7\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02989", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi made N problems for competitive programming.\nThe problems are numbered 1 to N, and the difficulty of Problem i is represented as an integer d_i (the higher, the harder).\n\nHe is dividing the problems into two categories by choosing an integer K, as follows:\n\nA problem with difficulty K or higher will be for ARCs.\n\nA problem with difficulty lower than K will be for ABCs.\n\nHow many choices of the integer K make the number of problems for ARCs and the number of problems for ABCs the same?\n\nProblem Statement\n\n2 \\leq N \\leq 10^5\n\nN is an even number.\n\n1 \\leq d_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\nd_1 d_2 ... d_N\n\nOutput\n\nPrint the number of choices of the integer K that make the number of problems for ARCs and the number of problems for ABCs the same.\n\nSample Input 1\n\n6\n9 1 4 4 6 7\n\nSample Output 1\n\n2\n\nIf we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and 4 will be for ABCs, and the objective is achieved.\nThus, the answer is 2.\n\nSample Input 2\n\n8\n9 1 14 5 5 4 4 14\n\nSample Output 2\n\n0\n\nThere may be no choice of the integer K that make the number of problems for ARCs and the number of problems for ABCs the same.\n\nSample Input 3\n\n14\n99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1\n\nSample Output 3\n\n42685", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4798, "cpu_time_ms": 392, "memory_kb": 23008}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s404494046", "group_id": "codeNet:p02990", "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(let ((arr (make-array (list 2000 2000) :initial-element -1)))\n (defun comb (n k)\n (when (< (aref arr n k) 0)\n (setf\n (aref arr n k)\n (cond\n\t ((< n k) 0)\n\t ((= n k) 1)\n\t ((= k 0) 1)\n\t ((= k 1) n)\n\t (t (+ (comb (1- n) k)\n\t (comb (1- n) (1- k)))))))\n (aref arr n k)))\n\n(defsolver solution-d (n k)\n (loop for i from 1 to k do\n (let ((cnt (comb\n\t\t(+ n (- k) 1)\n\t\ti))\n\t (w (comb (1- k) (1- i))))\n (format t \"~a~%\"\n\t (mod\n\t (* cnt w)\n\t 1000000007)))))\n\n(solution-d)", "language": "Lisp", "metadata": {"date": 1561867080, "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/s404494046.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s404494046", "user_id": "u100932207"}, "prompt_components": {"gold_output": "3\n6\n1\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(let ((arr (make-array (list 2000 2000) :initial-element -1)))\n (defun comb (n k)\n (when (< (aref arr n k) 0)\n (setf\n (aref arr n k)\n (cond\n\t ((< n k) 0)\n\t ((= n k) 1)\n\t ((= k 0) 1)\n\t ((= k 1) n)\n\t (t (+ (comb (1- n) k)\n\t (comb (1- n) (1- k)))))))\n (aref arr n k)))\n\n(defsolver solution-d (n k)\n (loop for i from 1 to k do\n (let ((cnt (comb\n\t\t(+ n (- k) 1)\n\t\ti))\n\t (w (comb (1- k) (1- i))))\n (format t \"~a~%\"\n\t (mod\n\t (* cnt w)\n\t 1000000007)))))\n\n(solution-d)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 700, "cpu_time_ms": 672, "memory_kb": 467552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s705601198", "group_id": "codeNet:p02990", "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(let ((arr (make-array (list 2000 50) :initial-element -1)))\n (defun comb (n k)\n (when (< (aref arr n k) 0)\n (setf\n (aref arr n k)\n (cond\n\t ((= n 0) 0)\n\t ((= k 0) 1)\n\t ((= k 1) n)\n\t (t (+ (comb (1- n) k)\n\t (comb (1- n) (1- k)))))))\n (aref arr n k)))\n\n(defsolver solution-d (n k)\n (dotimes (i k)\n (let ((cnt (comb\n\t\t(+ n (- k) 1)\n\t\t(1+ i)))\n\t (w (if (< 0 i (1- k))\n\t\t (1- k)\n\t\t 1)))\n (format t \"~a~%\"\n\t (mod\n\t (* cnt w)\n\t 1000000007)))))\n\n(solution-d)", "language": "Lisp", "metadata": {"date": 1561862513, "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/s705601198.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s705601198", "user_id": "u100932207"}, "prompt_components": {"gold_output": "3\n6\n1\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(let ((arr (make-array (list 2000 50) :initial-element -1)))\n (defun comb (n k)\n (when (< (aref arr n k) 0)\n (setf\n (aref arr n k)\n (cond\n\t ((= n 0) 0)\n\t ((= k 0) 1)\n\t ((= k 1) n)\n\t (t (+ (comb (1- n) k)\n\t (comb (1- n) (1- k)))))))\n (aref arr n k)))\n\n(defsolver solution-d (n k)\n (dotimes (i k)\n (let ((cnt (comb\n\t\t(+ n (- k) 1)\n\t\t(1+ i)))\n\t (w (if (< 0 i (1- k))\n\t\t (1- k)\n\t\t 1)))\n (format t \"~a~%\"\n\t (mod\n\t (* cnt w)\n\t 1000000007)))))\n\n(solution-d)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 691, "cpu_time_ms": 189, "memory_kb": 19816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s589226162", "group_id": "codeNet:p02993", "input_text": "(defparameter seq (read-line))\n \n(defun check (text)\n (if (or (eq (char text 0)\n (char text 1))\n (eq (char text 1)\n (char text 2))\n (eq (char text 2)\n (char text 3)))\n \"Bad\"\n \"Good\"))\n \n(print (check seq))", "language": "Lisp", "metadata": {"date": 1561317159, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s589226162.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s589226162", "user_id": "u425317134"}, "prompt_components": {"gold_output": "Bad\n", "input_to_evaluate": "(defparameter seq (read-line))\n \n(defun check (text)\n (if (or (eq (char text 0)\n (char text 1))\n (eq (char text 1)\n (char text 2))\n (eq (char text 2)\n (char text 3)))\n \"Bad\"\n \"Good\"))\n \n(print (check seq))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 273, "cpu_time_ms": 10, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s179580563", "group_id": "codeNet:p02993", "input_text": "(defparameter seq (subseq (read-line) 0 4)\n\n(defun check (text)\n (if (or (eq (char text 0)\n (char text 1))\n (eq (char text 1)\n (char text 2))\n (eq (char text 2)\n (char text 3)))\n \"Bad\"\n \"Good\")))\n\n(print (check seq))", "language": "Lisp", "metadata": {"date": 1561316982, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s179580563.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s179580563", "user_id": "u425317134"}, "prompt_components": {"gold_output": "Bad\n", "input_to_evaluate": "(defparameter seq (subseq (read-line) 0 4)\n\n(defun check (text)\n (if (or (eq (char text 0)\n (char text 1))\n (eq (char text 1)\n (char text 2))\n (eq (char text 2)\n (char text 3)))\n \"Bad\"\n \"Good\")))\n\n(print (check seq))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 41, "memory_kb": 5604}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s557188341", "group_id": "codeNet:p02993", "input_text": "(defun check (text)\n (if (= 1 (length text))\n \"Good\"\n (if (equal (char text 0)\n (char text 1))\n \"Bad\"\n (check (subseq text 1)))))\n\n(defparameter line (read-line nil nil))\n\n\n(print (check line))", "language": "Lisp", "metadata": {"date": 1561316365, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s557188341.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s557188341", "user_id": "u425317134"}, "prompt_components": {"gold_output": "Bad\n", "input_to_evaluate": "(defun check (text)\n (if (= 1 (length text))\n \"Good\"\n (if (equal (char text 0)\n (char text 1))\n \"Bad\"\n (check (subseq text 1)))))\n\n(defparameter line (read-line nil nil))\n\n\n(print (check line))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 111, "memory_kb": 10848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s673156879", "group_id": "codeNet:p02993", "input_text": "\n(let* ((line (read-line nil nil)))\n (if (or (and (char= (char line 0) (char line 1)))\n\t\t (and (char= (char line 1) (char line 2)))\n\t\t (and (char= (char line 2) (char line 3))))\n\t(format t \"Bad\")\n\t(format t \"Good\")))", "language": "Lisp", "metadata": {"date": 1561252425, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s673156879.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s673156879", "user_id": "u254205055"}, "prompt_components": {"gold_output": "Bad\n", "input_to_evaluate": "\n(let* ((line (read-line nil nil)))\n (if (or (and (char= (char line 0) (char line 1)))\n\t\t (and (char= (char line 1) (char line 2)))\n\t\t (and (char= (char line 2) (char line 3))))\n\t(format t \"Bad\")\n\t(format t \"Good\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 106, "memory_kb": 10720}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s858451638", "group_id": "codeNet:p02994", "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 l)\n (let ((sum (* (/ (+ (* 2 l) n -1) 2) n)))\n (format t \"~a~%\"\n (cond\n\t ((<= (- 1 N) l 0) sum) \n\t ((< l 0) (- sum l n -1))\n\t (t (- sum l))))))\n\n(solution-b)", "language": "Lisp", "metadata": {"date": 1561254357, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02994.html", "problem_id": "p02994", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02994/input.txt", "sample_output_relpath": "derived/input_output/data/p02994/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02994/Lisp/s858451638.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s858451638", "user_id": "u100932207"}, "prompt_components": {"gold_output": "18\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 l)\n (let ((sum (* (/ (+ (* 2 l) n -1) 2) n)))\n (format t \"~a~%\"\n (cond\n\t ((<= (- 1 N) l 0) sum) \n\t ((< l 0) (- sum l n -1))\n\t (t (- sum l))))))\n\n(solution-b)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.\n\nYou can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.\n\nYou planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.\n\nYou want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples.\n\nFind the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above.\n\nWe can prove that this value is uniquely determined.\n\nConstraints\n\n2 \\leq N \\leq 200\n\n-100 \\leq L \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN L\n\nOutput\n\nFind the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat.\n\nSample Input 1\n\n5 2\n\nSample Output 1\n\n18\n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively. The optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\nSample Input 2\n\n3 -1\n\nSample Output 2\n\n0\n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal choice is to eat Apple 2, so the answer is (-1)+1=0.\n\nSample Input 3\n\n30 -50\n\nSample Output 3\n\n-1044", "sample_input": "5 2\n"}, "reference_outputs": ["18\n"], "source_document_id": "p02994", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.\n\nYou can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.\n\nYou planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.\n\nYou want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples.\n\nFind the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above.\n\nWe can prove that this value is uniquely determined.\n\nConstraints\n\n2 \\leq N \\leq 200\n\n-100 \\leq L \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN L\n\nOutput\n\nFind the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat.\n\nSample Input 1\n\n5 2\n\nSample Output 1\n\n18\n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively. The optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\nSample Input 2\n\n3 -1\n\nSample Output 2\n\n0\n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal choice is to eat Apple 2, so the answer is (-1)+1=0.\n\nSample Input 3\n\n30 -50\n\nSample Output 3\n\n-1044", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 380, "cpu_time_ms": 138, "memory_kb": 15976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s544210520", "group_id": "codeNet:p02994", "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 (l (read)))\n (labels ((frob (i) (+ l i -1)))\n (let* ((original (loop for i from 1 to n sum (frob i)))\n (res #xffffffff))\n (loop for excluded from 1 to n\n for value = (loop for i from 1 to n unless (= i excluded) sum (frob i))\n when (<= (abs (- value original))\n (abs (- res original)))\n do (setf res value))\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", "language": "Lisp", "metadata": {"date": 1561252034, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02994.html", "problem_id": "p02994", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02994/input.txt", "sample_output_relpath": "derived/input_output/data/p02994/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02994/Lisp/s544210520.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s544210520", "user_id": "u352600849"}, "prompt_components": {"gold_output": "18\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 (l (read)))\n (labels ((frob (i) (+ l i -1)))\n (let* ((original (loop for i from 1 to n sum (frob i)))\n (res #xffffffff))\n (loop for excluded from 1 to n\n for value = (loop for i from 1 to n unless (= i excluded) sum (frob i))\n when (<= (abs (- value original))\n (abs (- res original)))\n do (setf res value))\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", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.\n\nYou can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.\n\nYou planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.\n\nYou want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples.\n\nFind the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above.\n\nWe can prove that this value is uniquely determined.\n\nConstraints\n\n2 \\leq N \\leq 200\n\n-100 \\leq L \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN L\n\nOutput\n\nFind the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat.\n\nSample Input 1\n\n5 2\n\nSample Output 1\n\n18\n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively. The optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\nSample Input 2\n\n3 -1\n\nSample Output 2\n\n0\n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal choice is to eat Apple 2, so the answer is (-1)+1=0.\n\nSample Input 3\n\n30 -50\n\nSample Output 3\n\n-1044", "sample_input": "5 2\n"}, "reference_outputs": ["18\n"], "source_document_id": "p02994", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.\n\nYou can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.\n\nYou planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.\n\nYou want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples.\n\nFind the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above.\n\nWe can prove that this value is uniquely determined.\n\nConstraints\n\n2 \\leq N \\leq 200\n\n-100 \\leq L \\leq 100\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN L\n\nOutput\n\nFind the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat.\n\nSample Input 1\n\n5 2\n\nSample Output 1\n\n18\n\nThe flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively. The optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.\n\nSample Input 2\n\n3 -1\n\nSample Output 2\n\n0\n\nThe flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal choice is to eat Apple 2, so the answer is (-1)+1=0.\n\nSample Input 3\n\n30 -50\n\nSample Output 3\n\n-1044", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3520, "cpu_time_ms": 151, "memory_kb": 17764}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s877891585", "group_id": "codeNet:p02995", "input_text": ";m以上n以下でNの倍数の個数を数える\n(defun count-m (m n k)\n (-(floor n k)\n (floor (1- m) k)))\n\n(defun solve (A B C D)\n (let (( E (lcm C D)))\n (- (1+ (- B A))\n (- (+ (count-m A B C)\n\t (count-m A B D))\n\t (count-m A B E)))))\n\n(princ (solve (read) (read) (read) (read)))\n", "language": "Lisp", "metadata": {"date": 1584528447, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p02995.html", "problem_id": "p02995", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p02995/input.txt", "sample_output_relpath": "derived/input_output/data/p02995/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p02995/Lisp/s877891585.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s877891585", "user_id": "u334552723"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";m以上n以下でNの倍数の個数を数える\n(defun count-m (m n k)\n (-(floor n k)\n (floor (1- m) k)))\n\n(defun solve (A B C D)\n (let (( E (lcm C D)))\n (- (1+ (- B A))\n (- (+ (count-m A B C)\n\t (count-m A B D))\n\t (count-m A B E)))))\n\n(princ (solve (read) (read) (read) (read)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.\n\nConstraints\n\n1\\leq A\\leq B\\leq 10^{18}\n\n1\\leq C,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 number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.\n\nSample Input 1\n\n4 9 2 3\n\nSample Output 1\n\n2\n\n5 and 7 satisfy the condition.\n\nSample Input 2\n\n10 40 6 8\n\nSample Output 2\n\n23\n\nSample Input 3\n\n314159265358979323 846264338327950288 419716939 937510582\n\nSample Output 3\n\n532105071133627368", "sample_input": "4 9 2 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p02995", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.\n\nConstraints\n\n1\\leq A\\leq B\\leq 10^{18}\n\n1\\leq C,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 number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.\n\nSample Input 1\n\n4 9 2 3\n\nSample Output 1\n\n2\n\n5 and 7 satisfy the condition.\n\nSample Input 2\n\n10 40 6 8\n\nSample Output 2\n\n23\n\nSample Input 3\n\n314159265358979323 846264338327950288 419716939 937510582\n\nSample Output 3\n\n532105071133627368", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 15, "memory_kb": 4200}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s021896864", "group_id": "codeNet:p02996", "input_text": "(let ((n (read))\n (end 2000000000)\n (lst (make-array 0 :element-type 'list\n :adjustable t\n :fill-pointer 0))\n s-lst)\n (dotimes (i n)\n (vector-push-extend (list (read) (read)) lst))\n (setf s-lst (sort lst #'(lambda (x y) (> (second x) (second y)))))\n (loop for i across s-lst do\n (if (< (second i) end) (setf end (second i)))\n (decf end (first i)))\n (princ (if (< end 0) \"No\" \"Yes\")))\n", "language": "Lisp", "metadata": {"date": 1561294847, "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/s021896864.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s021896864", "user_id": "u994767958"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read))\n (end 2000000000)\n (lst (make-array 0 :element-type 'list\n :adjustable t\n :fill-pointer 0))\n s-lst)\n (dotimes (i n)\n (vector-push-extend (list (read) (read)) lst))\n (setf s-lst (sort lst #'(lambda (x y) (> (second x) (second y)))))\n (loop for i across s-lst do\n (if (< (second i) end) (setf end (second i)))\n (decf end (first i)))\n (princ (if (< end 0) \"No\" \"Yes\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 966, "memory_kb": 65988}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s029060730", "group_id": "codeNet:p02996", "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)\n (let ((l (loop for i below n collect (cons (read) (read))))\n (acc 0))\n (sort l #'< :key #'cdr)\n (format t \"~:[No~;Yes~]\"\n (every #'(lambda (task)\n (incf acc (car task))\n (<= acc (cdr task)))\n l))))\n\n\n(solution-d)\n\n", "language": "Lisp", "metadata": {"date": 1561291396, "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/s029060730.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s029060730", "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 vars\n (mapcar (constantly '(read))\n vars)))\n ,@body)))\n\n(defsolver solution-d (n)\n (let ((l (loop for i below n collect (cons (read) (read))))\n (acc 0))\n (sort l #'< :key #'cdr)\n (format t \"~:[No~;Yes~]\"\n (every #'(lambda (task)\n (incf acc (car task))\n (<= acc (cdr task)))\n l))))\n\n\n(solution-d)\n\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 510, "cpu_time_ms": 938, "memory_kb": 64196}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s039771090", "group_id": "codeNet:p02999", "input_text": "(if (< (read) (read))\n (format t \"0~%\")\n (format t \"10~%\"))\n", "language": "Lisp", "metadata": {"date": 1598798056, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s039771090.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s039771090", "user_id": "u608227593"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(if (< (read) (read))\n (format t \"0~%\")\n (format t \"10~%\"))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 15, "memory_kb": 23100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s403200063", "group_id": "codeNet:p02999", "input_text": "(format t \"~a~%\" (if (< (read) (read)) 0 10))", "language": "Lisp", "metadata": {"date": 1568976595, "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/s403200063.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s403200063", "user_id": "u358554431"}, "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 6, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s215376215", "group_id": "codeNet:p02999", "input_text": "(defun abc130a ()\n (let ((x (read))\n\t(a (read)))\n (if (>= x a)\n\t(format t \"10~%\")\n\t(format t \"0~%\"))))\n\n(abc130a)", "language": "Lisp", "metadata": {"date": 1560713692, "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/s215376215.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s215376215", "user_id": "u777551961"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(defun abc130a ()\n (let ((x (read))\n\t(a (read)))\n (if (>= x a)\n\t(format t \"10~%\")\n\t(format t \"0~%\"))))\n\n(abc130a)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 113, "memory_kb": 11112}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s994307514", "group_id": "codeNet:p02999", "input_text": "(defun split (str)\n (labels ((inner (rest-str-list stack-str-list temp-out)\n (if rest-str-list\n (let ((now-char (car rest-str-list)))\n (cond ((eq #\\space now-char) (inner (cdr rest-str-list)\n '()\n (cons (concatenate 'string (reverse stack-str-list))\n temp-out)))\n (t (inner (cdr rest-str-list)\n (cons now-char stack-str-list)\n temp-out))))\n (reverse (cons (concatenate 'string (reverse stack-str-list))\n temp-out)))))\n (inner (concatenate 'list str)\n '()\n '())))\n\n(defun input-to-list (str)\n (mapcar #'parse-integer (split str)))\n\n(defvar xa (input-to-list (read-line)))\n(format t \"~d\"\n (if (< x a)\n 0\n 10))", "language": "Lisp", "metadata": {"date": 1560712363, "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/s994307514.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s994307514", "user_id": "u250100102"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(defun split (str)\n (labels ((inner (rest-str-list stack-str-list temp-out)\n (if rest-str-list\n (let ((now-char (car rest-str-list)))\n (cond ((eq #\\space now-char) (inner (cdr rest-str-list)\n '()\n (cons (concatenate 'string (reverse stack-str-list))\n temp-out)))\n (t (inner (cdr rest-str-list)\n (cons now-char stack-str-list)\n temp-out))))\n (reverse (cons (concatenate 'string (reverse stack-str-list))\n temp-out)))))\n (inner (concatenate 'list str)\n '()\n '())))\n\n(defun input-to-list (str)\n (mapcar #'parse-integer (split str)))\n\n(defvar xa (input-to-list (read-line)))\n(format t \"~d\"\n (if (< x a)\n 0\n 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1087, "cpu_time_ms": 104, "memory_kb": 12128}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s689720460", "group_id": "codeNet:p03000", "input_text": ";;; Utils\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(defmethod princ-for-each-line ((sequence list))\n (labels ((inner (sequence)\n (if (null sequence)\n (fresh-line)\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 (fresh-line))\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 solve (n x l)\n (let ((cum (make-cumlative-sum l)))\n (length (remove-if-not\n (lambda (pos)\n (<= pos x))\n cum))))\n\n\n(defun main ()\n (let* ((n (read))\n (x (read))\n (l (read-numbers-to-list n)))\n (format t \"~a~%\" (solve n x l))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1598979978, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s689720460.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s689720460", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";;; Utils\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(defmethod princ-for-each-line ((sequence list))\n (labels ((inner (sequence)\n (if (null sequence)\n (fresh-line)\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 (fresh-line))\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 solve (n x l)\n (let ((cum (make-cumlative-sum l)))\n (length (remove-if-not\n (lambda (pos)\n (<= pos x))\n cum))))\n\n\n(defun main ()\n (let* ((n (read))\n (x (read))\n (l (read-numbers-to-list n)))\n (format t \"~a~%\" (solve n x l))))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2672, "cpu_time_ms": 26, "memory_kb": 29144}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s296133782", "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(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": 1560712734, "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/s296133782.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s296133782", "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(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 143, "memory_kb": 15588}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s293497138", "group_id": "codeNet:p03001", "input_text": "(let* ((w (read))\n (h (read))\n (x (read))\n (y (read)))\n (format t \"~F ~A~%\"\n (/ (* w h) 2)\n (if (and (= w (* 2 x)) (= h (* 2 y)))\n 1\n 0)))\n(let* ((w (read))\n (h (read))\n (x (read))\n (y (read)))\n (format t \"~F ~A~%\"\n (/ (* w h) 2)\n (if (and (= w (* 2 x)) (= h (* 2 y)))\n 1\n 0)))\n", "language": "Lisp", "metadata": {"date": 1596373226, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s293497138.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s293497138", "user_id": "u608227593"}, "prompt_components": {"gold_output": "3.000000 0\n", "input_to_evaluate": "(let* ((w (read))\n (h (read))\n (x (read))\n (y (read)))\n (format t \"~F ~A~%\"\n (/ (* w h) 2)\n (if (and (= w (* 2 x)) (= h (* 2 y)))\n 1\n 0)))\n(let* ((w (read))\n (h (read))\n (x (read))\n (y (read)))\n (format t \"~F ~A~%\"\n (/ (* w h) 2)\n (if (and (= w (* 2 x)) (= h (* 2 y)))\n 1\n 0)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 404, "cpu_time_ms": 22, "memory_kb": 24152}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s790128267", "group_id": "codeNet:p03001", "input_text": ";;; Utils (quoted from https://competitive12.blogspot.com/2020/03/common-lisp.html)\n\n\n;; Read fixnum\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;; fast read-line\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\n;;; invoke child process\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; Write code here\n;-------------------\n\n\n\n(defun solve (w h x y)\n (if (and (= (* x 2) w)\n (= (* y 2) h))\n (cons (coerce (/ (* w h) 2) 'double-float) 1)\n (cons (coerce (/ (* w h) 2) 'double-float) 0)))\n\n(defun main ()\n (let ((l (read-from-string (concatenate 'string \"(\" (read-line) \")\"))))\n (destructuring-bind (w h x y) l\n (setq ans (solve w h x y))\n (let ((*read-default-float-format* 'double-float))\n (format t \"~a ~a\" (first ans) (rest ans)))\n (fresh-line))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1596224338, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s790128267.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s790128267", "user_id": "u425762225"}, "prompt_components": {"gold_output": "3.000000 0\n", "input_to_evaluate": ";;; Utils (quoted from https://competitive12.blogspot.com/2020/03/common-lisp.html)\n\n\n;; Read fixnum\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;; fast read-line\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\n;;; invoke child process\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; Write code here\n;-------------------\n\n\n\n(defun solve (w h x y)\n (if (and (= (* x 2) w)\n (= (* y 2) h))\n (cons (coerce (/ (* w h) 2) 'double-float) 1)\n (cons (coerce (/ (* w h) 2) 'double-float) 0)))\n\n(defun main ()\n (let ((l (read-from-string (concatenate 'string \"(\" (read-line) \")\"))))\n (destructuring-bind (w h x y) l\n (setq ans (solve w h x y))\n (let ((*read-default-float-format* 'double-float))\n (format t \"~a ~a\" (first ans) (rest ans)))\n (fresh-line))))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3183, "cpu_time_ms": 39, "memory_kb": 25548}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s619176255", "group_id": "codeNet:p03003", "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(declaim (inline bitree-update!))\n(defun bitree-update! (bitree index1 index2 delta)\n \"destructively increments the array: array[index1][index2] += delta.\"\n (declare ((integer 0 #.most-positive-fixnum) index1 index2))\n (let ((length1 (array-dimension bitree 0))\n (length2 (array-dimension bitree 1)))\n (do ((i index1 (logior i (+ i 1))))\n ((>= i length1))\n (declare (fixnum i))\n (let ((base-i (array-row-major-index bitree i 0)))\n (declare (fixnum base-i))\n (do ((j index2 (logior j (+ j 1))))\n ((>= j length2))\n (declare (fixnum j))\n (setf (row-major-aref bitree (+ base-i j))\n (funcall (lambda (x y) (mod (+ x y) +mod+))\n (row-major-aref bitree (the fixnum (+ base-i j)))\n delta)))))\n bitree))\n \n(declaim (inline bitree-sum))\n(defun bitree-sum (bitree end1 end2)\n \"returns the sum of the rectangle region: array[0][0] + ... +\narray[end1-1][end2-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end1 end2))\n (let ((res 0))\n (declare (type uint62 res))\n (do ((i (- end1 1) (- (logand i (+ i 1)) 1)))\n ((< i 0))\n (declare (fixnum i))\n (let ((base-i (array-row-major-index bitree i 0)))\n (declare (fixnum base-i))\n (do ((j (- end2 1) (- (logand j (+ j 1)) 1)))\n ((< j 0))\n (declare (fixnum j))\n (incf res (row-major-aref bitree (the fixnum (+ base-i j)))))))\n (mod res +mod+)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (ss (make-array n :element-type 'uint32))\n (ts (make-array m :element-type 'uint32))\n (bitree (make-array '(2000 2000) :element-type 'uint32 :initial-element 0)))\n (declare (uint16 n m))\n (dotimes (i n) (setf (aref ss i) (read-fixnum)))\n (dotimes (i m) (setf (aref ts i) (read-fixnum)))\n (dotimes (i n)\n (dotimes (j m)\n (when (= (aref ss i) (aref ts j))\n (bitree-update! bitree i j (+ 1 (bitree-sum bitree i j))))))\n (println (mod (+ 1 (bitree-sum bitree n m)) +mod+))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560891701, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03003.html", "problem_id": "p03003", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03003/input.txt", "sample_output_relpath": "derived/input_output/data/p03003/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03003/Lisp/s619176255.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s619176255", "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(declaim (inline bitree-update!))\n(defun bitree-update! (bitree index1 index2 delta)\n \"destructively increments the array: array[index1][index2] += delta.\"\n (declare ((integer 0 #.most-positive-fixnum) index1 index2))\n (let ((length1 (array-dimension bitree 0))\n (length2 (array-dimension bitree 1)))\n (do ((i index1 (logior i (+ i 1))))\n ((>= i length1))\n (declare (fixnum i))\n (let ((base-i (array-row-major-index bitree i 0)))\n (declare (fixnum base-i))\n (do ((j index2 (logior j (+ j 1))))\n ((>= j length2))\n (declare (fixnum j))\n (setf (row-major-aref bitree (+ base-i j))\n (funcall (lambda (x y) (mod (+ x y) +mod+))\n (row-major-aref bitree (the fixnum (+ base-i j)))\n delta)))))\n bitree))\n \n(declaim (inline bitree-sum))\n(defun bitree-sum (bitree end1 end2)\n \"returns the sum of the rectangle region: array[0][0] + ... +\narray[end1-1][end2-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end1 end2))\n (let ((res 0))\n (declare (type uint62 res))\n (do ((i (- end1 1) (- (logand i (+ i 1)) 1)))\n ((< i 0))\n (declare (fixnum i))\n (let ((base-i (array-row-major-index bitree i 0)))\n (declare (fixnum base-i))\n (do ((j (- end2 1) (- (logand j (+ j 1)) 1)))\n ((< j 0))\n (declare (fixnum j))\n (incf res (row-major-aref bitree (the fixnum (+ base-i j)))))))\n (mod res +mod+)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (ss (make-array n :element-type 'uint32))\n (ts (make-array m :element-type 'uint32))\n (bitree (make-array '(2000 2000) :element-type 'uint32 :initial-element 0)))\n (declare (uint16 n m))\n (dotimes (i n) (setf (aref ss i) (read-fixnum)))\n (dotimes (i m) (setf (aref ts i) (read-fixnum)))\n (dotimes (i n)\n (dotimes (j m)\n (when (= (aref ss i) (aref ts j))\n (bitree-update! bitree i j (+ 1 (bitree-sum bitree i j))))))\n (println (mod (+ 1 (bitree-sum bitree n m)) +mod+))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).\n\nIn how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?\n\nHere the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order.\n\nFor both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSince the answer can be tremendous, print the number modulo 10^9+7.\n\nConstraints\n\n1 \\leq N, M \\leq 2 \\times 10^3\n\nThe length of S is N.\n\nThe length of T is M.\n\n1 \\leq S_i, T_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\nS_1 S_2 ... S_{N-1} S_{N}\nT_1 T_2 ... T_{M-1} T_{M}\n\nOutput\n\nPrint the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7.\n\nSample Input 1\n\n2 2\n1 3\n3 1\n\nSample Output 1\n\n3\n\nS has four subsequences: (), (1), (3), (1, 3).\n\nT has four subsequences: (), (3), (1), (3, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 1 \\times 1 pair of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (3), for a total of three pairs.\n\nSample Input 2\n\n2 2\n1 1\n1 1\n\nSample Output 2\n\n6\n\nS has four subsequences: (), (1), (1), (1, 1).\n\nT has four subsequences: (), (1), (1), (1, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 2 \\times 2 pairs of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (1,1), for a total of six pairs.\nNote again that we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSample Input 3\n\n4 4\n3 4 5 6\n3 4 5 6\n\nSample Output 3\n\n16\n\nSample Input 4\n\n10 9\n9 6 5 7 5 9 8 5 6 7\n8 6 8 5 5 7 9 9 7\n\nSample Output 4\n\n191\n\nSample Input 5\n\n20 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n\nSample Output 5\n\n846527861\n\nBe sure to print the number modulo 10^9+7.", "sample_input": "2 2\n1 3\n3 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03003", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).\n\nIn how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?\n\nHere the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order.\n\nFor both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSince the answer can be tremendous, print the number modulo 10^9+7.\n\nConstraints\n\n1 \\leq N, M \\leq 2 \\times 10^3\n\nThe length of S is N.\n\nThe length of T is M.\n\n1 \\leq S_i, T_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\nS_1 S_2 ... S_{N-1} S_{N}\nT_1 T_2 ... T_{M-1} T_{M}\n\nOutput\n\nPrint the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7.\n\nSample Input 1\n\n2 2\n1 3\n3 1\n\nSample Output 1\n\n3\n\nS has four subsequences: (), (1), (3), (1, 3).\n\nT has four subsequences: (), (3), (1), (3, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 1 \\times 1 pair of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (3), for a total of three pairs.\n\nSample Input 2\n\n2 2\n1 1\n1 1\n\nSample Output 2\n\n6\n\nS has four subsequences: (), (1), (1), (1, 1).\n\nT has four subsequences: (), (1), (1), (1, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 2 \\times 2 pairs of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (1,1), for a total of six pairs.\nNote again that we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSample Input 3\n\n4 4\n3 4 5 6\n3 4 5 6\n\nSample Output 3\n\n16\n\nSample Input 4\n\n10 9\n9 6 5 7 5 9 8 5 6 7\n8 6 8 5 5 7 9 9 7\n\nSample Output 4\n\n191\n\nSample Input 5\n\n20 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n\nSample Output 5\n\n846527861\n\nBe sure to print the number modulo 10^9+7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4508, "cpu_time_ms": 625, "memory_kb": 34532}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s756873052", "group_id": "codeNet:p03003", "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(declaim (inline bitree-update!))\n(defun bitree-update! (bitree index1 index2 delta)\n \"destructively increments the array: array[index1][index2] += delta.\"\n (declare ((integer 0 #.most-positive-fixnum) index1 index2))\n (let ((length1 (array-dimension bitree 0))\n (length2 (array-dimension bitree 1)))\n (do ((i index1 (logior i (+ i 1))))\n ((>= i length1))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (let ((base-i (array-row-major-index bitree i 0)))\n (declare ((integer 0 #.most-positive-fixnum) base-i))\n (do ((j index2 (logior j (+ j 1))))\n ((>= j length2))\n (declare ((integer -1 #.most-positive-fixnum) j))\n (setf (row-major-aref bitree (+ base-i j))\n (funcall (lambda (x y) (mod (+ x y) +mod+))\n (row-major-aref bitree (+ base-i j))\n delta)))))\n bitree))\n \n(declaim (inline bitree-sum))\n(defun bitree-sum (bitree end1 end2)\n \"returns the sum of the rectangle region: array[0][0] + ... +\narray[end1-1][end2-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end1 end2))\n (let ((res 0))\n (declare (type uint62 res))\n (do ((i (- end1 1) (- (logand i (+ i 1)) 1)))\n ((< i 0))\n (declare ((integer -1 4611686018427387903) i))\n (let ((base-i (array-row-major-index bitree i 0)))\n (declare ((integer 0 #.most-positive-fixnum) base-i))\n (do ((j (- end2 1) (- (logand j (+ j 1)) 1)))\n ((< j 0))\n (declare ((integer -1 #.most-positive-fixnum) j))\n (incf res (row-major-aref bitree (the (integer -1 #.most-positive-fixnum) (+ base-i j)))))))\n (mod res +mod+)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (ss (make-array n :element-type 'uint32))\n (ts (make-array m :element-type 'uint32))\n (bitree (make-array '(2000 2000) :element-type 'uint32 :initial-element 0)))\n (declare (uint16 n m))\n (dotimes (i n) (setf (aref ss i) (read-fixnum)))\n (dotimes (i m) (setf (aref ts i) (read-fixnum)))\n (dotimes (i n)\n (dotimes (j m)\n (when (= (aref ss i) (aref ts j))\n (bitree-update! bitree i j (+ 1 (bitree-sum bitree i j))))))\n (println (mod (+ 1 (bitree-sum bitree n m)) +mod+))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560891538, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03003.html", "problem_id": "p03003", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03003/input.txt", "sample_output_relpath": "derived/input_output/data/p03003/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03003/Lisp/s756873052.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s756873052", "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(declaim (inline bitree-update!))\n(defun bitree-update! (bitree index1 index2 delta)\n \"destructively increments the array: array[index1][index2] += delta.\"\n (declare ((integer 0 #.most-positive-fixnum) index1 index2))\n (let ((length1 (array-dimension bitree 0))\n (length2 (array-dimension bitree 1)))\n (do ((i index1 (logior i (+ i 1))))\n ((>= i length1))\n (declare ((integer 0 #.most-positive-fixnum) i))\n (let ((base-i (array-row-major-index bitree i 0)))\n (declare ((integer 0 #.most-positive-fixnum) base-i))\n (do ((j index2 (logior j (+ j 1))))\n ((>= j length2))\n (declare ((integer -1 #.most-positive-fixnum) j))\n (setf (row-major-aref bitree (+ base-i j))\n (funcall (lambda (x y) (mod (+ x y) +mod+))\n (row-major-aref bitree (+ base-i j))\n delta)))))\n bitree))\n \n(declaim (inline bitree-sum))\n(defun bitree-sum (bitree end1 end2)\n \"returns the sum of the rectangle region: array[0][0] + ... +\narray[end1-1][end2-1].\"\n (declare ((integer 0 #.most-positive-fixnum) end1 end2))\n (let ((res 0))\n (declare (type uint62 res))\n (do ((i (- end1 1) (- (logand i (+ i 1)) 1)))\n ((< i 0))\n (declare ((integer -1 4611686018427387903) i))\n (let ((base-i (array-row-major-index bitree i 0)))\n (declare ((integer 0 #.most-positive-fixnum) base-i))\n (do ((j (- end2 1) (- (logand j (+ j 1)) 1)))\n ((< j 0))\n (declare ((integer -1 #.most-positive-fixnum) j))\n (incf res (row-major-aref bitree (the (integer -1 #.most-positive-fixnum) (+ base-i j)))))))\n (mod res +mod+)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (ss (make-array n :element-type 'uint32))\n (ts (make-array m :element-type 'uint32))\n (bitree (make-array '(2000 2000) :element-type 'uint32 :initial-element 0)))\n (declare (uint16 n m))\n (dotimes (i n) (setf (aref ss i) (read-fixnum)))\n (dotimes (i m) (setf (aref ts i) (read-fixnum)))\n (dotimes (i n)\n (dotimes (j m)\n (when (= (aref ss i) (aref ts j))\n (bitree-update! bitree i j (+ 1 (bitree-sum bitree i j))))))\n (println (mod (+ 1 (bitree-sum bitree n m)) +mod+))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).\n\nIn how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?\n\nHere the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order.\n\nFor both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSince the answer can be tremendous, print the number modulo 10^9+7.\n\nConstraints\n\n1 \\leq N, M \\leq 2 \\times 10^3\n\nThe length of S is N.\n\nThe length of T is M.\n\n1 \\leq S_i, T_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\nS_1 S_2 ... S_{N-1} S_{N}\nT_1 T_2 ... T_{M-1} T_{M}\n\nOutput\n\nPrint the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7.\n\nSample Input 1\n\n2 2\n1 3\n3 1\n\nSample Output 1\n\n3\n\nS has four subsequences: (), (1), (3), (1, 3).\n\nT has four subsequences: (), (3), (1), (3, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 1 \\times 1 pair of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (3), for a total of three pairs.\n\nSample Input 2\n\n2 2\n1 1\n1 1\n\nSample Output 2\n\n6\n\nS has four subsequences: (), (1), (1), (1, 1).\n\nT has four subsequences: (), (1), (1), (1, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 2 \\times 2 pairs of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (1,1), for a total of six pairs.\nNote again that we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSample Input 3\n\n4 4\n3 4 5 6\n3 4 5 6\n\nSample Output 3\n\n16\n\nSample Input 4\n\n10 9\n9 6 5 7 5 9 8 5 6 7\n8 6 8 5 5 7 9 9 7\n\nSample Output 4\n\n191\n\nSample Input 5\n\n20 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n\nSample Output 5\n\n846527861\n\nBe sure to print the number modulo 10^9+7.", "sample_input": "2 2\n1 3\n3 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03003", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).\n\nIn how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?\n\nHere the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order.\n\nFor both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSince the answer can be tremendous, print the number modulo 10^9+7.\n\nConstraints\n\n1 \\leq N, M \\leq 2 \\times 10^3\n\nThe length of S is N.\n\nThe length of T is M.\n\n1 \\leq S_i, T_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\nS_1 S_2 ... S_{N-1} S_{N}\nT_1 T_2 ... T_{M-1} T_{M}\n\nOutput\n\nPrint the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7.\n\nSample Input 1\n\n2 2\n1 3\n3 1\n\nSample Output 1\n\n3\n\nS has four subsequences: (), (1), (3), (1, 3).\n\nT has four subsequences: (), (3), (1), (3, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 1 \\times 1 pair of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (3), for a total of three pairs.\n\nSample Input 2\n\n2 2\n1 1\n1 1\n\nSample Output 2\n\n6\n\nS has four subsequences: (), (1), (1), (1, 1).\n\nT has four subsequences: (), (1), (1), (1, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 2 \\times 2 pairs of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (1,1), for a total of six pairs.\nNote again that we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSample Input 3\n\n4 4\n3 4 5 6\n3 4 5 6\n\nSample Output 3\n\n16\n\nSample Input 4\n\n10 9\n9 6 5 7 5 9 8 5 6 7\n8 6 8 5 5 7 9 9 7\n\nSample Output 4\n\n191\n\nSample Input 5\n\n20 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n\nSample Output 5\n\n846527861\n\nBe sure to print the number modulo 10^9+7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4692, "cpu_time_ms": 629, "memory_kb": 37352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s255124170", "group_id": "codeNet:p03003", "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(declaim (inline bitree-update!))\n(defun bitree-update! (bitree index1 index2 delta)\n \"destructively increments the array: array[index1][index2] += delta.\"\n (let ((length1 (array-dimension bitree 0))\n (length2 (array-dimension bitree 1)))\n (do ((i index1 (logior i (+ i 1))))\n ((>= i length1))\n (declare ((integer 0 4611686018427387903) i))\n (do ((j index2 (logior j (+ j 1))))\n ((>= j length2))\n (setf (aref bitree i j)\n (funcall (lambda (x y) (mod (+ x y) +mod+)) (aref bitree i j)\n delta))))\n bitree))\n\n(declaim (inline bitree-sum))\n(defun bitree-sum (bitree end1 end2)\n \"returns the sum of the rectangle region: array[0][0] + ... +\narray[end1-1][end2-1].\"\n (declare ((integer 0 4611686018427387903) end1 end2))\n (let ((res 0))\n (declare (type uint62 res))\n (do ((i (- end1 1) (- (logand i (+ i 1)) 1)))\n ((< i 0))\n (declare ((integer -1 4611686018427387903) i))\n (do ((j (- end2 1) (- (logand j (+ j 1)) 1)))\n ((< j 0))\n (incf res (aref bitree i j))))\n (mod res +mod+)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (ss (make-array n :element-type 'uint32))\n (ts (make-array m :element-type 'uint32))\n (bitree (make-array '(2000 2000) :element-type 'uint32 :initial-element 0)))\n (declare (uint16 n m))\n (dotimes (i n) (setf (aref ss i) (read-fixnum)))\n (dotimes (i m) (setf (aref ts i) (read-fixnum)))\n (dotimes (i n)\n (dotimes (j m)\n (when (= (aref ss i) (aref ts j))\n (bitree-update! bitree i j (+ 1 (bitree-sum bitree i j))))))\n (println (mod (+ 1 (bitree-sum bitree n m)) +mod+))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560758346, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03003.html", "problem_id": "p03003", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03003/input.txt", "sample_output_relpath": "derived/input_output/data/p03003/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03003/Lisp/s255124170.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s255124170", "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(declaim (inline bitree-update!))\n(defun bitree-update! (bitree index1 index2 delta)\n \"destructively increments the array: array[index1][index2] += delta.\"\n (let ((length1 (array-dimension bitree 0))\n (length2 (array-dimension bitree 1)))\n (do ((i index1 (logior i (+ i 1))))\n ((>= i length1))\n (declare ((integer 0 4611686018427387903) i))\n (do ((j index2 (logior j (+ j 1))))\n ((>= j length2))\n (setf (aref bitree i j)\n (funcall (lambda (x y) (mod (+ x y) +mod+)) (aref bitree i j)\n delta))))\n bitree))\n\n(declaim (inline bitree-sum))\n(defun bitree-sum (bitree end1 end2)\n \"returns the sum of the rectangle region: array[0][0] + ... +\narray[end1-1][end2-1].\"\n (declare ((integer 0 4611686018427387903) end1 end2))\n (let ((res 0))\n (declare (type uint62 res))\n (do ((i (- end1 1) (- (logand i (+ i 1)) 1)))\n ((< i 0))\n (declare ((integer -1 4611686018427387903) i))\n (do ((j (- end2 1) (- (logand j (+ j 1)) 1)))\n ((< j 0))\n (incf res (aref bitree i j))))\n (mod res +mod+)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (ss (make-array n :element-type 'uint32))\n (ts (make-array m :element-type 'uint32))\n (bitree (make-array '(2000 2000) :element-type 'uint32 :initial-element 0)))\n (declare (uint16 n m))\n (dotimes (i n) (setf (aref ss i) (read-fixnum)))\n (dotimes (i m) (setf (aref ts i) (read-fixnum)))\n (dotimes (i n)\n (dotimes (j m)\n (when (= (aref ss i) (aref ts j))\n (bitree-update! bitree i j (+ 1 (bitree-sum bitree i j))))))\n (println (mod (+ 1 (bitree-sum bitree n m)) +mod+))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).\n\nIn how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?\n\nHere the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order.\n\nFor both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSince the answer can be tremendous, print the number modulo 10^9+7.\n\nConstraints\n\n1 \\leq N, M \\leq 2 \\times 10^3\n\nThe length of S is N.\n\nThe length of T is M.\n\n1 \\leq S_i, T_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\nS_1 S_2 ... S_{N-1} S_{N}\nT_1 T_2 ... T_{M-1} T_{M}\n\nOutput\n\nPrint the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7.\n\nSample Input 1\n\n2 2\n1 3\n3 1\n\nSample Output 1\n\n3\n\nS has four subsequences: (), (1), (3), (1, 3).\n\nT has four subsequences: (), (3), (1), (3, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 1 \\times 1 pair of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (3), for a total of three pairs.\n\nSample Input 2\n\n2 2\n1 1\n1 1\n\nSample Output 2\n\n6\n\nS has four subsequences: (), (1), (1), (1, 1).\n\nT has four subsequences: (), (1), (1), (1, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 2 \\times 2 pairs of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (1,1), for a total of six pairs.\nNote again that we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSample Input 3\n\n4 4\n3 4 5 6\n3 4 5 6\n\nSample Output 3\n\n16\n\nSample Input 4\n\n10 9\n9 6 5 7 5 9 8 5 6 7\n8 6 8 5 5 7 9 9 7\n\nSample Output 4\n\n191\n\nSample Input 5\n\n20 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n\nSample Output 5\n\n846527861\n\nBe sure to print the number modulo 10^9+7.", "sample_input": "2 2\n1 3\n3 1\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03003", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).\n\nIn how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?\n\nHere the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order.\n\nFor both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSince the answer can be tremendous, print the number modulo 10^9+7.\n\nConstraints\n\n1 \\leq N, M \\leq 2 \\times 10^3\n\nThe length of S is N.\n\nThe length of T is M.\n\n1 \\leq S_i, T_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\nS_1 S_2 ... S_{N-1} S_{N}\nT_1 T_2 ... T_{M-1} T_{M}\n\nOutput\n\nPrint the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7.\n\nSample Input 1\n\n2 2\n1 3\n3 1\n\nSample Output 1\n\n3\n\nS has four subsequences: (), (1), (3), (1, 3).\n\nT has four subsequences: (), (3), (1), (3, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 1 \\times 1 pair of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (3), for a total of three pairs.\n\nSample Input 2\n\n2 2\n1 1\n1 1\n\nSample Output 2\n\n6\n\nS has four subsequences: (), (1), (1), (1, 1).\n\nT has four subsequences: (), (1), (1), (1, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both (), 2 \\times 2 pairs of subsequences in which the subsequences are both (1), and 1 \\times 1 pair of subsequences in which the subsequences are both (1,1), for a total of six pairs.\nNote again that we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.\n\nSample Input 3\n\n4 4\n3 4 5 6\n3 4 5 6\n\nSample Output 3\n\n16\n\nSample Input 4\n\n10 9\n9 6 5 7 5 9 8 5 6 7\n8 6 8 5 5 7 9 9 7\n\nSample Output 4\n\n191\n\nSample Input 5\n\n20 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n\nSample Output 5\n\n846527861\n\nBe sure to print the number modulo 10^9+7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4122, "cpu_time_ms": 671, "memory_kb": 33256}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s266392526", "group_id": "codeNet:p03004", "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 (xs- (make-array 0 :fill-pointer 0 :element-type 'int32))\n (xs0 (make-array 0 :fill-pointer 0 :element-type 'int32))\n (xs+ (make-array 0 :fill-pointer 0 :element-type 'int32))\n (ys- (make-array 0 :fill-pointer 0 :element-type 'int32))\n (ys0 (make-array 0 :fill-pointer 0 :element-type 'int32))\n (ys+ (make-array 0 :fill-pointer 0 :element-type 'int32)))\n (dotimes (i n)\n (let ((x (read-fixnum))\n (y (read-fixnum))\n (d (read-char)))\n (case d\n (#\\R\n (vector-push-extend x xs+)\n (vector-push-extend y ys0))\n (#\\L\n (vector-push-extend x xs-)\n (vector-push-extend y ys0))\n (#\\U\n (vector-push-extend x xs0)\n (vector-push-extend y ys+))\n (#\\D\n (vector-push-extend x xs0)\n (vector-push-extend y ys-)))))\n (let ((xmax+ (reduce #'max xs+ :initial-value most-negative-fixnum))\n (xmax- (reduce #'max xs- :initial-value most-negative-fixnum))\n (ymax+ (reduce #'max ys+ :initial-value most-negative-fixnum))\n (ymax- (reduce #'max ys- :initial-value most-negative-fixnum))\n (xmax0 (reduce #'max xs0 :initial-value most-negative-fixnum))\n (ymax0 (reduce #'max ys0 :initial-value most-negative-fixnum))\n (xmin+ (reduce #'min xs+ :initial-value most-positive-fixnum))\n (xmin- (reduce #'min xs- :initial-value most-positive-fixnum))\n (ymin+ (reduce #'min ys+ :initial-value most-positive-fixnum))\n (ymin- (reduce #'min ys- :initial-value most-positive-fixnum))\n (xmin0 (reduce #'min xs0 :initial-value most-positive-fixnum))\n (ymin0 (reduce #'min ys0 :initial-value most-positive-fixnum)))\n (let ((t1 (* 0.5d0 (- xmax- xmax+)))\n (t2 (* 0.5d0 (- xmin- xmin+)))\n (t3 (* 0.5d0 (- ymax- ymax+)))\n (t4 (* 0.5d0 (- ymin- ymin+)))\n (t5 xmax0)\n (t6 xmin0)\n (t7 ymax0)\n (t8 ymin0))\n (println\n (min (* (- (max (- xmax- t1) (+ xmax+ t1) xmax0)\n (min (- xmin- t1) (+ xmin+ t1) xmin0))\n (- (max (- ymax- t1) (+ ymax+ t1) ymax0)\n (min (- ymin- t1) (+ ymin+ t1) ymin0)))\n (* (- (max (- xmax- t2) (+ xmax+ t2) xmax0)\n (min (- xmin- t2) (+ xmin+ t2) xmin0))\n (- (max (- ymax- t2) (+ ymax+ t2) ymax0)\n (min (- ymin- t2) (+ ymin+ t2) ymin0)))\n (* (- (max (- xmax- t3) (+ xmax+ t3) xmax0)\n (min (- xmin- t3) (+ xmin+ t3) xmin0))\n (- (max (- ymax- t3) (+ ymax+ t3) ymax0)\n (min (- ymin- t3) (+ ymin+ t3) ymin0)))\n (* (- (max (- xmax- t4) (+ xmax+ t4) xmax0)\n (min (- xmin- t4) (+ xmin+ t4) xmin0))\n (- (max (- ymax- t4) (+ ymax+ t4) ymax0)\n (min (- ymin- t4) (+ ymin+ t4) ymin0)))\n (* (- (max (- xmax- t5) (+ xmax+ t5) xmax0)\n (min (- xmin- t5) (+ xmin+ t5) xmin0))\n (- (max (- ymax- t5) (+ ymax+ t5) ymax0)\n (min (- ymin- t5) (+ ymin+ t5) ymin0)))\n (* (- (max (- xmax- t6) (+ xmax+ t6) xmax0)\n (min (- xmin- t6) (+ xmin+ t6) xmin0))\n (- (max (- ymax- t6) (+ ymax+ t6) ymax0)\n (min (- ymin- t6) (+ ymin+ t6) ymin0)))\n (* (- (max (- xmax- t7) (+ xmax+ t7) xmax0)\n (min (- xmin- t7) (+ xmin+ t7) xmin0))\n (- (max (- ymax- t7) (+ ymax+ t7) ymax0)\n (min (- ymin- t7) (+ ymin+ t7) ymin0)))\n (* (- (max (- xmax- t8) (+ xmax+ t8) xmax0)\n (min (- xmin- t8) (+ xmin+ t8) xmin0))\n (- (max (- ymax- t8) (+ ymax+ t8) ymax0)\n (min (- ymin- t8) (+ ymin+ t8) ymin0)))))))))\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\n0 3 D\n3 0 L\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n-7 -10 U\n7 -6 U\n-8 7 D\n-3 3 D\n0 -6 R\n\"\n \"97.5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20\n6 -10 R\n-4 -9 U\n9 6 D\n-3 -2 R\n0 7 D\n4 5 D\n10 -10 U\n-1 -8 U\n10 -6 D\n8 -5 U\n6 4 D\n0 3 D\n7 9 R\n9 -4 R\n3 10 D\n1 9 U\n1 -6 U\n9 -8 R\n6 7 D\n7 -3 D\n\"\n \"273\n\")))\n", "language": "Lisp", "metadata": {"date": 1560739227, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03004.html", "problem_id": "p03004", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03004/input.txt", "sample_output_relpath": "derived/input_output/data/p03004/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03004/Lisp/s266392526.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s266392526", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\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 (xs- (make-array 0 :fill-pointer 0 :element-type 'int32))\n (xs0 (make-array 0 :fill-pointer 0 :element-type 'int32))\n (xs+ (make-array 0 :fill-pointer 0 :element-type 'int32))\n (ys- (make-array 0 :fill-pointer 0 :element-type 'int32))\n (ys0 (make-array 0 :fill-pointer 0 :element-type 'int32))\n (ys+ (make-array 0 :fill-pointer 0 :element-type 'int32)))\n (dotimes (i n)\n (let ((x (read-fixnum))\n (y (read-fixnum))\n (d (read-char)))\n (case d\n (#\\R\n (vector-push-extend x xs+)\n (vector-push-extend y ys0))\n (#\\L\n (vector-push-extend x xs-)\n (vector-push-extend y ys0))\n (#\\U\n (vector-push-extend x xs0)\n (vector-push-extend y ys+))\n (#\\D\n (vector-push-extend x xs0)\n (vector-push-extend y ys-)))))\n (let ((xmax+ (reduce #'max xs+ :initial-value most-negative-fixnum))\n (xmax- (reduce #'max xs- :initial-value most-negative-fixnum))\n (ymax+ (reduce #'max ys+ :initial-value most-negative-fixnum))\n (ymax- (reduce #'max ys- :initial-value most-negative-fixnum))\n (xmax0 (reduce #'max xs0 :initial-value most-negative-fixnum))\n (ymax0 (reduce #'max ys0 :initial-value most-negative-fixnum))\n (xmin+ (reduce #'min xs+ :initial-value most-positive-fixnum))\n (xmin- (reduce #'min xs- :initial-value most-positive-fixnum))\n (ymin+ (reduce #'min ys+ :initial-value most-positive-fixnum))\n (ymin- (reduce #'min ys- :initial-value most-positive-fixnum))\n (xmin0 (reduce #'min xs0 :initial-value most-positive-fixnum))\n (ymin0 (reduce #'min ys0 :initial-value most-positive-fixnum)))\n (let ((t1 (* 0.5d0 (- xmax- xmax+)))\n (t2 (* 0.5d0 (- xmin- xmin+)))\n (t3 (* 0.5d0 (- ymax- ymax+)))\n (t4 (* 0.5d0 (- ymin- ymin+)))\n (t5 xmax0)\n (t6 xmin0)\n (t7 ymax0)\n (t8 ymin0))\n (println\n (min (* (- (max (- xmax- t1) (+ xmax+ t1) xmax0)\n (min (- xmin- t1) (+ xmin+ t1) xmin0))\n (- (max (- ymax- t1) (+ ymax+ t1) ymax0)\n (min (- ymin- t1) (+ ymin+ t1) ymin0)))\n (* (- (max (- xmax- t2) (+ xmax+ t2) xmax0)\n (min (- xmin- t2) (+ xmin+ t2) xmin0))\n (- (max (- ymax- t2) (+ ymax+ t2) ymax0)\n (min (- ymin- t2) (+ ymin+ t2) ymin0)))\n (* (- (max (- xmax- t3) (+ xmax+ t3) xmax0)\n (min (- xmin- t3) (+ xmin+ t3) xmin0))\n (- (max (- ymax- t3) (+ ymax+ t3) ymax0)\n (min (- ymin- t3) (+ ymin+ t3) ymin0)))\n (* (- (max (- xmax- t4) (+ xmax+ t4) xmax0)\n (min (- xmin- t4) (+ xmin+ t4) xmin0))\n (- (max (- ymax- t4) (+ ymax+ t4) ymax0)\n (min (- ymin- t4) (+ ymin+ t4) ymin0)))\n (* (- (max (- xmax- t5) (+ xmax+ t5) xmax0)\n (min (- xmin- t5) (+ xmin+ t5) xmin0))\n (- (max (- ymax- t5) (+ ymax+ t5) ymax0)\n (min (- ymin- t5) (+ ymin+ t5) ymin0)))\n (* (- (max (- xmax- t6) (+ xmax+ t6) xmax0)\n (min (- xmin- t6) (+ xmin+ t6) xmin0))\n (- (max (- ymax- t6) (+ ymax+ t6) ymax0)\n (min (- ymin- t6) (+ ymin+ t6) ymin0)))\n (* (- (max (- xmax- t7) (+ xmax+ t7) xmax0)\n (min (- xmin- t7) (+ xmin+ t7) xmin0))\n (- (max (- ymax- t7) (+ ymax+ t7) ymax0)\n (min (- ymin- t7) (+ ymin+ t7) ymin0)))\n (* (- (max (- xmax- t8) (+ xmax+ t8) xmax0)\n (min (- xmin- t8) (+ xmin+ t8) xmin0))\n (- (max (- ymax- t8) (+ ymax+ t8) ymax0)\n (min (- ymin- t8) (+ ymin+ t8) ymin0)))))))))\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\n0 3 D\n3 0 L\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n-7 -10 U\n7 -6 U\n-8 7 D\n-3 3 D\n0 -6 R\n\"\n \"97.5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20\n6 -10 R\n-4 -9 U\n9 6 D\n-3 -2 R\n0 7 D\n4 5 D\n10 -10 U\n-1 -8 U\n10 -6 D\n8 -5 U\n6 4 D\n0 3 D\n7 9 R\n9 -4 R\n3 10 D\n1 9 U\n1 -6 U\n9 -8 R\n6 7 D\n7 -3 D\n\"\n \"273\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are N points in a two-dimensional plane. The initial coordinates of the i-th point are (x_i, y_i). Now, each point starts moving at a speed of 1 per second, in a direction parallel to the x- or y- axis. You are given a character d_i that represents the specific direction in which the i-th point moves, as follows:\n\nIf d_i = R, the i-th point moves in the positive x direction;\n\nIf d_i = L, the i-th point moves in the negative x direction;\n\nIf d_i = U, the i-th point moves in the positive y direction;\n\nIf d_i = D, the i-th point moves in the negative y direction.\n\nYou can stop all the points at some moment of your choice after they start moving (including the moment they start moving).\nThen, let x_{max} and x_{min} be the maximum and minimum among the x-coordinates of the N points, respectively. Similarly, let y_{max} and y_{min} be the maximum and minimum among the y-coordinates of the N points, respectively.\n\nFind the minimum possible value of (x_{max} - x_{min}) \\times (y_{max} - y_{min}) and print it.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n-10^8 \\leq x_i,\\ y_i \\leq 10^8\n\nx_i and y_i are integers.\n\nd_i is R, L, U, or D.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1 d_1\nx_2 y_2 d_2\n.\n.\n.\nx_N y_N d_N\n\nOutput\n\nPrint the minimum possible value of (x_{max} - x_{min}) \\times (y_{max} - y_{min}).\n\nThe output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-9}.\n\nSample Input 1\n\n2\n0 3 D\n3 0 L\n\nSample Output 1\n\n0\n\nAfter three seconds, the two points will meet at the origin. The value in question will be 0 at that moment.\n\nSample Input 2\n\n5\n-7 -10 U\n7 -6 U\n-8 7 D\n-3 3 D\n0 -6 R\n\nSample Output 2\n\n97.5\n\nThe answer may not be an integer.\n\nSample Input 3\n\n20\n6 -10 R\n-4 -9 U\n9 6 D\n-3 -2 R\n0 7 D\n4 5 D\n10 -10 U\n-1 -8 U\n10 -6 D\n8 -5 U\n6 4 D\n0 3 D\n7 9 R\n9 -4 R\n3 10 D\n1 9 U\n1 -6 U\n9 -8 R\n6 7 D\n7 -3 D\n\nSample Output 3\n\n273", "sample_input": "2\n0 3 D\n3 0 L\n"}, "reference_outputs": ["0\n"], "source_document_id": "p03004", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are N points in a two-dimensional plane. The initial coordinates of the i-th point are (x_i, y_i). Now, each point starts moving at a speed of 1 per second, in a direction parallel to the x- or y- axis. You are given a character d_i that represents the specific direction in which the i-th point moves, as follows:\n\nIf d_i = R, the i-th point moves in the positive x direction;\n\nIf d_i = L, the i-th point moves in the negative x direction;\n\nIf d_i = U, the i-th point moves in the positive y direction;\n\nIf d_i = D, the i-th point moves in the negative y direction.\n\nYou can stop all the points at some moment of your choice after they start moving (including the moment they start moving).\nThen, let x_{max} and x_{min} be the maximum and minimum among the x-coordinates of the N points, respectively. Similarly, let y_{max} and y_{min} be the maximum and minimum among the y-coordinates of the N points, respectively.\n\nFind the minimum possible value of (x_{max} - x_{min}) \\times (y_{max} - y_{min}) and print it.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n-10^8 \\leq x_i,\\ y_i \\leq 10^8\n\nx_i and y_i are integers.\n\nd_i is R, L, U, or D.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 y_1 d_1\nx_2 y_2 d_2\n.\n.\n.\nx_N y_N d_N\n\nOutput\n\nPrint the minimum possible value of (x_{max} - x_{min}) \\times (y_{max} - y_{min}).\n\nThe output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-9}.\n\nSample Input 1\n\n2\n0 3 D\n3 0 L\n\nSample Output 1\n\n0\n\nAfter three seconds, the two points will meet at the origin. The value in question will be 0 at that moment.\n\nSample Input 2\n\n5\n-7 -10 U\n7 -6 U\n-8 7 D\n-3 3 D\n0 -6 R\n\nSample Output 2\n\n97.5\n\nThe answer may not be an integer.\n\nSample Input 3\n\n20\n6 -10 R\n-4 -9 U\n9 6 D\n-3 -2 R\n0 7 D\n4 5 D\n10 -10 U\n-1 -8 U\n10 -6 D\n8 -5 U\n6 4 D\n0 3 D\n7 9 R\n9 -4 R\n3 10 D\n1 9 U\n1 -6 U\n9 -8 R\n6 7 D\n7 -3 D\n\nSample Output 3\n\n273", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8565, "cpu_time_ms": 253, "memory_kb": 42592}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s536428918", "group_id": "codeNet:p03005", "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(defparameter nk (input-to-list (read-line)))\n(if (eq 1 (cadr nk))\n 0\n (- (car nk) (cadr nk)))", "language": "Lisp", "metadata": {"date": 1560648562, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03005.html", "problem_id": "p03005", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03005/input.txt", "sample_output_relpath": "derived/input_output/data/p03005/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03005/Lisp/s536428918.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s536428918", "user_id": "u250100102"}, "prompt_components": {"gold_output": "1\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(defparameter nk (input-to-list (read-line)))\n(if (eq 1 (cadr nk))\n 0\n (- (car nk) (cadr nk)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nTakahashi is distributing N balls to K persons.\n\nIf each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?\n\nConstraints\n\n1 \\leq K \\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 K\n\nOutput\n\nPrint the maximum possible difference in the number of balls received.\n\nSample Input 1\n\n3 2\n\nSample Output 1\n\n1\n\nThe only way to distribute three balls to two persons so that each of them receives at least one ball is to give one ball to one person and give two balls to the other person.\n\nThus, the maximum possible difference in the number of balls received is 1.\n\nSample Input 2\n\n3 1\n\nSample Output 2\n\n0\n\nWe have no choice but to give three balls to the only person, in which case the difference in the number of balls received is 0.\n\nSample Input 3\n\n8 5\n\nSample Output 3\n\n3\n\nFor example, if we give 1, 4, 1, 1, 1 balls to the five persons, the number of balls received between the person with the most balls and the person with the fewest balls would be 3, which is the maximum result.", "sample_input": "3 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03005", "source_text": "Score : 100 points\n\nProblem Statement\n\nTakahashi is distributing N balls to K persons.\n\nIf each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?\n\nConstraints\n\n1 \\leq K \\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 K\n\nOutput\n\nPrint the maximum possible difference in the number of balls received.\n\nSample Input 1\n\n3 2\n\nSample Output 1\n\n1\n\nThe only way to distribute three balls to two persons so that each of them receives at least one ball is to give one ball to one person and give two balls to the other person.\n\nThus, the maximum possible difference in the number of balls received is 1.\n\nSample Input 2\n\n3 1\n\nSample Output 2\n\n0\n\nWe have no choice but to give three balls to the only person, in which case the difference in the number of balls received is 0.\n\nSample Input 3\n\n8 5\n\nSample Output 3\n\n3\n\nFor example, if we give 1, 4, 1, 1, 1 balls to the five persons, the number of balls received between the person with the most balls and the person with the fewest balls would be 3, which is the maximum result.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 747, "cpu_time_ms": 93, "memory_kb": 10340}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s940807318", "group_id": "codeNet:p03011", "input_text": "(let* ((a (sort (list (read) (read) (read)) #'<) ))\n (princ (+ (first a) (second a))))", "language": "Lisp", "metadata": {"date": 1560128542, "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/s940807318.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s940807318", "user_id": "u610490393"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let* ((a (sort (list (read) (read) (read)) #'<) ))\n (princ (+ (first a) (second a))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 90, "memory_kb": 9696}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s003372836", "group_id": "codeNet:p03012", "input_text": "(defun sum(lis)\n (eval (cons '+ lis)))\n\n(defun read-list(N &optional (l nil))\n (if (<= N 0) l (read-list (1- N) (cons (read) l))))\n\n\n(defun solve(l &optional (p (sum l)))\n (let ((n (- p (* 2 (car l)))))\n (if (< (abs p) (abs n)) (abs p)\n (solve (cdr l) n))))\n\n(princ (solve (read-list (read))))", "language": "Lisp", "metadata": {"date": 1584369146, "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/s003372836.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s003372836", "user_id": "u334552723"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(defun sum(lis)\n (eval (cons '+ lis)))\n\n(defun read-list(N &optional (l nil))\n (if (<= N 0) l (read-list (1- N) (cons (read) l))))\n\n\n(defun solve(l &optional (p (sum l)))\n (let ((n (- p (* 2 (car l)))))\n (if (< (abs p) (abs n)) (abs p)\n (solve (cdr l) n))))\n\n(princ (solve (read-list (read))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 305, "cpu_time_ms": 15, "memory_kb": 4072}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s588925335", "group_id": "codeNet:p03012", "input_text": "(defun abc129b ()\n (let* ((n (read))\n\t (sa 10000)\n\t (wn (loop repeat n\n\t\tcollect (read))))\n (loop for i from 1 below n\n do (let* ((wa1 (apply #'+ (subseq wn 0 i)))\n\t\t (wa2 (apply #'+ (subseq wn i)))\n\t\t (sai (abs (- wa1 wa2))))\n\t (when (> sa sai)\n\t (setf sa sai))))\n (format t \"~d~%\" sa)))\n\n(abc129b)", "language": "Lisp", "metadata": {"date": 1560129781, "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/s588925335.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s588925335", "user_id": "u777551961"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(defun abc129b ()\n (let* ((n (read))\n\t (sa 10000)\n\t (wn (loop repeat n\n\t\tcollect (read))))\n (loop for i from 1 below n\n do (let* ((wa1 (apply #'+ (subseq wn 0 i)))\n\t\t (wa2 (apply #'+ (subseq wn i)))\n\t\t (sai (abs (- wa1 wa2))))\n\t (when (> sa sai)\n\t (setf sa sai))))\n (format t \"~d~%\" sa)))\n\n(abc129b)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 320, "cpu_time_ms": 163, "memory_kb": 16228}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s465451359", "group_id": "codeNet:p03012", "input_text": "(let* ((a (read))\n (lst (loop :repeat a :collect (read)))\n (tt (reduce #'+ lst)))\n (princ (reduce #'min (maplist (lambda (k) (abs (- (reduce #'+ k) (- tt (reduce #'+ k))))) lst))))", "language": "Lisp", "metadata": {"date": 1560128824, "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/s465451359.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s465451359", "user_id": "u610490393"}, "prompt_components": {"gold_output": "0\n", "input_to_evaluate": "(let* ((a (read))\n (lst (loop :repeat a :collect (read)))\n (tt (reduce #'+ lst)))\n (princ (reduce #'min (maplist (lambda (k) (abs (- (reduce #'+ k) (- tt (reduce #'+ k))))) lst))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 138, "memory_kb": 13408}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s894753406", "group_id": "codeNet:p03013", "input_text": "(defun memo (fn)\n (declare (type function fn))\n (let ((table (make-hash-table :test 'equal)))\n #'(lambda (&rest rest)\n (multiple-value-bind (val found-p) (gethash rest table)\n (if found-p\n val\n (setf (gethash rest table) (apply fn rest)))))))\n\n(defun memoize (fn-name)\n (declare (type symbol fn-name))\n (setf (symbol-function fn-name) (memo (symbol-function fn-name))))\n\n(defmacro defun-memo (fn args &body body)\n `(memoize (defun ,fn ,args . ,body)))\n\n(defvar *mod* 1000000007)\n(defparameter *unuse-lst* '())\n\n(defun-memo find-element (elem)\n (declare (type fixnum elem))\n (not (null (find elem *unuse-lst*))))\n\n(defun-memo rec (goal now)\n (declare (type fixnum goal now))\n (cond ((eq goal now) 1)\n ((< goal now) 0)\n ((find-element now) 0)\n (t (+ (rec goal (+ 1 now))\n (rec goal (+ 2 now))))))\n\n(defun solve (goal)\n (declare (type fixnum goal))\n (let ((result (the fixnum (rec goal 0))))\n (print (rem result *mod*))))\n\n(let ((goal (read))\n (num (read)))\n (dotimes (i num)\n (push (read) *unuse-lst*))\n (solve goal))\n", "language": "Lisp", "metadata": {"date": 1560447399, "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/s894753406.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s894753406", "user_id": "u761519515"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun memo (fn)\n (declare (type function fn))\n (let ((table (make-hash-table :test 'equal)))\n #'(lambda (&rest rest)\n (multiple-value-bind (val found-p) (gethash rest table)\n (if found-p\n val\n (setf (gethash rest table) (apply fn rest)))))))\n\n(defun memoize (fn-name)\n (declare (type symbol fn-name))\n (setf (symbol-function fn-name) (memo (symbol-function fn-name))))\n\n(defmacro defun-memo (fn args &body body)\n `(memoize (defun ,fn ,args . ,body)))\n\n(defvar *mod* 1000000007)\n(defparameter *unuse-lst* '())\n\n(defun-memo find-element (elem)\n (declare (type fixnum elem))\n (not (null (find elem *unuse-lst*))))\n\n(defun-memo rec (goal now)\n (declare (type fixnum goal now))\n (cond ((eq goal now) 1)\n ((< goal now) 0)\n ((find-element now) 0)\n (t (+ (rec goal (+ 1 now))\n (rec goal (+ 2 now))))))\n\n(defun solve (goal)\n (declare (type fixnum goal))\n (let ((result (the fixnum (rec goal 0))))\n (print (rem result *mod*))))\n\n(let ((goal (read))\n (num (read)))\n (dotimes (i num)\n (push (read) *unuse-lst*))\n (solve goal))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1191, "cpu_time_ms": 2104, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s311507367", "group_id": "codeNet:p03013", "input_text": "(defun memo (fn)\n (let ((table (make-hash-table :test 'equal)))\n #'(lambda (&rest rest)\n (multiple-value-bind (val found-p) (gethash rest table)\n (if found-p\n val\n (setf (gethash rest table) (apply fn rest)))))))\n\n(defun memoize (fn-name)\n (setf (symbol-function fn-name) (memo (symbol-function fn-name))))\n\n(defmacro defun-memo (fn args &body body)\n `(memoize (defun ,fn ,args . ,body)))\n\n(defvar *mod* 1000000007)\n\n(defun-memo rec (goal unuse-lst now)\n (cond ((eq goal now) 1)\n ((< goal now) 0)\n ((not (null (find now unuse-lst))) 0)\n (t (+ (rec goal unuse-lst (+ 1 now))\n (rec goal unuse-lst (+ 2 now))))))\n\n(defun solve (goal unuse-lst)\n (let ((result (rec goal unuse-lst 0)))\n (print (mod result *mod*))))\n\n(let ((goal (read))\n (num (read))\n (lst '()))\n (dotimes (i num)\n (push (read) lst))\n (solve goal lst))\n", "language": "Lisp", "metadata": {"date": 1560437571, "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/s311507367.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s311507367", "user_id": "u761519515"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defun memo (fn)\n (let ((table (make-hash-table :test 'equal)))\n #'(lambda (&rest rest)\n (multiple-value-bind (val found-p) (gethash rest table)\n (if found-p\n val\n (setf (gethash rest table) (apply fn rest)))))))\n\n(defun memoize (fn-name)\n (setf (symbol-function fn-name) (memo (symbol-function fn-name))))\n\n(defmacro defun-memo (fn args &body body)\n `(memoize (defun ,fn ,args . ,body)))\n\n(defvar *mod* 1000000007)\n\n(defun-memo rec (goal unuse-lst now)\n (cond ((eq goal now) 1)\n ((< goal now) 0)\n ((not (null (find now unuse-lst))) 0)\n (t (+ (rec goal unuse-lst (+ 1 now))\n (rec goal unuse-lst (+ 2 now))))))\n\n(defun solve (goal unuse-lst)\n (let ((result (rec goal unuse-lst 0)))\n (print (mod result *mod*))))\n\n(let ((goal (read))\n (num (read))\n (lst '()))\n (dotimes (i num)\n (push (read) lst))\n (solve goal lst))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 980, "cpu_time_ms": 2105, "memory_kb": 89700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s448956479", "group_id": "codeNet:p03013", "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(defconstant *mod* 1000000007)\n(defvar n (read))\n(defvar m (read))\n(defvar fib\n (make-array (1+ n)))\n\n(vref fib 0 1)\n(vref fib 1 1)\n(loop for i from 2 to n\n do (vref fib i (mod\n (+ (vref fib (1- i))\n (vref fib (- i 2)))\n *mod*)))\n(vref fib 1 0)\n\n\n(defun main ()\n (let ((ans 1) (pos 0) next)\n (dotimes (i m)\n (setf next (1- (read)))\n (if (< (- next pos) 0)\n (setf ans 0)\n (setf ans (mod (* ans (vref fib (- next pos))) *mod*)))\n (setf pos (+ 2 next)))\n (setf ans (mod (* ans (vref fib (- n pos))) *mod*))\n (println ans)))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560132845, "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/s448956479.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s448956479", "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(defconstant *mod* 1000000007)\n(defvar n (read))\n(defvar m (read))\n(defvar fib\n (make-array (1+ n)))\n\n(vref fib 0 1)\n(vref fib 1 1)\n(loop for i from 2 to n\n do (vref fib i (mod\n (+ (vref fib (1- i))\n (vref fib (- i 2)))\n *mod*)))\n(vref fib 1 0)\n\n\n(defun main ()\n (let ((ans 1) (pos 0) next)\n (dotimes (i m)\n (setf next (1- (read)))\n (if (< (- next pos) 0)\n (setf ans 0)\n (setf ans (mod (* ans (vref fib (- next pos))) *mod*)))\n (setf pos (+ 2 next)))\n (setf ans (mod (* ans (vref fib (- n pos))) *mod*))\n (println ans)))\n\n#-swank(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2635, "cpu_time_ms": 240, "memory_kb": 59876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s760938706", "group_id": "codeNet:p03014", "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(defparameter hw (input-to-list (read-line)))\n(defparameter stage (loop for i from 1 to (car hw)\n collect (read-line)))\n\n(defun sacc (stage x y)\n (schar (nth y stage) x))\n\n#| (defun idn (&rest lst)\n lst) |#\n\n#| (defun lit (x y stage hw)\n (if (eq #\\. (sacc stage x y))\n (labels ((count-lit (x y direction cnt)\n (format t \"coor: ~d, ~d~%dir: ~d~%~%\" x y direction)\n (case direction\n (0 (if (zerop y)\n cnt\n (if (eq #\\. (sacc stage x (1- y)))\n (count-lit x (1- y) 0 (1+ cnt))\n cnt)))\n (1 (if (eq y (1- (car hw)))\n cnt\n (if (eq #\\. (sacc stage x (1+ y)))\n (count-lit x (1+ y) 0 (1+ cnt))\n cnt)))\n (2 (if (zerop x)\n cnt\n (if (eq #\\. (sacc stage (1- x) y))\n (count-lit (1- x) y 0 (1+ cnt))\n cnt)))\n (3 (if (eq x (1- (cadr hw)))\n cnt\n (if (eq #\\. (sacc stage (1+ x) y))\n (count-lit (1+ x) y 0 (1+ cnt))\n cnt))))))\n (1+ (apply #'+ (loop for i from 0 to 3\n collect (count-lit x y i 0)))))\n 0)) |#\n\n(defun l-lit (x y cnt)\n (if (zerop x)\n cnt\n (if (eq #\\. (sacc stage (1- x) y))\n (l-lit (1- x) y (1+ cnt))\n cnt)))\n\n(defun r-lit (x y cnt)\n (if (eq x (1- (cadr hw)))\n cnt\n (if (eq #\\. (sacc stage (1+ x) y))\n (r-lit (1+ x) y (1+ cnt))\n cnt)))\n\n(defun u-lit (x y cnt)\n (if (zerop y)\n cnt\n (if (eq #\\. (sacc stage x (1- y)))\n (u-lit x (1- y) (1+ cnt))\n cnt)))\n\n(defun d-lit (x y cnt)\n (if (eq y (1- (car hw)))\n cnt\n (if (eq #\\. (sacc stage x (1+ y)))\n (d-lit x (1+ y) (1+ cnt))\n cnt)))\n\n(defun lit (x y)\n (if (eq #\\. (sacc stage x y))\n (+ 1\n (l-lit x y 0)\n (r-lit x y 0)\n (u-lit x y 0)\n (d-lit x y 0))\n 0))\n\n(format t \"~d\" (apply #'max (loop for i from 0 to (1- (cadr hw))\n collect (apply #'max (loop for j from 0 to (1- (car hw))\n collect (lit i j))))))", "language": "Lisp", "metadata": {"date": 1560134680, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03014.html", "problem_id": "p03014", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03014/input.txt", "sample_output_relpath": "derived/input_output/data/p03014/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03014/Lisp/s760938706.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s760938706", "user_id": "u250100102"}, "prompt_components": {"gold_output": "8\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(defparameter hw (input-to-list (read-line)))\n(defparameter stage (loop for i from 1 to (car hw)\n collect (read-line)))\n\n(defun sacc (stage x y)\n (schar (nth y stage) x))\n\n#| (defun idn (&rest lst)\n lst) |#\n\n#| (defun lit (x y stage hw)\n (if (eq #\\. (sacc stage x y))\n (labels ((count-lit (x y direction cnt)\n (format t \"coor: ~d, ~d~%dir: ~d~%~%\" x y direction)\n (case direction\n (0 (if (zerop y)\n cnt\n (if (eq #\\. (sacc stage x (1- y)))\n (count-lit x (1- y) 0 (1+ cnt))\n cnt)))\n (1 (if (eq y (1- (car hw)))\n cnt\n (if (eq #\\. (sacc stage x (1+ y)))\n (count-lit x (1+ y) 0 (1+ cnt))\n cnt)))\n (2 (if (zerop x)\n cnt\n (if (eq #\\. (sacc stage (1- x) y))\n (count-lit (1- x) y 0 (1+ cnt))\n cnt)))\n (3 (if (eq x (1- (cadr hw)))\n cnt\n (if (eq #\\. (sacc stage (1+ x) y))\n (count-lit (1+ x) y 0 (1+ cnt))\n cnt))))))\n (1+ (apply #'+ (loop for i from 0 to 3\n collect (count-lit x y i 0)))))\n 0)) |#\n\n(defun l-lit (x y cnt)\n (if (zerop x)\n cnt\n (if (eq #\\. (sacc stage (1- x) y))\n (l-lit (1- x) y (1+ cnt))\n cnt)))\n\n(defun r-lit (x y cnt)\n (if (eq x (1- (cadr hw)))\n cnt\n (if (eq #\\. (sacc stage (1+ x) y))\n (r-lit (1+ x) y (1+ cnt))\n cnt)))\n\n(defun u-lit (x y cnt)\n (if (zerop y)\n cnt\n (if (eq #\\. (sacc stage x (1- y)))\n (u-lit x (1- y) (1+ cnt))\n cnt)))\n\n(defun d-lit (x y cnt)\n (if (eq y (1- (car hw)))\n cnt\n (if (eq #\\. (sacc stage x (1+ y)))\n (d-lit x (1+ y) (1+ cnt))\n cnt)))\n\n(defun lit (x y)\n (if (eq #\\. (sacc stage x y))\n (+ 1\n (l-lit x y 0)\n (r-lit x y 0)\n (u-lit x y 0)\n (d-lit x y 0))\n 0))\n\n(format t \"~d\" (apply #'max (loop for i from 0 to (1- (cadr hw))\n collect (apply #'max (loop for j from 0 to (1- (car hw))\n collect (lit i j))))))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.\n\nSnuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.\nThe lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.\nIn each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.\n\nSnuke wants to maximize the number of squares lighted by the lamp.\n\nYou are given H strings S_i (1 \\leq i \\leq H), each of length W. If the j-th character (1 \\leq j \\leq W) of S_i is #, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is ., there is no obstacle on that square.\n\nFind the maximum possible number of squares lighted by the lamp.\n\nConstraints\n\n1 \\leq H \\leq 2,000\n\n1 \\leq W \\leq 2,000\n\nS_i is a string of length W consisting of # and ..\n\n. occurs at least once in one of the strings S_i (1 \\leq i \\leq H).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nS_1\n:\nS_H\n\nOutput\n\nPrint the maximum possible number of squares lighted by the lamp.\n\nSample Input 1\n\n4 6\n#..#..\n.....#\n....#.\n#.#...\n\nSample Output 1\n\n8\n\nIf Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.\n\nSample Input 2\n\n8 8\n..#...#.\n....#...\n##......\n..###..#\n...#..#.\n##....#.\n#...#...\n###.#..#\n\nSample Output 2\n\n13", "sample_input": "4 6\n#..#..\n.....#\n....#.\n#.#...\n"}, "reference_outputs": ["8\n"], "source_document_id": "p03014", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.\n\nSnuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.\nThe lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.\nIn each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.\n\nSnuke wants to maximize the number of squares lighted by the lamp.\n\nYou are given H strings S_i (1 \\leq i \\leq H), each of length W. If the j-th character (1 \\leq j \\leq W) of S_i is #, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is ., there is no obstacle on that square.\n\nFind the maximum possible number of squares lighted by the lamp.\n\nConstraints\n\n1 \\leq H \\leq 2,000\n\n1 \\leq W \\leq 2,000\n\nS_i is a string of length W consisting of # and ..\n\n. occurs at least once in one of the strings S_i (1 \\leq i \\leq H).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nS_1\n:\nS_H\n\nOutput\n\nPrint the maximum possible number of squares lighted by the lamp.\n\nSample Input 1\n\n4 6\n#..#..\n.....#\n....#.\n#.#...\n\nSample Output 1\n\n8\n\nIf Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.\n\nSample Input 2\n\n8 8\n..#...#.\n....#...\n##......\n..###..#\n...#..#.\n##....#.\n#...#...\n###.#..#\n\nSample Output 2\n\n13", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3320, "cpu_time_ms": 2104, "memory_kb": 51560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s406950395", "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 ((integer 0 #.most-positive-fixnum) divisor)\n (integer base))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x)\n (unsigned-byte 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 (let ((factor (mod (expt 10 width) divisor)))\n (labels ((recur (k)\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 (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 (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 'fixnum :initial-element 0)))\n (dotimes (d 19)\n (setf (aref boundaries d)\n (max 0 (ceiling (- (expt 10 d) a) b))))\n (let ((res 0))\n (loop for d from (position-if #'plusp boundaries) below 19\n for length = (* d (- (aref boundaries d) (aref boundaries (- d 1))))\n until (>= (aref boundaries d) l)\n do (setf res\n (mod\n (+ (mod (* res (power-mod 10 length m)) m)\n (calc (- (aref boundaries d) (aref boundaries (- d 1)))\n (+ a (* b (aref boundaries (- d 1)))) b d m))\n m))\n finally (setf res\n (mod\n (+ (mod (* res (power-mod 10 (* d (- l (aref boundaries (- d 1)))) m)) m)\n (calc (- l (aref boundaries (- d 1)))\n (+ a (* b (aref boundaries (- d 1)))) b d m))\n m)))\n (println res))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560211679, "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/s406950395.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s406950395", "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 ((integer 0 #.most-positive-fixnum) divisor)\n (integer base))\n (labels ((recur (x p)\n (declare ((integer 0 #.most-positive-fixnum) x)\n (unsigned-byte 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 (let ((factor (mod (expt 10 width) divisor)))\n (labels ((recur (k)\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 (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 (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 'fixnum :initial-element 0)))\n (dotimes (d 19)\n (setf (aref boundaries d)\n (max 0 (ceiling (- (expt 10 d) a) b))))\n (let ((res 0))\n (loop for d from (position-if #'plusp boundaries) below 19\n for length = (* d (- (aref boundaries d) (aref boundaries (- d 1))))\n until (>= (aref boundaries d) l)\n do (setf res\n (mod\n (+ (mod (* res (power-mod 10 length m)) m)\n (calc (- (aref boundaries d) (aref boundaries (- d 1)))\n (+ a (* b (aref boundaries (- d 1)))) b d m))\n m))\n finally (setf res\n (mod\n (+ (mod (* res (power-mod 10 (* d (- l (aref boundaries (- d 1)))) m)) m)\n (calc (- l (aref boundaries (- d 1)))\n (+ 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4328, "cpu_time_ms": 263, "memory_kb": 62056}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s233498702", "group_id": "codeNet:p03023", "input_text": "(princ(*(-(read)2)180))", "language": "Lisp", "metadata": {"date": 1559498346, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03023.html", "problem_id": "p03023", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03023/input.txt", "sample_output_relpath": "derived/input_output/data/p03023/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03023/Lisp/s233498702.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s233498702", "user_id": "u994767958"}, "prompt_components": {"gold_output": "180\n", "input_to_evaluate": "(princ(*(-(read)2)180))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nGiven an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides.\n\nPrint the answer in degrees, but do not print units.\n\nConstraints\n\n3 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint an integer representing the sum of the interior angles of a regular polygon with N sides.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n180\n\nThe sum of the interior angles of a regular triangle is 180 degrees.\n\nSample Input 2\n\n100\n\nSample Output 2\n\n17640", "sample_input": "3\n"}, "reference_outputs": ["180\n"], "source_document_id": "p03023", "source_text": "Score : 100 points\n\nProblem Statement\n\nGiven an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides.\n\nPrint the answer in degrees, but do not print units.\n\nConstraints\n\n3 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint an integer representing the sum of the interior angles of a regular polygon with N sides.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n180\n\nThe sum of the interior angles of a regular triangle is 180 degrees.\n\nSample Input 2\n\n100\n\nSample Output 2\n\n17640", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 22, "memory_kb": 3808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s263585686", "group_id": "codeNet:p03029", "input_text": "(princ(float(/(+(*(read)3)(read))2)))", "language": "Lisp", "metadata": {"date": 1560624573, "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/s263585686.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s263585686", "user_id": "u994767958"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(princ(float(/(+(*(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 4072}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s840885354", "group_id": "codeNet:p03030", "input_text": ";グローバル変数\n(setq *n* (read))\n(setq *l* nil)\n\n;ガイドブック順ソートの定義\n(defun my< (a b)\n (cond\n ((equal (car a) (car b))\n (if (> (cadr a) (cadr b)) t nil))\n ((string< (car a) (car b))\n t)\n (t nil)))\n\n;入力\n(dotimes (i *n*)\n (setq *l* (append *l* (list (list (string (read)) (read) (1+ i))))))\n\n;ソート実行\n(sort *l* #'(lambda (a b) (my< a b)))\n\n;出力\n(format t \"~{~a~^~%~}~%\" (mapcar #'caddr *l*))", "language": "Lisp", "metadata": {"date": 1569275452, "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/s840885354.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s840885354", "user_id": "u358554431"}, "prompt_components": {"gold_output": "3\n4\n6\n1\n5\n2\n", "input_to_evaluate": ";グローバル変数\n(setq *n* (read))\n(setq *l* nil)\n\n;ガイドブック順ソートの定義\n(defun my< (a b)\n (cond\n ((equal (car a) (car b))\n (if (> (cadr a) (cadr b)) t nil))\n ((string< (car a) (car b))\n t)\n (t nil)))\n\n;入力\n(dotimes (i *n*)\n (setq *l* (append *l* (list (list (string (read)) (read) (1+ i))))))\n\n;ソート実行\n(sort *l* #'(lambda (a b) (my< a b)))\n\n;出力\n(format t \"~{~a~^~%~}~%\" (mapcar #'caddr *l*))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 141, "memory_kb": 13280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s074341136", "group_id": "codeNet:p03030", "input_text": "(let* ((a (read))\n (lst (loop :repeat a :collect (read-line)))\n (srt nil))\n (defun f (k)\n (cons (subseq k 0 (position #\\Space k :test #'char=)) (parse-integer (subseq k (1+ (position #\\Space k :test #'char=))))))\n (map-into lst #'f lst)\n (defun ff< (p q)\n (if (string= (car p) (car q))\n (> (cdr p) (cdr q))\n (string< (car p) (car q))))\n (setf srt (sort (copy-seq lst) #'ff<))\n (mapcar (lambda (k) (print (1+ (position k lst)))) srt))", "language": "Lisp", "metadata": {"date": 1558968806, "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/s074341136.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s074341136", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3\n4\n6\n1\n5\n2\n", "input_to_evaluate": "(let* ((a (read))\n (lst (loop :repeat a :collect (read-line)))\n (srt nil))\n (defun f (k)\n (cons (subseq k 0 (position #\\Space k :test #'char=)) (parse-integer (subseq k (1+ (position #\\Space k :test #'char=))))))\n (map-into lst #'f lst)\n (defun ff< (p q)\n (if (string= (car p) (car q))\n (> (cdr p) (cdr q))\n (string< (car p) (car q))))\n (setf srt (sort (copy-seq lst) #'ff<))\n (mapcar (lambda (k) (print (1+ (position k lst)))) srt))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 472, "cpu_time_ms": 25, "memory_kb": 6624}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s163912649", "group_id": "codeNet:p03030", "input_text": "(defstruct p i city point)\n(defun f (s)\n (let* ((n (read s))\n (ps (loop for i from 1 to n\n for city = (read s)\n for point = (read s)\n collecting (make-p :i i :city city :point point)))\n (sorted1 (sort ps #'> :key #'p-point))\n (sorted2 (sort sorted1 #'string< :key #'p-city))\n (loop for p in sorted2\n do (progn (princ (p-i p)) (terpri))))\n(f t)", "language": "Lisp", "metadata": {"date": 1558926444, "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/s163912649.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s163912649", "user_id": "u378695780"}, "prompt_components": {"gold_output": "3\n4\n6\n1\n5\n2\n", "input_to_evaluate": "(defstruct p i city point)\n(defun f (s)\n (let* ((n (read s))\n (ps (loop for i from 1 to n\n for city = (read s)\n for point = (read s)\n collecting (make-p :i i :city city :point point)))\n (sorted1 (sort ps #'> :key #'p-point))\n (sorted2 (sort sorted1 #'string< :key #'p-city))\n (loop for p in sorted2\n do (progn (princ (p-i p)) (terpri))))\n(f t)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 182, "memory_kb": 19428}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s522168890", "group_id": "codeNet:p03030", "input_text": "(defun f (s)\n (let* ((n (read s))\n (ps (loop for i from 1 to n\n for city = (read s)\n for point = (read s)\n collecting (list i city point)))\n (sorted1 (sort ps #'(lambda (p pp) (> (third p) (third pp)))))\n (sorted2 (sort sorted1 #'(lambda (p pp) (string< (second p) (second pp))))))\n (loop for p in sorted2\n do (format t \"~A~%\" (first p)))))\n(f t)", "language": "Lisp", "metadata": {"date": 1558922775, "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/s522168890.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s522168890", "user_id": "u378695780"}, "prompt_components": {"gold_output": "3\n4\n6\n1\n5\n2\n", "input_to_evaluate": "(defun f (s)\n (let* ((n (read s))\n (ps (loop for i from 1 to n\n for city = (read s)\n for point = (read s)\n collecting (list i city point)))\n (sorted1 (sort ps #'(lambda (p pp) (> (third p) (third pp)))))\n (sorted2 (sort sorted1 #'(lambda (p pp) (string< (second p) (second pp))))))\n (loop for p in sorted2\n do (format t \"~A~%\" (first p)))))\n(f t)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 437, "cpu_time_ms": 132, "memory_kb": 13280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s813052943", "group_id": "codeNet:p03030", "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-b2 (n)\n (let ((l (list)))\n (dotimes (i n l)\n (push (list (read) (read) (+ i 1)) l))\n (setf l (sort l #'(lambda (x y)\n\t\t\t(or\n\t\t\t (and\n\t\t\t (string= (nth 0 x) (nth 0 y))\n\t\t\t (> (nth 1 x) (nth 1 y)))\n\t\t\t (string< (nth 0 x) (nth 0 y))))))\n (loop for x in l do (format t \"~a~%\" (nth 2 x)))))\n\n(solution-b2)", "language": "Lisp", "metadata": {"date": 1558921649, "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/s813052943.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s813052943", "user_id": "u100932207"}, "prompt_components": {"gold_output": "3\n4\n6\n1\n5\n2\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-b2 (n)\n (let ((l (list)))\n (dotimes (i n l)\n (push (list (read) (read) (+ i 1)) l))\n (setf l (sort l #'(lambda (x y)\n\t\t\t(or\n\t\t\t (and\n\t\t\t (string= (nth 0 x) (nth 0 y))\n\t\t\t (> (nth 1 x) (nth 1 y)))\n\t\t\t (string< (nth 0 x) (nth 0 y))))))\n (loop for x in l do (format t \"~a~%\" (nth 2 x)))))\n\n(solution-b2)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 137, "memory_kb": 15972}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s506210841", "group_id": "codeNet:p03031", "input_text": "(let* ((n (read))\n (m (read))\n (k (make-array (list (1+ m))))\n (s (make-array (list (1+ m) (1+ n))))\n (p (make-array (list (1+ m))))\n (ans 0))\n (loop :for i :from 1 :to m\n :do (setf (aref k i) (read))\n :do (loop :for j :from 1 :to (aref k i)\n :do (setf (aref s i j) (read))))\n (loop :for i :from 1 :to m\n :do (setf (aref p i) (read)))\n (defun check (cnt sw)\n (if (= cnt (+ n 1))\n (if (= (loop :for i :from 1 :to m\n :if (= (mod (loop :for j :from 1 :to (aref k i)\n :sum (aref sw (aref s i j))) \n 2)\n (aref p i))\n :sum 1)\n m)\n (incf ans))\n (loop :for a :from 0 :to 1\n :do (setf (aref sw cnt) a)\n :do (check (1+ cnt) sw))))\n (check 1 (make-array (list (1+ n))))\n (format t \"~A~%\" ans))\n", "language": "Lisp", "metadata": {"date": 1598824944, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03031.html", "problem_id": "p03031", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03031/input.txt", "sample_output_relpath": "derived/input_output/data/p03031/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03031/Lisp/s506210841.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s506210841", "user_id": "u608227593"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (k (make-array (list (1+ m))))\n (s (make-array (list (1+ m) (1+ n))))\n (p (make-array (list (1+ m))))\n (ans 0))\n (loop :for i :from 1 :to m\n :do (setf (aref k i) (read))\n :do (loop :for j :from 1 :to (aref k i)\n :do (setf (aref s i j) (read))))\n (loop :for i :from 1 :to m\n :do (setf (aref p i) (read)))\n (defun check (cnt sw)\n (if (= cnt (+ n 1))\n (if (= (loop :for i :from 1 :to m\n :if (= (mod (loop :for j :from 1 :to (aref k i)\n :sum (aref sw (aref s i j))) \n 2)\n (aref p i))\n :sum 1)\n m)\n (incf ans))\n (loop :for a :from 0 :to 1\n :do (setf (aref sw cnt) a)\n :do (check (1+ cnt) sw))))\n (check 1 (make-array (list (1+ n))))\n (format t \"~A~%\" ans))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have N switches with \"on\" and \"off\" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.\n\nBulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are \"on\" among these switches is congruent to p_i modulo 2.\n\nHow many combinations of \"on\" and \"off\" states of the switches light all the bulbs?\n\nConstraints\n\n1 \\leq N, M \\leq 10\n\n1 \\leq k_i \\leq N\n\n1 \\leq s_{ij} \\leq N\n\ns_{ia} \\neq s_{ib} (a \\neq b)\n\np_i is 0 or 1.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nk_1 s_{11} s_{12} ... s_{1k_1}\n:\nk_M s_{M1} s_{M2} ... s_{Mk_M}\np_1 p_2 ... p_M\n\nOutput\n\nPrint the number of combinations of \"on\" and \"off\" states of the switches that light all the bulbs.\n\nSample Input 1\n\n2 2\n2 1 2\n1 2\n0 1\n\nSample Output 1\n\n1\n\nBulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.\n\nBulb 2 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.\n\nThere are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1.\n\nSample Input 2\n\n2 3\n2 1 2\n1 1\n1 2\n0 0 1\n\nSample Output 2\n\n0\n\nBulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.\n\nBulb 2 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1.\n\nBulb 3 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.\n\nSwitch 1 has to be \"off\" to light Bulb 2 and Switch 2 has to be \"on\" to light Bulb 3, but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0.\n\nSample Input 3\n\n5 2\n3 1 2 5\n2 2 3\n1 0\n\nSample Output 3\n\n8", "sample_input": "2 2\n2 1 2\n1 2\n0 1\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03031", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have N switches with \"on\" and \"off\" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.\n\nBulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are \"on\" among these switches is congruent to p_i modulo 2.\n\nHow many combinations of \"on\" and \"off\" states of the switches light all the bulbs?\n\nConstraints\n\n1 \\leq N, M \\leq 10\n\n1 \\leq k_i \\leq N\n\n1 \\leq s_{ij} \\leq N\n\ns_{ia} \\neq s_{ib} (a \\neq b)\n\np_i is 0 or 1.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nk_1 s_{11} s_{12} ... s_{1k_1}\n:\nk_M s_{M1} s_{M2} ... s_{Mk_M}\np_1 p_2 ... p_M\n\nOutput\n\nPrint the number of combinations of \"on\" and \"off\" states of the switches that light all the bulbs.\n\nSample Input 1\n\n2 2\n2 1 2\n1 2\n0 1\n\nSample Output 1\n\n1\n\nBulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.\n\nBulb 2 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.\n\nThere are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1.\n\nSample Input 2\n\n2 3\n2 1 2\n1 1\n1 2\n0 0 1\n\nSample Output 2\n\n0\n\nBulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.\n\nBulb 2 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1.\n\nBulb 3 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.\n\nSwitch 1 has to be \"off\" to light Bulb 2 and Switch 2 has to be \"on\" to light Bulb 3, but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0.\n\nSample Input 3\n\n5 2\n3 1 2 5\n2 2 3\n1 0\n\nSample Output 3\n\n8", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 963, "cpu_time_ms": 21, "memory_kb": 24768}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s969213204", "group_id": "codeNet:p03031", "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(defun gene-switch-type (n)\n (let ((line (loop repeat n collect 0))\n (res))\n (labels ((f (lst thunk)\n (if lst\n (progn\n (setf (car lst) 0)\n (f (cdr lst) thunk)\n (setf (car lst) 1)\n (f (cdr lst) thunk))\n (funcall thunk))))\n (f line (lambda () (push (coerce line 'vector) res)))\n res)))\n\n(defun check (lights switch-type sums)\n (let ((n (length lights)))\n (dotimes (i n)\n (unless (= (aref sums i)\n (mod (loop for j in (aref lights i)\n sum (aref switch-type j)) 2))\n (return-from check nil))))\n t)\n\n(defun main (n m lights sum)\n (loop for switch-type in (gene-switch-type n)\n sum\n (if (check lights switch-type sum) 1 0)))\n\n(let* ((n (read))\n (m (read))\n (lights (coerce (loop repeat m collect\n (loop repeat (read) collect (1- (read))))\n 'vector))\n (sum (coerce (loop repeat m collect (read)) 'vector)))\n (princ (main n m lights sum)))\n", "language": "Lisp", "metadata": {"date": 1585803365, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03031.html", "problem_id": "p03031", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03031/input.txt", "sample_output_relpath": "derived/input_output/data/p03031/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03031/Lisp/s969213204.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s969213204", "user_id": "u493610446"}, "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(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(defun gene-switch-type (n)\n (let ((line (loop repeat n collect 0))\n (res))\n (labels ((f (lst thunk)\n (if lst\n (progn\n (setf (car lst) 0)\n (f (cdr lst) thunk)\n (setf (car lst) 1)\n (f (cdr lst) thunk))\n (funcall thunk))))\n (f line (lambda () (push (coerce line 'vector) res)))\n res)))\n\n(defun check (lights switch-type sums)\n (let ((n (length lights)))\n (dotimes (i n)\n (unless (= (aref sums i)\n (mod (loop for j in (aref lights i)\n sum (aref switch-type j)) 2))\n (return-from check nil))))\n t)\n\n(defun main (n m lights sum)\n (loop for switch-type in (gene-switch-type n)\n sum\n (if (check lights switch-type sum) 1 0)))\n\n(let* ((n (read))\n (m (read))\n (lights (coerce (loop repeat m collect\n (loop repeat (read) collect (1- (read))))\n 'vector))\n (sum (coerce (loop repeat m collect (read)) 'vector)))\n (princ (main n m lights sum)))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have N switches with \"on\" and \"off\" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.\n\nBulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are \"on\" among these switches is congruent to p_i modulo 2.\n\nHow many combinations of \"on\" and \"off\" states of the switches light all the bulbs?\n\nConstraints\n\n1 \\leq N, M \\leq 10\n\n1 \\leq k_i \\leq N\n\n1 \\leq s_{ij} \\leq N\n\ns_{ia} \\neq s_{ib} (a \\neq b)\n\np_i is 0 or 1.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nk_1 s_{11} s_{12} ... s_{1k_1}\n:\nk_M s_{M1} s_{M2} ... s_{Mk_M}\np_1 p_2 ... p_M\n\nOutput\n\nPrint the number of combinations of \"on\" and \"off\" states of the switches that light all the bulbs.\n\nSample Input 1\n\n2 2\n2 1 2\n1 2\n0 1\n\nSample Output 1\n\n1\n\nBulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.\n\nBulb 2 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.\n\nThere are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1.\n\nSample Input 2\n\n2 3\n2 1 2\n1 1\n1 2\n0 0 1\n\nSample Output 2\n\n0\n\nBulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.\n\nBulb 2 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1.\n\nBulb 3 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.\n\nSwitch 1 has to be \"off\" to light Bulb 2 and Switch 2 has to be \"on\" to light Bulb 3, but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0.\n\nSample Input 3\n\n5 2\n3 1 2 5\n2 2 3\n1 0\n\nSample Output 3\n\n8", "sample_input": "2 2\n2 1 2\n1 2\n0 1\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03031", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have N switches with \"on\" and \"off\" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.\n\nBulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are \"on\" among these switches is congruent to p_i modulo 2.\n\nHow many combinations of \"on\" and \"off\" states of the switches light all the bulbs?\n\nConstraints\n\n1 \\leq N, M \\leq 10\n\n1 \\leq k_i \\leq N\n\n1 \\leq s_{ij} \\leq N\n\ns_{ia} \\neq s_{ib} (a \\neq b)\n\np_i is 0 or 1.\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nk_1 s_{11} s_{12} ... s_{1k_1}\n:\nk_M s_{M1} s_{M2} ... s_{Mk_M}\np_1 p_2 ... p_M\n\nOutput\n\nPrint the number of combinations of \"on\" and \"off\" states of the switches that light all the bulbs.\n\nSample Input 1\n\n2 2\n2 1 2\n1 2\n0 1\n\nSample Output 1\n\n1\n\nBulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.\n\nBulb 2 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.\n\nThere are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1.\n\nSample Input 2\n\n2 3\n2 1 2\n1 1\n1 2\n0 0 1\n\nSample Output 2\n\n0\n\nBulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.\n\nBulb 2 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1.\n\nBulb 3 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.\n\nSwitch 1 has to be \"off\" to light Bulb 2 and Switch 2 has to be \"on\" to light Bulb 3, but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0.\n\nSample Input 3\n\n5 2\n3 1 2 5\n2 2 3\n1 0\n\nSample Output 3\n\n8", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2033, "cpu_time_ms": 81, "memory_kb": 15668}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s996592528", "group_id": "codeNet:p03032", "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(defparameter nk (input-to-list (read-line)))\n(defparameter v (input-to-list (read-line)))\n\n(defun num-pat (num len)\n (labels ((inner (num cnt lst)\n (if (eq cnt len)\n lst\n (inner (truncate num 4) (1+ cnt) (cons (mod num 4) lst)))))\n (inner num 0 '())))\n\n(defun dot (lst1 lst2)\n (reduce #'+ (mapcar #'* lst1 lst2)))\n\n(defun lastvalue (pattern column hand)\n (if pattern\n (case (car pattern)\n (0 (if column\n (lastvalue (cdr pattern) (cdr column) (cons (first column) hand))\n (lastvalue (cdr pattern) column hand)))\n (1 (if column\n (lastvalue (cdr pattern) (subseq column 0 (1- (length column))) (cons (car (last column)) hand))\n (lastvalue (cdr pattern) column hand)))\n (2 (if hand\n (let ((mi (apply #'min hand))) (lastvalue (cdr pattern) (cons mi column) (remove mi hand)))\n (lastvalue (cdr pattern) column hand)))\n (3 (if hand\n (let ((mi (apply #'min hand))) (lastvalue (cdr pattern) (append `(,mi) column) (remove mi hand)))\n (lastvalue (cdr pattern) column hand)))\n (otherwise (princ \"error\")))\n (if hand\n (reduce #'+ hand)\n 0)))\n\n(princ (apply #'max (loop for i from 0 to (cadr nk)\n collect (apply #'max (loop for j from 0 to (1- (expt 4 i))\n collect (lastvalue (num-pat j (cadr nk)) v '()))))))", "language": "Lisp", "metadata": {"date": 1558925640, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03032.html", "problem_id": "p03032", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03032/input.txt", "sample_output_relpath": "derived/input_output/data/p03032/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03032/Lisp/s996592528.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s996592528", "user_id": "u250100102"}, "prompt_components": {"gold_output": "14\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(defparameter nk (input-to-list (read-line)))\n(defparameter v (input-to-list (read-line)))\n\n(defun num-pat (num len)\n (labels ((inner (num cnt lst)\n (if (eq cnt len)\n lst\n (inner (truncate num 4) (1+ cnt) (cons (mod num 4) lst)))))\n (inner num 0 '())))\n\n(defun dot (lst1 lst2)\n (reduce #'+ (mapcar #'* lst1 lst2)))\n\n(defun lastvalue (pattern column hand)\n (if pattern\n (case (car pattern)\n (0 (if column\n (lastvalue (cdr pattern) (cdr column) (cons (first column) hand))\n (lastvalue (cdr pattern) column hand)))\n (1 (if column\n (lastvalue (cdr pattern) (subseq column 0 (1- (length column))) (cons (car (last column)) hand))\n (lastvalue (cdr pattern) column hand)))\n (2 (if hand\n (let ((mi (apply #'min hand))) (lastvalue (cdr pattern) (cons mi column) (remove mi hand)))\n (lastvalue (cdr pattern) column hand)))\n (3 (if hand\n (let ((mi (apply #'min hand))) (lastvalue (cdr pattern) (append `(,mi) column) (remove mi hand)))\n (lastvalue (cdr pattern) column hand)))\n (otherwise (princ \"error\")))\n (if hand\n (reduce #'+ hand)\n 0)))\n\n(princ (apply #'max (loop for i from 0 to (cadr nk)\n collect (apply #'max (loop for j from 0 to (1- (expt 4 i))\n collect (lastvalue (num-pat j (cadr nk)) v '()))))))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYour friend gave you a dequeue D as a birthday present.\n\nD is a horizontal cylinder that contains a row of N jewels.\n\nThe values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.\n\nIn the beginning, you have no jewel in your hands.\n\nYou can perform at most K operations on D, chosen from the following, at most K times (possibly zero):\n\nOperation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.\n\nOperation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.\n\nFind the maximum possible sum of the values of jewels in your hands after the operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 50\n\n1 \\leq K \\leq 100\n\n-10^7 \\leq V_i \\leq 10^7\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nV_1 V_2 ... V_N\n\nOutput\n\nPrint the maximum possible sum of the values of jewels in your hands after the operations.\n\nSample Input 1\n\n6 4\n-10 8 2 1 2 6\n\nSample Output 1\n\n14\n\nAfter the following sequence of operations, you have two jewels of values 8 and 6 in your hands for a total of 14, which is the maximum result.\n\nDo operation A. You take out the jewel of value -10 from the left end of D.\n\nDo operation B. You take out the jewel of value 6 from the right end of D.\n\nDo operation A. You take out the jewel of value 8 from the left end of D.\n\nDo operation D. You insert the jewel of value -10 to the right end of D.\n\nSample Input 2\n\n6 4\n-6 -100 50 -2 -5 -3\n\nSample Output 2\n\n44\n\nSample Input 3\n\n6 3\n-6 -100 50 -2 -5 -3\n\nSample Output 3\n\n0\n\nIt is optimal to do no operation.", "sample_input": "6 4\n-10 8 2 1 2 6\n"}, "reference_outputs": ["14\n"], "source_document_id": "p03032", "source_text": "Score : 400 points\n\nProblem Statement\n\nYour friend gave you a dequeue D as a birthday present.\n\nD is a horizontal cylinder that contains a row of N jewels.\n\nThe values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.\n\nIn the beginning, you have no jewel in your hands.\n\nYou can perform at most K operations on D, chosen from the following, at most K times (possibly zero):\n\nOperation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.\n\nOperation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.\n\nFind the maximum possible sum of the values of jewels in your hands after the operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 50\n\n1 \\leq K \\leq 100\n\n-10^7 \\leq V_i \\leq 10^7\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nV_1 V_2 ... V_N\n\nOutput\n\nPrint the maximum possible sum of the values of jewels in your hands after the operations.\n\nSample Input 1\n\n6 4\n-10 8 2 1 2 6\n\nSample Output 1\n\n14\n\nAfter the following sequence of operations, you have two jewels of values 8 and 6 in your hands for a total of 14, which is the maximum result.\n\nDo operation A. You take out the jewel of value -10 from the left end of D.\n\nDo operation B. You take out the jewel of value 6 from the right end of D.\n\nDo operation A. You take out the jewel of value 8 from the left end of D.\n\nDo operation D. You insert the jewel of value -10 to the right end of D.\n\nSample Input 2\n\n6 4\n-6 -100 50 -2 -5 -3\n\nSample Output 2\n\n44\n\nSample Input 3\n\n6 3\n-6 -100 50 -2 -5 -3\n\nSample Output 3\n\n0\n\nIt is optimal to do no operation.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2190, "cpu_time_ms": 2105, "memory_kb": 65152}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s311085796", "group_id": "codeNet:p03032", "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(defparameter nk (input-to-list (read-line)))\n(defparameter v (input-to-list (read-line)))\n\n(defun num-pat (num len)\n (labels ((inner (num cnt lst)\n (if (eq cnt len)\n lst\n (inner (truncate num 4) (1+ cnt) (cons (mod num 4) lst)))))\n (inner num 0 '())))\n\n(defun dot (lst1 lst2)\n (reduce #'+ (mapcar #'* lst1 lst2)))\n\n(defun lastvalue (pattern column hand)\n (if pattern\n (case (car pattern)\n (0 (if column\n (lastvalue (cdr pattern) (cdr column) (cons (first column) hand))\n (lastvalue (cdr pattern) column hand)))\n (1 (if column\n (lastvalue (cdr pattern) (subseq column 0 (1- (length column))) (cons (car (last column)) hand))\n (lastvalue (cdr pattern) column hand)))\n (2 (if hand\n (let ((mi (apply #'min hand))) (lastvalue (cdr pattern) (cons mi column) (remove mi hand)))\n (lastvalue (cdr pattern) column hand)))\n (3 (if hand\n (let ((mi (apply #'min hand))) (lastvalue (cdr pattern) (append `(,mi) column) (remove mi hand)))\n (lastvalue (cdr pattern) column hand)))\n (t (princ \"error\")))\n (if hand\n (reduce #'+ hand)\n 0)))\n\n(princ (apply #'max (loop for i from 0 to (cadr nk)\n collect (apply #'max (loop for j from 0 to (1- (expt 4 i))\n collect (lastvalue (num-pat j (cadr nk)) v '()))))))", "language": "Lisp", "metadata": {"date": 1558925318, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03032.html", "problem_id": "p03032", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03032/input.txt", "sample_output_relpath": "derived/input_output/data/p03032/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03032/Lisp/s311085796.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s311085796", "user_id": "u250100102"}, "prompt_components": {"gold_output": "14\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(defparameter nk (input-to-list (read-line)))\n(defparameter v (input-to-list (read-line)))\n\n(defun num-pat (num len)\n (labels ((inner (num cnt lst)\n (if (eq cnt len)\n lst\n (inner (truncate num 4) (1+ cnt) (cons (mod num 4) lst)))))\n (inner num 0 '())))\n\n(defun dot (lst1 lst2)\n (reduce #'+ (mapcar #'* lst1 lst2)))\n\n(defun lastvalue (pattern column hand)\n (if pattern\n (case (car pattern)\n (0 (if column\n (lastvalue (cdr pattern) (cdr column) (cons (first column) hand))\n (lastvalue (cdr pattern) column hand)))\n (1 (if column\n (lastvalue (cdr pattern) (subseq column 0 (1- (length column))) (cons (car (last column)) hand))\n (lastvalue (cdr pattern) column hand)))\n (2 (if hand\n (let ((mi (apply #'min hand))) (lastvalue (cdr pattern) (cons mi column) (remove mi hand)))\n (lastvalue (cdr pattern) column hand)))\n (3 (if hand\n (let ((mi (apply #'min hand))) (lastvalue (cdr pattern) (append `(,mi) column) (remove mi hand)))\n (lastvalue (cdr pattern) column hand)))\n (t (princ \"error\")))\n (if hand\n (reduce #'+ hand)\n 0)))\n\n(princ (apply #'max (loop for i from 0 to (cadr nk)\n collect (apply #'max (loop for j from 0 to (1- (expt 4 i))\n collect (lastvalue (num-pat j (cadr nk)) v '()))))))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYour friend gave you a dequeue D as a birthday present.\n\nD is a horizontal cylinder that contains a row of N jewels.\n\nThe values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.\n\nIn the beginning, you have no jewel in your hands.\n\nYou can perform at most K operations on D, chosen from the following, at most K times (possibly zero):\n\nOperation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.\n\nOperation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.\n\nFind the maximum possible sum of the values of jewels in your hands after the operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 50\n\n1 \\leq K \\leq 100\n\n-10^7 \\leq V_i \\leq 10^7\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nV_1 V_2 ... V_N\n\nOutput\n\nPrint the maximum possible sum of the values of jewels in your hands after the operations.\n\nSample Input 1\n\n6 4\n-10 8 2 1 2 6\n\nSample Output 1\n\n14\n\nAfter the following sequence of operations, you have two jewels of values 8 and 6 in your hands for a total of 14, which is the maximum result.\n\nDo operation A. You take out the jewel of value -10 from the left end of D.\n\nDo operation B. You take out the jewel of value 6 from the right end of D.\n\nDo operation A. You take out the jewel of value 8 from the left end of D.\n\nDo operation D. You insert the jewel of value -10 to the right end of D.\n\nSample Input 2\n\n6 4\n-6 -100 50 -2 -5 -3\n\nSample Output 2\n\n44\n\nSample Input 3\n\n6 3\n-6 -100 50 -2 -5 -3\n\nSample Output 3\n\n0\n\nIt is optimal to do no operation.", "sample_input": "6 4\n-10 8 2 1 2 6\n"}, "reference_outputs": ["14\n"], "source_document_id": "p03032", "source_text": "Score : 400 points\n\nProblem Statement\n\nYour friend gave you a dequeue D as a birthday present.\n\nD is a horizontal cylinder that contains a row of N jewels.\n\nThe values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.\n\nIn the beginning, you have no jewel in your hands.\n\nYou can perform at most K operations on D, chosen from the following, at most K times (possibly zero):\n\nOperation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.\n\nOperation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.\n\nFind the maximum possible sum of the values of jewels in your hands after the operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 50\n\n1 \\leq K \\leq 100\n\n-10^7 \\leq V_i \\leq 10^7\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nV_1 V_2 ... V_N\n\nOutput\n\nPrint the maximum possible sum of the values of jewels in your hands after the operations.\n\nSample Input 1\n\n6 4\n-10 8 2 1 2 6\n\nSample Output 1\n\n14\n\nAfter the following sequence of operations, you have two jewels of values 8 and 6 in your hands for a total of 14, which is the maximum result.\n\nDo operation A. You take out the jewel of value -10 from the left end of D.\n\nDo operation B. You take out the jewel of value 6 from the right end of D.\n\nDo operation A. You take out the jewel of value 8 from the left end of D.\n\nDo operation D. You insert the jewel of value -10 to the right end of D.\n\nSample Input 2\n\n6 4\n-6 -100 50 -2 -5 -3\n\nSample Output 2\n\n44\n\nSample Input 3\n\n6 3\n-6 -100 50 -2 -5 -3\n\nSample Output 3\n\n0\n\nIt is optimal to do no operation.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2182, "cpu_time_ms": 2105, "memory_kb": 65156}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s999160823", "group_id": "codeNet:p03032", "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 (vs (make-array n :element-type 'int32))\n (res 0))\n (dotimes (i n) (setf (aref vs i) (read)))\n (labels ((strip (list r)\n (declare (uint32 r))\n (if (or (zerop r)\n (null list)\n (>= (the fixnum (car list)) 0))\n list\n (strip (cdr list) (- r 1))))\n (frob (x y r)\n (declare (uint32 x y r))\n (let (list)\n (loop for i below x do (push (aref vs i) list))\n (loop for i from (- n 1) downto (- n y) do (push (aref vs i) list))\n (strip (sort list #'<) r))))\n (loop for x to (min n k)\n do (loop for y from 0 to (min (- k x) (- n x))\n do (let ((r (max 0 (- k x y))))\n (let ((list (frob x y r)))\n (setf res (max res (reduce #'+ list :initial-value 0)))))))\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 (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 \"6 4\n-10 8 2 1 2 6\n\"\n \"14\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 4\n-6 -100 50 -2 -5 -3\n\"\n \"44\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 3\n-6 -100 50 -2 -5 -3\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1558921442, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03032.html", "problem_id": "p03032", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03032/input.txt", "sample_output_relpath": "derived/input_output/data/p03032/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03032/Lisp/s999160823.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s999160823", "user_id": "u352600849"}, "prompt_components": {"gold_output": "14\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 (vs (make-array n :element-type 'int32))\n (res 0))\n (dotimes (i n) (setf (aref vs i) (read)))\n (labels ((strip (list r)\n (declare (uint32 r))\n (if (or (zerop r)\n (null list)\n (>= (the fixnum (car list)) 0))\n list\n (strip (cdr list) (- r 1))))\n (frob (x y r)\n (declare (uint32 x y r))\n (let (list)\n (loop for i below x do (push (aref vs i) list))\n (loop for i from (- n 1) downto (- n y) do (push (aref vs i) list))\n (strip (sort list #'<) r))))\n (loop for x to (min n k)\n do (loop for y from 0 to (min (- k x) (- n x))\n do (let ((r (max 0 (- k x y))))\n (let ((list (frob x y r)))\n (setf res (max res (reduce #'+ list :initial-value 0)))))))\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 (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 \"6 4\n-10 8 2 1 2 6\n\"\n \"14\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 4\n-6 -100 50 -2 -5 -3\n\"\n \"44\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 3\n-6 -100 50 -2 -5 -3\n\"\n \"0\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYour friend gave you a dequeue D as a birthday present.\n\nD is a horizontal cylinder that contains a row of N jewels.\n\nThe values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.\n\nIn the beginning, you have no jewel in your hands.\n\nYou can perform at most K operations on D, chosen from the following, at most K times (possibly zero):\n\nOperation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.\n\nOperation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.\n\nFind the maximum possible sum of the values of jewels in your hands after the operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 50\n\n1 \\leq K \\leq 100\n\n-10^7 \\leq V_i \\leq 10^7\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nV_1 V_2 ... V_N\n\nOutput\n\nPrint the maximum possible sum of the values of jewels in your hands after the operations.\n\nSample Input 1\n\n6 4\n-10 8 2 1 2 6\n\nSample Output 1\n\n14\n\nAfter the following sequence of operations, you have two jewels of values 8 and 6 in your hands for a total of 14, which is the maximum result.\n\nDo operation A. You take out the jewel of value -10 from the left end of D.\n\nDo operation B. You take out the jewel of value 6 from the right end of D.\n\nDo operation A. You take out the jewel of value 8 from the left end of D.\n\nDo operation D. You insert the jewel of value -10 to the right end of D.\n\nSample Input 2\n\n6 4\n-6 -100 50 -2 -5 -3\n\nSample Output 2\n\n44\n\nSample Input 3\n\n6 3\n-6 -100 50 -2 -5 -3\n\nSample Output 3\n\n0\n\nIt is optimal to do no operation.", "sample_input": "6 4\n-10 8 2 1 2 6\n"}, "reference_outputs": ["14\n"], "source_document_id": "p03032", "source_text": "Score : 400 points\n\nProblem Statement\n\nYour friend gave you a dequeue D as a birthday present.\n\nD is a horizontal cylinder that contains a row of N jewels.\n\nThe values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.\n\nIn the beginning, you have no jewel in your hands.\n\nYou can perform at most K operations on D, chosen from the following, at most K times (possibly zero):\n\nOperation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.\n\nOperation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.\n\nFind the maximum possible sum of the values of jewels in your hands after the operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 50\n\n1 \\leq K \\leq 100\n\n-10^7 \\leq V_i \\leq 10^7\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nV_1 V_2 ... V_N\n\nOutput\n\nPrint the maximum possible sum of the values of jewels in your hands after the operations.\n\nSample Input 1\n\n6 4\n-10 8 2 1 2 6\n\nSample Output 1\n\n14\n\nAfter the following sequence of operations, you have two jewels of values 8 and 6 in your hands for a total of 14, which is the maximum result.\n\nDo operation A. You take out the jewel of value -10 from the left end of D.\n\nDo operation B. You take out the jewel of value 6 from the right end of D.\n\nDo operation A. You take out the jewel of value 8 from the left end of D.\n\nDo operation D. You insert the jewel of value -10 to the right end of D.\n\nSample Input 2\n\n6 4\n-6 -100 50 -2 -5 -3\n\nSample Output 2\n\n44\n\nSample Input 3\n\n6 3\n-6 -100 50 -2 -5 -3\n\nSample Output 3\n\n0\n\nIt is optimal to do no operation.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4164, "cpu_time_ms": 162, "memory_kb": 21088}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s451581265", "group_id": "codeNet:p03032", "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 (vs (make-array n :element-type 'int32))\n (res 0))\n (dotimes (i n) (setf (aref vs i) (read)))\n (labels ((strip (list r)\n (declare (uint32 r))\n (if (or (zerop r)\n (null list)\n (>= (the fixnum (car list)) 0))\n list\n (strip (cdr list) (- r 1))))\n (frob (x y r)\n (declare (uint32 x y r))\n (let (list)\n (loop for i below x do (push (aref vs i) list))\n (loop for i from (- n 1) downto (- n y) do (push (aref vs i) list))\n (strip (sort list #'<) r))))\n (loop for x to (min n k)\n do (loop for y from 0 to (min (- k x) (- n x))\n do (let ((r (min (- k x y) (- n x y))))\n (let ((list (frob x y r)))\n (setf res (max res (reduce #'+ list :initial-value 0)))))))\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 (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 \"6 4\n-10 8 2 1 2 6\n\"\n \"14\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 4\n-6 -100 50 -2 -5 -3\n\"\n \"44\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 3\n-6 -100 50 -2 -5 -3\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1558920998, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03032.html", "problem_id": "p03032", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03032/input.txt", "sample_output_relpath": "derived/input_output/data/p03032/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03032/Lisp/s451581265.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s451581265", "user_id": "u352600849"}, "prompt_components": {"gold_output": "14\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 (vs (make-array n :element-type 'int32))\n (res 0))\n (dotimes (i n) (setf (aref vs i) (read)))\n (labels ((strip (list r)\n (declare (uint32 r))\n (if (or (zerop r)\n (null list)\n (>= (the fixnum (car list)) 0))\n list\n (strip (cdr list) (- r 1))))\n (frob (x y r)\n (declare (uint32 x y r))\n (let (list)\n (loop for i below x do (push (aref vs i) list))\n (loop for i from (- n 1) downto (- n y) do (push (aref vs i) list))\n (strip (sort list #'<) r))))\n (loop for x to (min n k)\n do (loop for y from 0 to (min (- k x) (- n x))\n do (let ((r (min (- k x y) (- n x y))))\n (let ((list (frob x y r)))\n (setf res (max res (reduce #'+ list :initial-value 0)))))))\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 (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 \"6 4\n-10 8 2 1 2 6\n\"\n \"14\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 4\n-6 -100 50 -2 -5 -3\n\"\n \"44\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 3\n-6 -100 50 -2 -5 -3\n\"\n \"0\n\")))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYour friend gave you a dequeue D as a birthday present.\n\nD is a horizontal cylinder that contains a row of N jewels.\n\nThe values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.\n\nIn the beginning, you have no jewel in your hands.\n\nYou can perform at most K operations on D, chosen from the following, at most K times (possibly zero):\n\nOperation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.\n\nOperation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.\n\nFind the maximum possible sum of the values of jewels in your hands after the operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 50\n\n1 \\leq K \\leq 100\n\n-10^7 \\leq V_i \\leq 10^7\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nV_1 V_2 ... V_N\n\nOutput\n\nPrint the maximum possible sum of the values of jewels in your hands after the operations.\n\nSample Input 1\n\n6 4\n-10 8 2 1 2 6\n\nSample Output 1\n\n14\n\nAfter the following sequence of operations, you have two jewels of values 8 and 6 in your hands for a total of 14, which is the maximum result.\n\nDo operation A. You take out the jewel of value -10 from the left end of D.\n\nDo operation B. You take out the jewel of value 6 from the right end of D.\n\nDo operation A. You take out the jewel of value 8 from the left end of D.\n\nDo operation D. You insert the jewel of value -10 to the right end of D.\n\nSample Input 2\n\n6 4\n-6 -100 50 -2 -5 -3\n\nSample Output 2\n\n44\n\nSample Input 3\n\n6 3\n-6 -100 50 -2 -5 -3\n\nSample Output 3\n\n0\n\nIt is optimal to do no operation.", "sample_input": "6 4\n-10 8 2 1 2 6\n"}, "reference_outputs": ["14\n"], "source_document_id": "p03032", "source_text": "Score : 400 points\n\nProblem Statement\n\nYour friend gave you a dequeue D as a birthday present.\n\nD is a horizontal cylinder that contains a row of N jewels.\n\nThe values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.\n\nIn the beginning, you have no jewel in your hands.\n\nYou can perform at most K operations on D, chosen from the following, at most K times (possibly zero):\n\nOperation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.\n\nOperation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.\n\nOperation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.\n\nFind the maximum possible sum of the values of jewels in your hands after the operations.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 50\n\n1 \\leq K \\leq 100\n\n-10^7 \\leq V_i \\leq 10^7\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nV_1 V_2 ... V_N\n\nOutput\n\nPrint the maximum possible sum of the values of jewels in your hands after the operations.\n\nSample Input 1\n\n6 4\n-10 8 2 1 2 6\n\nSample Output 1\n\n14\n\nAfter the following sequence of operations, you have two jewels of values 8 and 6 in your hands for a total of 14, which is the maximum result.\n\nDo operation A. You take out the jewel of value -10 from the left end of D.\n\nDo operation B. You take out the jewel of value 6 from the right end of D.\n\nDo operation A. You take out the jewel of value 8 from the left end of D.\n\nDo operation D. You insert the jewel of value -10 to the right end of D.\n\nSample Input 2\n\n6 4\n-6 -100 50 -2 -5 -3\n\nSample Output 2\n\n44\n\nSample Input 3\n\n6 3\n-6 -100 50 -2 -5 -3\n\nSample Output 3\n\n0\n\nIt is optimal to do no operation.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4173, "cpu_time_ms": 202, "memory_kb": 21220}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s744867579", "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(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(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)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\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 &key left right lazy))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value +op-identity+ :type fixnum)\n (lazy +updater-identity+ :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 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 (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-value treap)\n (modifier-op (%treap-value treap)\n (%treap-lazy treap)))\n (setf (%treap-lazy treap) +updater-identity+)))\n\n(defun treap-bisect (key treap)\n (declare #.OPT ((or null treap) treap))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (force-down treap)\n (if (treap-order key (%treap-key treap))\n (recur (%treap-left treap))\n (or (recur (%treap-right 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(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 (values treap right))\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(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 #.OPT ((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 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 treap))))\n (recur (%make-treap key (random most-positive-fixnum) 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 ((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 t))\n ((treap-order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\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)) right)\n ((null right) (when left (force-down 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 left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left 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\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(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)\n (let* ((n (read))\n (q (read))\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 (setf treap (treap-insert most-positive-fixnum most-positive-fixnum treap))\n (setf treap (treap-insert most-negative-fixnum 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 (with-output-buffer\n (dotimes (i q)\n (let* ((d (read-fixnum))\n (res (nth-value 1 (treap-bisect d treap))))\n (println\n (if (< (the fixnum res) most-positive-fixnum)\n res\n -1)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559024218, "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/s744867579.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s744867579", "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(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(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)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\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 &key left right lazy))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value +op-identity+ :type fixnum)\n (lazy +updater-identity+ :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 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 (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-value treap)\n (modifier-op (%treap-value treap)\n (%treap-lazy treap)))\n (setf (%treap-lazy treap) +updater-identity+)))\n\n(defun treap-bisect (key treap)\n (declare #.OPT ((or null treap) treap))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (force-down treap)\n (if (treap-order key (%treap-key treap))\n (recur (%treap-left treap))\n (or (recur (%treap-right 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(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 (values treap right))\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(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 #.OPT ((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 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 treap))))\n (recur (%make-treap key (random most-positive-fixnum) 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 ((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 t))\n ((treap-order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\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)) right)\n ((null right) (when left (force-down 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 left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left 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\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(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)\n (let* ((n (read))\n (q (read))\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 (setf treap (treap-insert most-positive-fixnum most-positive-fixnum treap))\n (setf treap (treap-insert most-negative-fixnum 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 (with-output-buffer\n (dotimes (i q)\n (let* ((d (read-fixnum))\n (res (nth-value 1 (treap-bisect d treap))))\n (println\n (if (< (the fixnum res) most-positive-fixnum)\n res\n -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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11473, "cpu_time_ms": 1059, "memory_kb": 101600}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s733731377", "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(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(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)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\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 &key left right lazy))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value +op-identity+ :type fixnum)\n (lazy +updater-identity+ :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 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 (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-value treap)\n (modifier-op (%treap-value treap)\n (%treap-lazy treap)))\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 (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 (recur treap)))\n\n(defun treap-bisect (key treap)\n (declare #.OPT ((or null treap) treap))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (force-down treap)\n (if (treap-order key (%treap-key treap))\n (recur (%treap-left treap))\n (or (recur (%treap-right 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(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 (values treap right))\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(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 #.OPT ((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 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 treap))))\n (recur (%make-treap key (random most-positive-fixnum) 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 ((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 t))\n ((treap-order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\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)) right)\n ((null right) (when left (force-down 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 left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left 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\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(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)\n (let* ((n (read))\n (q (read))\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 (setf treap (treap-insert most-positive-fixnum most-positive-fixnum treap))\n (setf treap (treap-insert most-negative-fixnum 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 \n (with-output-buffer\n (dotimes (i q)\n (let* ((d (read-fixnum))\n (res (nth-value 1 (treap-bisect 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": 1559020948, "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/s733731377.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s733731377", "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(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(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)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\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 &key left right lazy))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value +op-identity+ :type fixnum)\n (lazy +updater-identity+ :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 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 (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-value treap)\n (modifier-op (%treap-value treap)\n (%treap-lazy treap)))\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 (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 (recur treap)))\n\n(defun treap-bisect (key treap)\n (declare #.OPT ((or null treap) treap))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (force-down treap)\n (if (treap-order key (%treap-key treap))\n (recur (%treap-left treap))\n (or (recur (%treap-right 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(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 (values treap right))\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(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 #.OPT ((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 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 treap))))\n (recur (%make-treap key (random most-positive-fixnum) 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 ((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 t))\n ((treap-order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\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)) right)\n ((null right) (when left (force-down 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 left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left 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\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(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)\n (let* ((n (read))\n (q (read))\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 (setf treap (treap-insert most-positive-fixnum most-positive-fixnum treap))\n (setf treap (treap-insert most-negative-fixnum 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 \n (with-output-buffer\n (dotimes (i q)\n (let* ((d (read-fixnum))\n (res (nth-value 1 (treap-bisect 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 12152, "cpu_time_ms": 984, "memory_kb": 100968}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s467929128", "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(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(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)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\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 &key left right lazy))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value +op-identity+ :type fixnum)\n (lazy +updater-identity+ :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 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 (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-value treap)\n (modifier-op (%treap-value treap)\n (%treap-lazy treap)))\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 (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 (recur treap)))\n\n(defun treap-bisect-left (key treap)\n (declare #.OPT ((or null treap) treap))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (force-down treap)\n (if (treap-order (%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(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 (values treap right))\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(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 #.OPT ((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 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 treap))))\n (recur (%make-treap key (random most-positive-fixnum) 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 ((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 t))\n ((treap-order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\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)) right)\n ((null right) (when left (force-down 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 left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left 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\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(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)\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 (setf treap (treap-insert most-positive-fixnum most-positive-fixnum treap))\n (setf treap (treap-insert most-negative-fixnum most-positive-fixnum treap))\n (dotimes (i q)\n (let ((d (read-fixnum)))\n (setf (aref ds i) d)))\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 \n (with-output-buffer\n (dotimes (i q)\n (let* ((d (aref ds i))\n (res (nth-value 1 (treap-bisect-left 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": 1559020515, "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/s467929128.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s467929128", "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(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(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)\n \"Is the operator to update ACCUMULATOR based on LAZY value.\"\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 &key left right lazy))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value +op-identity+ :type fixnum)\n (lazy +updater-identity+ :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 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 (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-value treap)\n (modifier-op (%treap-value treap)\n (%treap-lazy treap)))\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 (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 (recur treap)))\n\n(defun treap-bisect-left (key treap)\n (declare #.OPT ((or null treap) treap))\n (labels ((recur (treap)\n (unless treap (return-from recur nil))\n (force-down treap)\n (if (treap-order (%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(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 (values treap right))\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(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 #.OPT ((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 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 treap))))\n (recur (%make-treap key (random most-positive-fixnum) 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 ((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 t))\n ((treap-order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\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)) right)\n ((null right) (when left (force-down 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 left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left 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\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(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)\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 (setf treap (treap-insert most-positive-fixnum most-positive-fixnum treap))\n (setf treap (treap-insert most-negative-fixnum most-positive-fixnum treap))\n (dotimes (i q)\n (let ((d (read-fixnum)))\n (setf (aref ds i) d)))\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 \n (with-output-buffer\n (dotimes (i q)\n (let* ((d (aref ds i))\n (res (nth-value 1 (treap-bisect-left 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 12292, "cpu_time_ms": 1080, "memory_kb": 100192}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s831668112", "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 (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 (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(declaim (inline make-reverse-lookup-table))\n(defun make-reverse-lookup-table (vector &key (test #'eql))\n \"Assigns each value of the (usually sorted) VECTOR of length n to the integers\n0, ..., 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(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 (min a b))\n\n(defconstant +op-identity+ most-positive-fixnum)\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 (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 (min a b))\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator +op-identity+) (lazy +updater-identity+)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum) ; e.g. MIN, MAX, SUM, ...\n (lazy +updater-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 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 ((integer 0 #.most-positive-fixnum) index))\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (force-down itreap)\n (let ((implicit-key (1+ (itreap-count (%itreap-left itreap)))))\n (if (< index implicit-key)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) index)\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) (- index implicit-key))\n (setf (%itreap-right itreap) left)\n (force-self itreap)\n (values itreap right)))))\n\n(defun itreap-merge (left right)\n \"Destructively merges two ITREAPs.\"\n (declare ((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 (format stream \"Invalid index ~W for itreap ~W.\"\n (invalid-itreap-index-error-index condition)\n (invalid-itreap-index-error-itreap condition)))))\n\n(declaim (inline itreap-insert))\n(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP at INDEX.\"\n (declare ((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 ((obj-itreap (%make-itreap obj (random most-positive-fixnum))))\n (multiple-value-bind (left right)\n (itreap-split itreap index)\n (itreap-merge (itreap-merge left obj-itreap) right))))\n\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (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(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((size (itreap-count object))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (itreap-map (lambda (x)\n (princ x stream)\n (incf index)\n (when (< index size)\n (write-char #\\ stream)))\n object))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size)\n \"Makes a treap of SIZE in O(SIZE) time. The values are filled with the\nidentity element.\"\n (labels ((heapify (top)\n (when top\n (let ((prioritized-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority prioritized-node)))\n (setq prioritized-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority prioritized-node)))\n (setq prioritized-node (%itreap-right top)))\n (unless (eql prioritized-node top)\n (rotatef (%itreap-priority prioritized-node)\n (%itreap-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-itreap +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 (update-count node)\n node))))\n (build 0 size)))\n\n(declaim (inline itreap-delete))\n(defun itreap-delete (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 (multiple-value-bind (itreap1 itreap2)\n (itreap-split itreap (1+ index))\n (multiple-value-bind (itreap1 _)\n (itreap-split itreap1 index)\n (declare (ignore _))\n (itreap-merge itreap1 itreap2))))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (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-self itreap))))\n (%ref itreap index)))\n\n(declaim (inline (setf itreap-ref)))\n(defun (setf itreap-ref) (new-value 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 ((%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(declaim (inline itreap-update))\n(defun itreap-update (itreap x l r)\n \"Updates ITREAP[i] := (OP ITREAP[i] X) 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) x)))\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 (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\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *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 (table (make-array 0 :element-type 'int32 :fill-pointer 0)))\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 (vector-push-extend (- s x) table)\n (vector-push-extend (- end x) table)))\n (dotimes (i q)\n (let ((d (read-fixnum)))\n (setf (aref ds i) d)\n (vector-push-extend d table)))\n (setf table (sort table #'<))\n (let ((revs (make-reverse-lookup-table table))\n (itreap (make-itreap (length table))))\n (dotimes (i n)\n (itreap-update itreap (aref xs i)\n (gethash (- (aref ss i) (aref xs i)) revs)\n (gethash (- (aref ts i) (aref xs i)) revs)))\n (dotimes (i q)\n (let ((d (aref ds i)))\n (let ((q (itreap-ref itreap (gethash d revs))))\n (if (< q most-positive-fixnum)\n (println q)\n (println -1))))))))\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\n;; 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 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n\"\n \"2\n2\n10\n-1\n13\n-1\n\")))\n", "language": "Lisp", "metadata": {"date": 1558923568, "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/s831668112.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s831668112", "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 (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 (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(declaim (inline make-reverse-lookup-table))\n(defun make-reverse-lookup-table (vector &key (test #'eql))\n \"Assigns each value of the (usually sorted) VECTOR of length n to the integers\n0, ..., 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(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 (min a b))\n\n(defconstant +op-identity+ most-positive-fixnum)\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 (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 (min a b))\n\n(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator +op-identity+) (lazy +updater-identity+)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +op-identity+ :type fixnum)\n (accumulator +op-identity+ :type fixnum) ; e.g. MIN, MAX, SUM, ...\n (lazy +updater-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 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 ((integer 0 #.most-positive-fixnum) index))\n (unless itreap\n (return-from itreap-split (values nil nil)))\n (force-down itreap)\n (let ((implicit-key (1+ (itreap-count (%itreap-left itreap)))))\n (if (< index implicit-key)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) index)\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) (- index implicit-key))\n (setf (%itreap-right itreap) left)\n (force-self itreap)\n (values itreap right)))))\n\n(defun itreap-merge (left right)\n \"Destructively merges two ITREAPs.\"\n (declare ((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 (format stream \"Invalid index ~W for itreap ~W.\"\n (invalid-itreap-index-error-index condition)\n (invalid-itreap-index-error-itreap condition)))))\n\n(declaim (inline itreap-insert))\n(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP at INDEX.\"\n (declare ((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 ((obj-itreap (%make-itreap obj (random most-positive-fixnum))))\n (multiple-value-bind (left right)\n (itreap-split itreap index)\n (itreap-merge (itreap-merge left obj-itreap) right))))\n\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (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(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((size (itreap-count object))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (itreap-map (lambda (x)\n (princ x stream)\n (incf index)\n (when (< index size)\n (write-char #\\ stream)))\n object))))\n\n(declaim (inline make-itreap))\n(defun make-itreap (size)\n \"Makes a treap of SIZE in O(SIZE) time. The values are filled with the\nidentity element.\"\n (labels ((heapify (top)\n (when top\n (let ((prioritized-node top))\n (when (and (%itreap-left top)\n (> (%itreap-priority (%itreap-left top))\n (%itreap-priority prioritized-node)))\n (setq prioritized-node (%itreap-left top)))\n (when (and (%itreap-right top)\n (> (%itreap-priority (%itreap-right top))\n (%itreap-priority prioritized-node)))\n (setq prioritized-node (%itreap-right top)))\n (unless (eql prioritized-node top)\n (rotatef (%itreap-priority prioritized-node)\n (%itreap-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-itreap +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 (update-count node)\n node))))\n (build 0 size)))\n\n(declaim (inline itreap-delete))\n(defun itreap-delete (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 (multiple-value-bind (itreap1 itreap2)\n (itreap-split itreap (1+ index))\n (multiple-value-bind (itreap1 _)\n (itreap-split itreap1 index)\n (declare (ignore _))\n (itreap-merge itreap1 itreap2))))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (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-self itreap))))\n (%ref itreap index)))\n\n(declaim (inline (setf itreap-ref)))\n(defun (setf itreap-ref) (new-value 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 ((%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(declaim (inline itreap-update))\n(defun itreap-update (itreap x l r)\n \"Updates ITREAP[i] := (OP ITREAP[i] X) 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) x)))\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 (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\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *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 (table (make-array 0 :element-type 'int32 :fill-pointer 0)))\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 (vector-push-extend (- s x) table)\n (vector-push-extend (- end x) table)))\n (dotimes (i q)\n (let ((d (read-fixnum)))\n (setf (aref ds i) d)\n (vector-push-extend d table)))\n (setf table (sort table #'<))\n (let ((revs (make-reverse-lookup-table table))\n (itreap (make-itreap (length table))))\n (dotimes (i n)\n (itreap-update itreap (aref xs i)\n (gethash (- (aref ss i) (aref xs i)) revs)\n (gethash (- (aref ts i) (aref xs i)) revs)))\n (dotimes (i q)\n (let ((d (aref ds i)))\n (let ((q (itreap-ref itreap (gethash d revs))))\n (if (< q most-positive-fixnum)\n (println q)\n (println -1))))))))\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\n;; 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 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n\"\n \"2\n2\n10\n-1\n13\n-1\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 18096, "cpu_time_ms": 1997, "memory_kb": 96864}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s531482954", "group_id": "codeNet:p03035", "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(defparameter param (input-to-list (readline)))\n(princ (cond ((<= (car param) 5) 0)\n ((and (<= (car param) 12)\n (>= (car param) 6)) (/ (cadr param) 2))\n (t (cadr param))))\n", "language": "Lisp", "metadata": {"date": 1558833622, "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/s531482954.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s531482954", "user_id": "u250100102"}, "prompt_components": {"gold_output": "100\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(defparameter param (input-to-list (readline)))\n(princ (cond ((<= (car param) 5) 0)\n ((and (<= (car param) 12)\n (>= (car param) 6)) (/ (cadr param) 2))\n (t (cadr param))))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 827, "cpu_time_ms": 113, "memory_kb": 12392}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s690413816", "group_id": "codeNet:p03035", "input_text": "(defun _ferris (a b)\n (cond ((<= a 5) 0)\n ((and (<= 6 a) (<= a 12)) (floor b 2))\n (t b)))\n\n(defun ferris(a b)\n (print (_ferris a b)))\n\n#|\n(ferris 30 100)\n(ferris 12 100)\n(ferris 0 100)\n|#\n(let ((a (read))\n (b (read)))\n (ferris a b))", "language": "Lisp", "metadata": {"date": 1558832849, "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/s690413816.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s690413816", "user_id": "u788952094"}, "prompt_components": {"gold_output": "100\n", "input_to_evaluate": "(defun _ferris (a b)\n (cond ((<= a 5) 0)\n ((and (<= 6 a) (<= a 12)) (floor b 2))\n (t b)))\n\n(defun ferris(a b)\n (print (_ferris a b)))\n\n#|\n(ferris 30 100)\n(ferris 12 100)\n(ferris 0 100)\n|#\n(let ((a (read))\n (b (read)))\n (ferris 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 188, "memory_kb": 13024}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s033340700", "group_id": "codeNet:p03036", "input_text": "(defun solve (r d x)\n (loop for i below 10\n do (setf x (- (* r x) d))\n do (format t \"~A~%\" x)))\n(solve (read) (read) (read))", "language": "Lisp", "metadata": {"date": 1577039817, "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/s033340700.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s033340700", "user_id": "u672956630"}, "prompt_components": {"gold_output": "30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n", "input_to_evaluate": "(defun solve (r d x)\n (loop for i below 10\n do (setf x (- (* r x) d))\n do (format t \"~A~%\" x)))\n(solve (read) (read) (read))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 156, "memory_kb": 12384}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s987995020", "group_id": "codeNet:p03036", "input_text": "(defun next (r d xi c)\n (if (> c 9)\n xi\n (progn (format t \"~a~%\" (- (* r xi) d)) (next r d (- (* r xi) d) (1+ c)))))\n\n(next (read) (read) (read) 0)", "language": "Lisp", "metadata": {"date": 1569270735, "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/s987995020.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s987995020", "user_id": "u358554431"}, "prompt_components": {"gold_output": "30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n", "input_to_evaluate": "(defun next (r d xi c)\n (if (> c 9)\n xi\n (progn (format t \"~a~%\" (- (* r xi) d)) (next r d (- (* r xi) d) (1+ c)))))\n\n(next (read) (read) (read) 0)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 39, "memory_kb": 5088}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s545978053", "group_id": "codeNet:p03036", "input_text": "(defun solve (r d x i) (print (- (* r x ) d)) (if (equal i 9) () (solve r d ( - ( * r x ) d ) (+ i 1))))\n\n(setq r (read))\n(setq d (read))\n(solve r d (read) 0)\n", "language": "Lisp", "metadata": {"date": 1559456102, "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/s545978053.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s545978053", "user_id": "u192442087"}, "prompt_components": {"gold_output": "30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n", "input_to_evaluate": "(defun solve (r d x i) (print (- (* r x ) d)) (if (equal i 9) () (solve r d ( - ( * r x ) d ) (+ i 1))))\n\n(setq r (read))\n(setq d (read))\n(solve r d (read) 0)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 126, "memory_kb": 12004}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s193159194", "group_id": "codeNet:p03037", "input_text": "(defvar N (read))\n\n(loop repeat (read)\n with maxL = 0 \n and minR = (1+ N)\n and L and R \n do \n (setf L (read)\n R (read))\n (if (> L maxL) (setf maxL L))\n (if (< R minR) (setf minR R))\n finally (princ (max (1+ (- minR maxL)) 0)))", "language": "Lisp", "metadata": {"date": 1585801445, "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/s193159194.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s193159194", "user_id": "u334552723"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defvar N (read))\n\n(loop repeat (read)\n with maxL = 0 \n and minR = (1+ N)\n and L and R \n do \n (setf L (read)\n R (read))\n (if (> L maxL) (setf maxL L))\n (if (< R minR) (setf minR R))\n finally (princ (max (1+ (- minR maxL)) 0)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 277, "cpu_time_ms": 368, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s019590169", "group_id": "codeNet:p03037", "input_text": "(defun _prison (n m lst)\n (let* ((lr (reduce #'(lambda (a b)\n (let ((a-l (car a))\n (a-r (cdr a))\n (b-l (car b))\n (b-r (cdr b)))\n ;(print `(:e ,a-l ,a-r ,b-l ,b-r))\n (cons\n (max a-l b-l)\n (min a-r b-r)))) lst :initial-value `(1 . ,n)))\n (max-l (car lr))\n (min-r (cdr lr)))\n ;(print lr)\n (if (> max-l min-r) 0\n (+ (- min-r max-l) 1))))\n\n(defun prison (n m lst)\n (print (_prison n m lst)))\n\n#|\n(prison 4 2\n '((1 . 3) (2 . 4)))\n\n(prison 10 2\n '((3 . 6) (5 . 7) (6 . 9)))\n\n(prison 100000 1\n '((1 . 100000)))\n|#\n\n(let* ((n (read))\n (m (read))\n (lst (labels ((read-m (my-m rv)\n (if (= my-m 0) (nreverse rv)\n (let ((l (read))\n (r (read)))\n (read-m (- my-m 1) (cons (cons l r) rv))))))\n (read-m m nil))))\n ;(print lst)\n (prison n m lst))\n", "language": "Lisp", "metadata": {"date": 1558835397, "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/s019590169.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s019590169", "user_id": "u788952094"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun _prison (n m lst)\n (let* ((lr (reduce #'(lambda (a b)\n (let ((a-l (car a))\n (a-r (cdr a))\n (b-l (car b))\n (b-r (cdr b)))\n ;(print `(:e ,a-l ,a-r ,b-l ,b-r))\n (cons\n (max a-l b-l)\n (min a-r b-r)))) lst :initial-value `(1 . ,n)))\n (max-l (car lr))\n (min-r (cdr lr)))\n ;(print lr)\n (if (> max-l min-r) 0\n (+ (- min-r max-l) 1))))\n\n(defun prison (n m lst)\n (print (_prison n m lst)))\n\n#|\n(prison 4 2\n '((1 . 3) (2 . 4)))\n\n(prison 10 2\n '((3 . 6) (5 . 7) (6 . 9)))\n\n(prison 100000 1\n '((1 . 100000)))\n|#\n\n(let* ((n (read))\n (m (read))\n (lst (labels ((read-m (my-m rv)\n (if (= my-m 0) (nreverse rv)\n (let ((l (read))\n (r (read)))\n (read-m (- my-m 1) (cons (cons l r) rv))))))\n (read-m m nil))))\n ;(print lst)\n (prison n m lst))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1155, "cpu_time_ms": 374, "memory_kb": 59876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s961284151", "group_id": "codeNet:p03037", "input_text": "(let* ((n (read))\n (m (read))\n (arr (make-array n :initial-element 0 :element-type 'fixnum))\n (gatea (make-array m :initial-element 0 :element-type 'fixnum))\n (gateb (make-array m :initial-element 0 :element-type 'fixnum)))\n (loop :for a :from 0 :upto (1- m) :do(setf (aref gatea a) (1- (read)))\n :do(setf (aref gateb a) (1- (read))))\n (map nil (lambda (a b) (loop :for x :from a :upto b :do(setf (aref arr x) (1+ (aref arr x))))) gatea gateb)\n (princ (count m arr)))", "language": "Lisp", "metadata": {"date": 1558833998, "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/s961284151.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s961284151", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (arr (make-array n :initial-element 0 :element-type 'fixnum))\n (gatea (make-array m :initial-element 0 :element-type 'fixnum))\n (gateb (make-array m :initial-element 0 :element-type 'fixnum)))\n (loop :for a :from 0 :upto (1- m) :do(setf (aref gatea a) (1- (read)))\n :do(setf (aref gateb a) (1- (read))))\n (map nil (lambda (a b) (loop :for x :from a :upto b :do(setf (aref arr x) (1+ (aref arr x))))) gatea gateb)\n (princ (count m arr)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2105, "memory_kb": 61732}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s671173844", "group_id": "codeNet:p03038", "input_text": "(defun _int-cards (n m lst m-lst)\n (let ((new-m-lst (sort m-lst #'(lambda (a b) \n (let ((a0 (car a))\n (b0 (car b)))\n (> a0 b0))))))\n (labels ((all-m-lst (_m-lst sum-m rv)\n (if (or (null _m-lst) (>= sum-m n)) rv\n (let* ((elm (car _m-lst))\n (b (car elm))\n (c (cdr elm))\n (new-lst (make-list b :initial-element c)))\n (all-m-lst (cdr _m-lst) (+ sum-m b) (append rv new-lst))))))\n ;(print new-m-lst)\n (let ((all-lst (append lst (all-m-lst new-m-lst 0 nil))))\n (apply #'+\n (subseq (sort all-lst #'>) 0 n))))))\n\n\n(defun int-cards (n m lst m-lst)\n (print (_int-cards n m lst m-lst)))\n\n#|\n(int-cards 3 2 '(5 1 4) '((2 . 3) (1 . 5)))\n(int-cards 10 2 '(1 8 5 7 100 4 52 33 13 5) '((2 . 10) (4 . 30) (1 . 4)))\n(int-cards 3 2 '(100 100 100) '((3 . 99) (3 . 99) ))\n(int-cards 11 4 '(1 1 1 1 1 1 1 1 1 1 1) '((3 . 10000000000) (4 . 10000000000) (3 . 10000000000 )))\n|#\n\n(let* ((n (read))\n (m (read))\n (lst (labels ((read-n (my-n rv)\n (if (= my-n 0) (nreverse rv)\n (let ((a (read)))\n (read-n (- my-n 1) (cons a rv))))))\n (read-n n nil)))\n (m-lst (labels ((read-m (my-m rv)\n (if (= my-m 0) (nreverse rv)\n (let ((b (read))\n (c (read)))\n (read-m (- my-m 1) (cons (cons b c) rv))))))\n (read-m m nil))))\n (int-cards n m lst m-lst))\n\n", "language": "Lisp", "metadata": {"date": 1558839411, "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/s671173844.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s671173844", "user_id": "u788952094"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": "(defun _int-cards (n m lst m-lst)\n (let ((new-m-lst (sort m-lst #'(lambda (a b) \n (let ((a0 (car a))\n (b0 (car b)))\n (> a0 b0))))))\n (labels ((all-m-lst (_m-lst sum-m rv)\n (if (or (null _m-lst) (>= sum-m n)) rv\n (let* ((elm (car _m-lst))\n (b (car elm))\n (c (cdr elm))\n (new-lst (make-list b :initial-element c)))\n (all-m-lst (cdr _m-lst) (+ sum-m b) (append rv new-lst))))))\n ;(print new-m-lst)\n (let ((all-lst (append lst (all-m-lst new-m-lst 0 nil))))\n (apply #'+\n (subseq (sort all-lst #'>) 0 n))))))\n\n\n(defun int-cards (n m lst m-lst)\n (print (_int-cards n m lst m-lst)))\n\n#|\n(int-cards 3 2 '(5 1 4) '((2 . 3) (1 . 5)))\n(int-cards 10 2 '(1 8 5 7 100 4 52 33 13 5) '((2 . 10) (4 . 30) (1 . 4)))\n(int-cards 3 2 '(100 100 100) '((3 . 99) (3 . 99) ))\n(int-cards 11 4 '(1 1 1 1 1 1 1 1 1 1 1) '((3 . 10000000000) (4 . 10000000000) (3 . 10000000000 )))\n|#\n\n(let* ((n (read))\n (m (read))\n (lst (labels ((read-n (my-n rv)\n (if (= my-n 0) (nreverse rv)\n (let ((a (read)))\n (read-n (- my-n 1) (cons a rv))))))\n (read-n n nil)))\n (m-lst (labels ((read-m (my-m rv)\n (if (= my-m 0) (nreverse rv)\n (let ((b (read))\n (c (read)))\n (read-m (- my-m 1) (cons (cons b c) rv))))))\n (read-m m nil))))\n (int-cards n m lst m-lst))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2106, "memory_kb": 74048}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s428814139", "group_id": "codeNet:p03038", "input_text": "(defun munipulate (bj cj as)\n (labels ((rec (lst n acc)\n (if (or (<= cj (car lst)) (<= n 0))\n (nconc acc lst)\n (rec (cdr lst) (1- n) (cons cj acc)))))\n (rec as bj '())))\n\n(let ((n (read))\n (m (read)))\n (let ((as (sort (loop repeat n collect (read)) #'<=))\n (bcs (loop repeat m collect (cons (read) (read)))))\n (loop for bc in bcs\n do (let ((b (car bc))\n (c (cdr bc)))\n (setf as (munipulate b c as))))\n (apply #'+ as)))\n", "language": "Lisp", "metadata": {"date": 1558838380, "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/s428814139.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s428814139", "user_id": "u956039157"}, "prompt_components": {"gold_output": "14\n", "input_to_evaluate": "(defun munipulate (bj cj as)\n (labels ((rec (lst n acc)\n (if (or (<= cj (car lst)) (<= n 0))\n (nconc acc lst)\n (rec (cdr lst) (1- n) (cons cj acc)))))\n (rec as bj '())))\n\n(let ((n (read))\n (m (read)))\n (let ((as (sort (loop repeat n collect (read)) #'<=))\n (bcs (loop repeat m collect (cons (read) (read)))))\n (loop for bc in bcs\n do (let ((b (car bc))\n (c (cdr bc)))\n (setf as (munipulate b c as))))\n (apply #'+ as)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2106, "memory_kb": 72040}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s301894757", "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(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(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 (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator +op-identity+)))\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))\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) (fixnum 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\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 itreap\n (return-from itreap-split (values nil nil)))\n (let ((implicit-key (1+ (itreap-count (%itreap-left itreap)))))\n (if (< index implicit-key)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) index)\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) (- index implicit-key))\n (setf (%itreap-right itreap) left)\n (force-self itreap)\n (values itreap right)))))\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-self right)) right)\n ((null right) (when left (force-self 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-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(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP and returns the resultant treap. You\ncannot rely on the side effect. Use the returned value.\"\n (declare #.OPT\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 pos)\n (declare ((integer 0 #.most-positive-fixnum) pos))\n (unless itreap (return-from recur node))\n (if (> (%itreap-priority node) (%itreap-priority itreap))\n (progn\n (setf (values (%itreap-left node) (%itreap-right node))\n (itreap-split itreap pos))\n (force-self node)\n node)\n (let ((implicit-key (+ 1 (itreap-count (%itreap-left itreap)))))\n (if (< pos implicit-key)\n (setf (%itreap-left itreap)\n (recur (%itreap-left itreap) pos))\n (setf (%itreap-right itreap)\n (recur (%itreap-right itreap) (- pos implicit-key))))\n (force-self itreap)\n itreap))))\n (recur itreap index))))\n\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (when 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(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((size (itreap-count object))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (itreap-map (lambda (x)\n (princ x stream)\n (incf index)\n (when (< index size)\n (write-char #\\ stream)))\n object))))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (itreap-count itreap)))\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-self itreap))))\n (%ref itreap index)))\n\n(declaim (inline itreap-bisect-left))\n(defun itreap-bisect-left (threshold treap &key (order #'<))\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 order))\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) nil)\n ((funcall order (%itreap-value treap) threshold)\n (recur count (%itreap-right treap)))\n (t (let ((left-count (- count (itreap-count (%itreap-right treap)) 1)))\n (or (recur left-count (%itreap-left treap))\n left-count))))))\n (or (recur (itreap-count treap) treap)\n (itreap-count treap))))\n\n(declaim (inline itreap-query))\n(defun itreap-query (itreap &key (start 0) end)\n \"Queries the sum of the half-open interval specified by the index: [START,\nEND). If START (END) is not given, it is assumed to be 0 (the size of ITREAP).\"\n (declare ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (if (zerop start)\n (if (null end)\n (itreap-accumulator itreap)\n (multiple-value-bind (itreap-0-r itreap-r-n)\n (itreap-split itreap end)\n (prog1 (itreap-accumulator itreap-0-r)\n (itreap-merge itreap-0-r itreap-r-n))))\n (if (null end)\n (multiple-value-bind (itreap-0-l itreap-l-n)\n (itreap-split itreap start)\n (prog1 (itreap-accumulator itreap-l-n)\n (itreap-merge itreap-0-l itreap-l-n)))\n (progn\n (assert (<= start end))\n (multiple-value-bind (itreap-0-l itreap-l-n)\n (itreap-split itreap start)\n (multiple-value-bind (itreap-l-r itreap-r-n)\n (itreap-split itreap-l-n end)\n (prog1 (itreap-accumulator itreap-l-r)\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 (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 itreap)\n (declare (uint32 q) (fixnum const))\n (with-output-buffer\n (dotimes (i q)\n (let ((id (read-fixnum)))\n (if (= id 1)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (setf itreap (itreap-insert itreap (itreap-bisect-left a itreap) a))\n (incf const b))\n (let ((count (itreap-count itreap)))\n (if (oddp count)\n (let* ((mid (floor count 2))\n (at (itreap-ref itreap mid)))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (itreap-query itreap :start (+ mid 1))\n (- (itreap-query itreap :end mid)))))\n (let* ((mid (floor count 2))\n (at (itreap-ref itreap (- mid 1))))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (itreap-query itreap :start mid)\n (- (itreap-query itreap :end mid)))))))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559720938, "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/s301894757.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s301894757", "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(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(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 (itreap (:constructor %make-itreap (value priority &key left right (count 1) (accumulator +op-identity+)))\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))\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) (fixnum 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\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 itreap\n (return-from itreap-split (values nil nil)))\n (let ((implicit-key (1+ (itreap-count (%itreap-left itreap)))))\n (if (< index implicit-key)\n (multiple-value-bind (left right)\n (itreap-split (%itreap-left itreap) index)\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) (- index implicit-key))\n (setf (%itreap-right itreap) left)\n (force-self itreap)\n (values itreap right)))))\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-self right)) right)\n ((null right) (when left (force-self 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-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(defun itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP and returns the resultant treap. You\ncannot rely on the side effect. Use the returned value.\"\n (declare #.OPT\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 pos)\n (declare ((integer 0 #.most-positive-fixnum) pos))\n (unless itreap (return-from recur node))\n (if (> (%itreap-priority node) (%itreap-priority itreap))\n (progn\n (setf (values (%itreap-left node) (%itreap-right node))\n (itreap-split itreap pos))\n (force-self node)\n node)\n (let ((implicit-key (+ 1 (itreap-count (%itreap-left itreap)))))\n (if (< pos implicit-key)\n (setf (%itreap-left itreap)\n (recur (%itreap-left itreap) pos))\n (setf (%itreap-right itreap)\n (recur (%itreap-right itreap) (- pos implicit-key))))\n (force-self itreap)\n itreap))))\n (recur itreap index))))\n\n(defun itreap-map (function itreap)\n \"Successively applies FUNCTION to ITREAP[0], ..., ITREAP[SIZE-1].\"\n (declare (function function))\n (when 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(defmethod print-object ((object itreap) stream)\n (print-unreadable-object (object stream :type t)\n (let ((size (itreap-count object))\n (index 0))\n (declare ((integer 0 #.most-positive-fixnum) index))\n (itreap-map (lambda (x)\n (princ x stream)\n (incf index)\n (when (< index size)\n (write-char #\\ stream)))\n object))))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (itreap index)\n (declare ((integer 0 #.most-positive-fixnum) index))\n (assert (< index (itreap-count itreap)))\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-self itreap))))\n (%ref itreap index)))\n\n(declaim (inline itreap-bisect-left))\n(defun itreap-bisect-left (threshold treap &key (order #'<))\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 order))\n (labels ((recur (count treap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null treap) nil)\n ((funcall order (%itreap-value treap) threshold)\n (recur count (%itreap-right treap)))\n (t (let ((left-count (- count (itreap-count (%itreap-right treap)) 1)))\n (or (recur left-count (%itreap-left treap))\n left-count))))))\n (or (recur (itreap-count treap) treap)\n (itreap-count treap))))\n\n(declaim (inline itreap-query))\n(defun itreap-query (itreap &key (start 0) end)\n \"Queries the sum of the half-open interval specified by the index: [START,\nEND). If START (END) is not given, it is assumed to be 0 (the size of ITREAP).\"\n (declare ((integer 0 #.most-positive-fixnum) start)\n ((or null (integer 0 #.most-positive-fixnum)) end))\n (if (zerop start)\n (if (null end)\n (itreap-accumulator itreap)\n (multiple-value-bind (itreap-0-r itreap-r-n)\n (itreap-split itreap end)\n (prog1 (itreap-accumulator itreap-0-r)\n (itreap-merge itreap-0-r itreap-r-n))))\n (if (null end)\n (multiple-value-bind (itreap-0-l itreap-l-n)\n (itreap-split itreap start)\n (prog1 (itreap-accumulator itreap-l-n)\n (itreap-merge itreap-0-l itreap-l-n)))\n (progn\n (assert (<= start end))\n (multiple-value-bind (itreap-0-l itreap-l-n)\n (itreap-split itreap start)\n (multiple-value-bind (itreap-l-r itreap-r-n)\n (itreap-split itreap-l-n end)\n (prog1 (itreap-accumulator itreap-l-r)\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 (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 itreap)\n (declare (uint32 q) (fixnum const))\n (with-output-buffer\n (dotimes (i q)\n (let ((id (read-fixnum)))\n (if (= id 1)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (setf itreap (itreap-insert itreap (itreap-bisect-left a itreap) a))\n (incf const b))\n (let ((count (itreap-count itreap)))\n (if (oddp count)\n (let* ((mid (floor count 2))\n (at (itreap-ref itreap mid)))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (itreap-query itreap :start (+ mid 1))\n (- (itreap-query itreap :end mid)))))\n (let* ((mid (floor count 2))\n (at (itreap-ref itreap (- mid 1))))\n (format t\n \"~D ~D~%\"\n at\n (+ const\n (itreap-query itreap :start mid)\n (- (itreap-query itreap :end 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 12676, "cpu_time_ms": 734, "memory_kb": 80224}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s227341436", "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 (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 (or (recur left-count (%inode-left treap))\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": 1558838033, "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/s227341436.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s227341436", "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 (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 (or (recur left-count (%inode-left treap))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10309, "cpu_time_ms": 1148, "memory_kb": 53344}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s730626539", "group_id": "codeNet:p03041", "input_text": "(setq n (read) k (read))\n(setq s (read-line))\n\n(setf (char s (- k 1)) (coerce (string-downcase (char s (- k 1))) 'character))\n(princ s) ", "language": "Lisp", "metadata": {"date": 1563235258, "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/s730626539.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s730626539", "user_id": "u480300350"}, "prompt_components": {"gold_output": "aBC\n", "input_to_evaluate": "(setq n (read) k (read))\n(setq s (read-line))\n\n(setf (char s (- k 1)) (coerce (string-downcase (char s (- k 1))) 'character))\n(princ s) ", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 14, "memory_kb": 3680}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s563058682", "group_id": "codeNet:p03041", "input_text": "(setq n (read))\n(setq k (read))\n(dotimes (i n) (if (equal (+ i 1) k) (princ (char-downcase (read-char))) (princ (read-char)) ))", "language": "Lisp", "metadata": {"date": 1559289095, "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/s563058682.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s563058682", "user_id": "u192442087"}, "prompt_components": {"gold_output": "aBC\n", "input_to_evaluate": "(setq n (read))\n(setq k (read))\n(dotimes (i n) (if (equal (+ i 1) k) (princ (char-downcase (read-char))) (princ (read-char)) ))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 139, "memory_kb": 12512}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s273619097", "group_id": "codeNet:p03041", "input_text": "(let ((n (read)) (k (read)) (s (read-line)))\n\t(setf (subseq s (- k 1) k) (string-downcase (subseq s (1- k) k)))\n\t(format t \"~A~%\" s))\n", "language": "Lisp", "metadata": {"date": 1558745028, "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/s273619097.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s273619097", "user_id": "u143397629"}, "prompt_components": {"gold_output": "aBC\n", "input_to_evaluate": "(let ((n (read)) (k (read)) (s (read-line)))\n\t(setf (subseq s (- k 1) k) (string-downcase (subseq s (1- k) k)))\n\t(format t \"~A~%\" s))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 108, "memory_kb": 11624}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s147627345", "group_id": "codeNet:p03042", "input_text": "(defun betweenp (num inf sup)\n (if (>= num inf)\n (if (<= num sup)\n t\n nil)\n nil))\n\n(defun convert-data (str)\n (list (parse-integer (subseq str 0 2)) (parse-integer (subseq str 2 4))))\n(defun monthp (num)\n (betweenp num 1 12))\n\n(defun yearp (num)\n (betweenp num 0 99))\n\n(defun yymmp (lst)\n (and (yearp (car lst))\n (monthp (cadr lst))))\n\n(defun mmyyp (lst)\n (and (monthp (car lst))\n (yearp (cadr lst))))\n\n(defparameter input (read-line))\n(let ((data (convert-data input)))\n (cond ((and (yymmp data)\n (mmyyp data)) (format t \"AMBIGUOUS\"))\n ((and (yymmp data)\n (not (mmyyp data))) (format t \"YYMM\"))\n ((and (not (yymmp data))\n (mmyyp data)) (format t \"MMYY\"))\n (t (format t \"NA\"))\n ))", "language": "Lisp", "metadata": {"date": 1558317783, "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/s147627345.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s147627345", "user_id": "u250100102"}, "prompt_components": {"gold_output": "YYMM\n", "input_to_evaluate": "(defun betweenp (num inf sup)\n (if (>= num inf)\n (if (<= num sup)\n t\n nil)\n nil))\n\n(defun convert-data (str)\n (list (parse-integer (subseq str 0 2)) (parse-integer (subseq str 2 4))))\n(defun monthp (num)\n (betweenp num 1 12))\n\n(defun yearp (num)\n (betweenp num 0 99))\n\n(defun yymmp (lst)\n (and (yearp (car lst))\n (monthp (cadr lst))))\n\n(defun mmyyp (lst)\n (and (monthp (car lst))\n (yearp (cadr lst))))\n\n(defparameter input (read-line))\n(let ((data (convert-data input)))\n (cond ((and (yymmp data)\n (mmyyp data)) (format t \"AMBIGUOUS\"))\n ((and (yymmp data)\n (not (mmyyp data))) (format t \"YYMM\"))\n ((and (not (yymmp data))\n (mmyyp data)) (format t \"MMYY\"))\n (t (format t \"NA\"))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 119, "memory_kb": 14180}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s650471064", "group_id": "codeNet:p03042", "input_text": "(defun mmp (n)\n (and (> n 0) (<= n 12)))\n\n(defun solve (s)\n (let ((before (parse-integer (subseq s 0 2)))\n (after (parse-integer (subseq s 2 4))))\n (cond\n ((and (mmp before) (mmp after)) \"AMBIGUOUS\")\n ((mmp before) \"MMYY\")\n ((mmp after) \"YYMM\")\n (t \"NA\"))))\n\n(defun main ()\n (format t \"~A~%\" (solve (read-line))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1558315190, "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/s650471064.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s650471064", "user_id": "u736675286"}, "prompt_components": {"gold_output": "YYMM\n", "input_to_evaluate": "(defun mmp (n)\n (and (> n 0) (<= n 12)))\n\n(defun solve (s)\n (let ((before (parse-integer (subseq s 0 2)))\n (after (parse-integer (subseq s 2 4))))\n (cond\n ((and (mmp before) (mmp after)) \"AMBIGUOUS\")\n ((mmp before) \"MMYY\")\n ((mmp after) \"YYMM\")\n (t \"NA\"))))\n\n(defun main ()\n (format t \"~A~%\" (solve (read-line))))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 111, "memory_kb": 11620}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s162291202", "group_id": "codeNet:p03043", "input_text": "(defun dice (n k)\n (let ((log2 (log 2)))\n (labels ((dice0 (n0 rv)\n (if (or (= n0 k) (> n0 n)) rv\n (let ((nx (ceiling (/ (log (/ k n0)) log2))))\n ;(print `(:dice0 ,n0 ,nx))\n (dice0 (+ n0 1) (+ rv (/ 1 (expt 2 nx))))))))\n (let ((p0 (/ (dice0 1 0) n)))\n (if (< n k) p0\n (+ p0\n (/ (+ (- n k) 1) n)))))))\n\n#|\n(print (dice 3 10))\n(print (dice 100000 5))\n(format t \"~,10f\" (dice 3 10))\n(format t \"~,10f\" (dice 100000 5))\n|#\n\n(format t \"~,10f\" (dice (read) (read)))", "language": "Lisp", "metadata": {"date": 1558325899, "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/s162291202.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s162291202", "user_id": "u788952094"}, "prompt_components": {"gold_output": "0.145833333333\n", "input_to_evaluate": "(defun dice (n k)\n (let ((log2 (log 2)))\n (labels ((dice0 (n0 rv)\n (if (or (= n0 k) (> n0 n)) rv\n (let ((nx (ceiling (/ (log (/ k n0)) log2))))\n ;(print `(:dice0 ,n0 ,nx))\n (dice0 (+ n0 1) (+ rv (/ 1 (expt 2 nx))))))))\n (let ((p0 (/ (dice0 1 0) n)))\n (if (< n k) p0\n (+ p0\n (/ (+ (- n k) 1) n)))))))\n\n#|\n(print (dice 3 10))\n(print (dice 100000 5))\n(format t \"~,10f\" (dice 3 10))\n(format t \"~,10f\" (dice 100000 5))\n|#\n\n(format t \"~,10f\" (dice (read) (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 838, "memory_kb": 16488}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s345802061", "group_id": "codeNet:p03043", "input_text": "(defun solve (n k)\n (let ((x -1)\n (prev n)\n (ans 0))\n (loop :while (>= (/ k (expt 2 x)) 1)\n :do\n (setf x (1+ x))\n (let* ((newk (/ k (expt 2 x)))\n (per (* (/ (- prev (floor newk)) n) (expt (/ 1 2) x))))\n (format t \"newk ~A prev ~A per ~A~%\" newk prev per)\n (if (>= per 0)\n (progn\n (setf ans (+ ans per))\n (setf prev (floor newk))))))\n ans))\n\n(defun main ()\n (let ((n (read))\n (k (read)))\n (format t \"~A~%\" (solve n k))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1558318410, "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/s345802061.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s345802061", "user_id": "u736675286"}, "prompt_components": {"gold_output": "0.145833333333\n", "input_to_evaluate": "(defun solve (n k)\n (let ((x -1)\n (prev n)\n (ans 0))\n (loop :while (>= (/ k (expt 2 x)) 1)\n :do\n (setf x (1+ x))\n (let* ((newk (/ k (expt 2 x)))\n (per (* (/ (- prev (floor newk)) n) (expt (/ 1 2) x))))\n (format t \"newk ~A prev ~A per ~A~%\" newk prev per)\n (if (>= per 0)\n (progn\n (setf ans (+ ans per))\n (setf prev (floor newk))))))\n ans))\n\n(defun main ()\n (let ((n (read))\n (k (read)))\n (format t \"~A~%\" (solve n k))))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 598, "cpu_time_ms": 177, "memory_kb": 16608}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s962506611", "group_id": "codeNet:p03043", "input_text": "(let* ((n (read))\n (m (read)))\n (setf *read-default-float-format* 'double-float)\n (format t \"~a\" (float (* (/ 1 n) (loop :for j :from 2 :upto (length (format nil \"~b\" m)) :sum (expt 0.5 j))))))", "language": "Lisp", "metadata": {"date": 1558315866, "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/s962506611.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s962506611", "user_id": "u610490393"}, "prompt_components": {"gold_output": "0.145833333333\n", "input_to_evaluate": "(let* ((n (read))\n (m (read)))\n (setf *read-default-float-format* 'double-float)\n (format t \"~a\" (float (* (/ 1 n) (loop :for j :from 2 :upto (length (format nil \"~b\" m)) :sum (expt 0.5 j))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 139, "memory_kb": 13920}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s806260047", "group_id": "codeNet:p03044", "input_text": "(defconstant +color-unknown+ -1)\n(defconstant +color-white+ 0)\n(defconstant +color-black+ 1)\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 (stack nil)) ; 頂点の色。\n\n\n (push (list 0 +color-white+) stack)\n (loop while stack\n do\n (destructuring-bind (now mod) (pop stack)\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 (push (list next-vertex (mod (+ mod length) 2)) stack))))))\n\n (loop for i below n\n do\n (format t \"~A~%\" (aref color i))))))\n\n(defun next-int ()\n (read))\n\n;; 各頂点についてその接続情報を収めた表 g を生成して返す。\n;; g[頂点番号][各辺] = (list 辺の長さ 接続先の頂点)\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": 1558527267, "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/s806260047.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s806260047", "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(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 (stack nil)) ; 頂点の色。\n\n\n (push (list 0 +color-white+) stack)\n (loop while stack\n do\n (destructuring-bind (now mod) (pop stack)\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 (push (list next-vertex (mod (+ mod length) 2)) stack))))))\n\n (loop for i below n\n do\n (format t \"~A~%\" (aref color i))))))\n\n(defun next-int ()\n (read))\n\n;; 各頂点についてその接続情報を収めた表 g を生成して返す。\n;; g[頂点番号][各辺] = (list 辺の長さ 接続先の頂点)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2722, "cpu_time_ms": 936, "memory_kb": 62052}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s971458559", "group_id": "codeNet:p03044", "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 (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 (graph (make-array n :element-type 'list :initial-element nil))\n (res (make-array n :element-type 'int8 :initial-element -1)))\n (dotimes (i (- n 1))\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (w (read-fixnum)))\n (push (cons u w) (aref graph v))\n (push (cons v w) (aref graph u))))\n (labels ((dfs (v)\n (dolist (cell (aref graph v))\n (destructuring-bind (neighbor . cost) cell\n (when (= -1 (aref res neighbor))\n (setf (aref res neighbor)\n (if (= 0 (aref res v))\n (if (evenp cost) 0 1)\n (if (evenp cost) 1 0)))\n (dfs neighbor))))))\n (setf (aref res 0) 0)\n (dfs 0)\n (map () #'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 (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-cases)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 2\n2 3 1\n\"\n \"0\n0\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n2 5 2\n2 3 10\n1 3 8\n3 4 2\n\"\n \"1\n0\n1\n0\n1\n\")))\n", "language": "Lisp", "metadata": {"date": 1558315998, "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/s971458559.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s971458559", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\n0\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\" \"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 (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 (graph (make-array n :element-type 'list :initial-element nil))\n (res (make-array n :element-type 'int8 :initial-element -1)))\n (dotimes (i (- n 1))\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1))\n (w (read-fixnum)))\n (push (cons u w) (aref graph v))\n (push (cons v w) (aref graph u))))\n (labels ((dfs (v)\n (dolist (cell (aref graph v))\n (destructuring-bind (neighbor . cost) cell\n (when (= -1 (aref res neighbor))\n (setf (aref res neighbor)\n (if (= 0 (aref res v))\n (if (evenp cost) 0 1)\n (if (evenp cost) 1 0)))\n (dfs neighbor))))))\n (setf (aref res 0) 0)\n (dfs 0)\n (map () #'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 (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-cases)\n#+swank\n(it.bese.fiveam:test :sample\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n1 2 2\n2 3 1\n\"\n \"0\n0\n1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n2 5 2\n2 3 10\n1 3 8\n3 4 2\n\"\n \"1\n0\n1\n0\n1\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5534, "cpu_time_ms": 336, "memory_kb": 38072}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s926633474", "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 do (rplacd (gethash (read) ht)\n (root (gethash (read) ht)))\n (read)\n finally (princ (loop for v being each hash-value of ht\n count (null (cdr v)))))", "language": "Lisp", "metadata": {"date": 1600798428, "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/s926633474.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s926633474", "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 do (rplacd (gethash (read) ht)\n (root (gethash (read) ht)))\n (read)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 438, "cpu_time_ms": 297, "memory_kb": 80952}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s637136830", "group_id": "codeNet:p03045", "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 (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 (graph (make-array n :element-type 'list :initial-element nil))\n (zs (make-array n :element-type 'uint32))\n connects\n (marked (make-array n :element-type 'boolean :initial-element nil)))\n (dotimes (i m)\n (let ((x (- (read-fixnum) 1))\n (y (- (read-fixnum) 1))\n (z (read-fixnum)))\n (push x (aref graph y))\n (push y (aref graph x))\n (setf (aref zs i) z)))\n (labels ((dfs (pos)\n (setf (aref marked pos) t)\n (push pos (car connects))\n (dolist (neighbor (aref graph pos))\n (unless (aref marked neighbor)\n (dfs neighbor)))))\n (dotimes (i n)\n (unless (aref marked i)\n (push nil connects)\n (dfs i)))\n (println (length connects)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558317211, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s637136830.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s637136830", "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;; -*- 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 (graph (make-array n :element-type 'list :initial-element nil))\n (zs (make-array n :element-type 'uint32))\n connects\n (marked (make-array n :element-type 'boolean :initial-element nil)))\n (dotimes (i m)\n (let ((x (- (read-fixnum) 1))\n (y (- (read-fixnum) 1))\n (z (read-fixnum)))\n (push x (aref graph y))\n (push y (aref graph x))\n (setf (aref zs i) z)))\n (labels ((dfs (pos)\n (setf (aref marked pos) t)\n (push pos (car connects))\n (dolist (neighbor (aref graph pos))\n (unless (aref marked neighbor)\n (dfs neighbor)))))\n (dotimes (i n)\n (unless (aref marked i)\n (push nil connects)\n (dfs i)))\n (println (length connects)))))\n\n#-swank(main)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3669, "cpu_time_ms": 269, "memory_kb": 29752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s952685375", "group_id": "codeNet:p03048", "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;; 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 calc-min-factor))\n(defun calc-min-factor (x alpha)\n \"Returns k, so that x+k*alpha is the smallest non-negative number.\"\n (if (plusp alpha)\n (ceiling (- x) alpha)\n (floor (- x) alpha)))\n\n(declaim (inline calc-max-factor))\n(defun calc-max-factor (x alpha)\n \"Returns k, so that x+k*alpha is the largest non-positive number.\"\n (if (plusp alpha)\n (floor (- x) alpha)\n (ceiling (- x) alpha)))\n\n(defun solve-bezout (a b c &optional min max)\n \"Returns an integer solution of a*x+b*y = c, if it exists.\n\nIf MIN is specified and MAX is null, X is the smallest integer equal or larger\nthan MIN. If MAX is specified and MIN is null, X is the largest integer smaller\nthan MAX. If the both are specified, X is an integer in [MIN, MAX]. This\nfunction returns NIL when no x, that satisfies the given condition, exists.\"\n (declare (fixnum a b c)\n ((or null fixnum) min max))\n (let ((gcd-ab (gcd a b)))\n (if (zerop (mod c gcd-ab))\n (multiple-value-bind (init-x init-y) (ext-gcd a b)\n (let* ((factor (floor c gcd-ab))\n ;; m*x0 + n*y0 = d\n (x0 (* init-x factor))\n (y0 (* init-y factor)))\n (if (and (null min) (null max))\n (values x0 y0)\n (let (;; general solution: x = x0 + kΔx, y = y0 - kΔy\n (deltax (floor b gcd-ab))\n (deltay (floor a gcd-ab)))\n (if min\n (let* ((k-min (calc-min-factor (- x0 min) deltax))\n (x (+ x0 (* k-min deltax)))\n (y (- y0 (* k-min deltay))))\n (if (and max (> x max))\n (values nil nil)\n (values x y)))\n (let* ((k-max (calc-max-factor (- x0 max) deltax))\n (x (+ x0 (* k-max deltax)))\n (y (- y0 (* k-max deltay))))\n (if (<= x max)\n (values x y)\n (values nil nil))))))))\n (values nil nil))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *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* ((unit-r (read))\n (unit-g (read))\n (unit-b (read))\n (n (read))\n (res 0))\n (declare ((integer 0 3000) unit-r unit-g unit-b n)\n ((unsigned-byte 32) res))\n (loop for r to n by unit-r\n for rest = (- n r)\n do (let ((min-g (solve-bezout unit-g unit-b rest 0))\n (min-b (solve-bezout unit-b unit-g rest 0)))\n (when (and min-g min-b)\n (let* ((delta-g (floor unit-b (gcd unit-g unit-b)))\n (max-g (floor (- rest (* min-b unit-b)) unit-g)))\n (when (<= min-g max-g)\n (incf res (+ 1 (floor (- max-g min-g) delta-g))))))))\n (format t \"~D~%\" res)))\n \n#-swank(main)\n\n", "language": "Lisp", "metadata": {"date": 1557712843, "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/s952685375.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s952685375", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\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;; 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 calc-min-factor))\n(defun calc-min-factor (x alpha)\n \"Returns k, so that x+k*alpha is the smallest non-negative number.\"\n (if (plusp alpha)\n (ceiling (- x) alpha)\n (floor (- x) alpha)))\n\n(declaim (inline calc-max-factor))\n(defun calc-max-factor (x alpha)\n \"Returns k, so that x+k*alpha is the largest non-positive number.\"\n (if (plusp alpha)\n (floor (- x) alpha)\n (ceiling (- x) alpha)))\n\n(defun solve-bezout (a b c &optional min max)\n \"Returns an integer solution of a*x+b*y = c, if it exists.\n\nIf MIN is specified and MAX is null, X is the smallest integer equal or larger\nthan MIN. If MAX is specified and MIN is null, X is the largest integer smaller\nthan MAX. If the both are specified, X is an integer in [MIN, MAX]. This\nfunction returns NIL when no x, that satisfies the given condition, exists.\"\n (declare (fixnum a b c)\n ((or null fixnum) min max))\n (let ((gcd-ab (gcd a b)))\n (if (zerop (mod c gcd-ab))\n (multiple-value-bind (init-x init-y) (ext-gcd a b)\n (let* ((factor (floor c gcd-ab))\n ;; m*x0 + n*y0 = d\n (x0 (* init-x factor))\n (y0 (* init-y factor)))\n (if (and (null min) (null max))\n (values x0 y0)\n (let (;; general solution: x = x0 + kΔx, y = y0 - kΔy\n (deltax (floor b gcd-ab))\n (deltay (floor a gcd-ab)))\n (if min\n (let* ((k-min (calc-min-factor (- x0 min) deltax))\n (x (+ x0 (* k-min deltax)))\n (y (- y0 (* k-min deltay))))\n (if (and max (> x max))\n (values nil nil)\n (values x y)))\n (let* ((k-max (calc-max-factor (- x0 max) deltax))\n (x (+ x0 (* k-max deltax)))\n (y (- y0 (* k-max deltay))))\n (if (<= x max)\n (values x y)\n (values nil nil))))))))\n (values nil nil))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *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* ((unit-r (read))\n (unit-g (read))\n (unit-b (read))\n (n (read))\n (res 0))\n (declare ((integer 0 3000) unit-r unit-g unit-b n)\n ((unsigned-byte 32) res))\n (loop for r to n by unit-r\n for rest = (- n r)\n do (let ((min-g (solve-bezout unit-g unit-b rest 0))\n (min-b (solve-bezout unit-b unit-g rest 0)))\n (when (and min-g min-b)\n (let* ((delta-g (floor unit-b (gcd unit-g unit-b)))\n (max-g (floor (- rest (* min-b unit-b)) unit-g)))\n (when (<= min-g max-g)\n (incf res (+ 1 (floor (- max-g min-g) delta-g))))))))\n (format t \"~D~%\" res)))\n \n#-swank(main)\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5073, "cpu_time_ms": 230, "memory_kb": 29028}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s232285328", "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\n (cond\n ((= last-a first-b both) (1- last-a))\n (t (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": 1557630147, "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/s232285328.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s232285328", "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\n (cond\n ((= last-a first-b both) (1- last-a))\n (t (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1078, "cpu_time_ms": 358, "memory_kb": 23652}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s908073807", "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\n (cond\n ((= last-a first-b both) (1- last-a))\n (t (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": 1557629776, "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/s908073807.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s908073807", "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\n (cond\n ((= last-a first-b both) (1- last-a))\n (t (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1078, "cpu_time_ms": 419, "memory_kb": 23656}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s152483938", "group_id": "codeNet:p03050", "input_text": "(defun solve (n)\n (let ((sq (floor (sqrt n))))\n (loop :for i :from 1 :to sq\n :sum (if (zerop (rem (- n i) i)) (/ (- n i) i) 0))))\n\n(defun main ()\n (format t \"~A~%\" (solve (read))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1557632378, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03050.html", "problem_id": "p03050", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03050/input.txt", "sample_output_relpath": "derived/input_output/data/p03050/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03050/Lisp/s152483938.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s152483938", "user_id": "u736675286"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(defun solve (n)\n (let ((sq (floor (sqrt n))))\n (loop :for i :from 1 :to sq\n :sum (if (zerop (rem (- n i) i)) (/ (- n i) i) 0))))\n\n(defun main ()\n (format t \"~A~%\" (solve (read))))\n\n(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nSnuke received a positive integer N from Takahashi.\nA positive integer m is called a favorite number when the following condition is satisfied:\n\nThe quotient and remainder of N divided by m are equal, that is, \\lfloor \\frac{N}{m} \\rfloor = N \\bmod m holds.\n\nFind all favorite numbers and print the sum of those.\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 answer.\n\nSample Input 1\n\n8\n\nSample Output 1\n\n10\n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\nSample Input 2\n\n1000000000000\n\nSample Output 2\n\n2499686339916\n\nWatch out for overflow.", "sample_input": "8\n"}, "reference_outputs": ["10\n"], "source_document_id": "p03050", "source_text": "Score : 500 points\n\nProblem Statement\n\nSnuke received a positive integer N from Takahashi.\nA positive integer m is called a favorite number when the following condition is satisfied:\n\nThe quotient and remainder of N divided by m are equal, that is, \\lfloor \\frac{N}{m} \\rfloor = N \\bmod m holds.\n\nFind all favorite numbers and print the sum of those.\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 answer.\n\nSample Input 1\n\n8\n\nSample Output 1\n\n10\n\nThere are two favorite numbers: 3 and 7. Print the sum of these, 10.\n\nSample Input 2\n\n1000000000000\n\nSample Output 2\n\n2499686339916\n\nWatch out for overflow.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 265, "memory_kb": 16352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s621538883", "group_id": "codeNet:p03055", "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(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(declaim (inline println))\n(defun println (obj &optional (stream *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 (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)\n (setf (aref dist pos) len)\n (loop for next in (aref graph pos)\n unless (= next prev-pos)\n do (calc-length next pos (+ 1 len) dist))))\n (calc-length 0 -1 0 dist0)\n (let ((init-v (loop with v = 0\n with len = 0\n for i below n\n when (> (aref dist0 i) len)\n do (setf v i len (aref dist0 i))\n finally (return v))))\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": 1557026709, "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/s621538883.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s621538883", "user_id": "u352600849"}, "prompt_components": {"gold_output": "First\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(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(declaim (inline println))\n(defun println (obj &optional (stream *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 (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)\n (setf (aref dist pos) len)\n (loop for next in (aref graph pos)\n unless (= next prev-pos)\n do (calc-length next pos (+ 1 len) dist))))\n (calc-length 0 -1 0 dist0)\n (let ((init-v (loop with v = 0\n with len = 0\n for i below n\n when (> (aref dist0 i) len)\n do (setf v i len (aref dist0 i))\n finally (return v))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3904, "cpu_time_ms": 258, "memory_kb": 42036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s841704632", "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) (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-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(defconstant +max-complexity+ (ceiling (log (* 185 185) 2)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (cumuls (make-array '(186 186) :element-type 'uint16 :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 (186 186 186 #.(+ 1 +max-complexity+))\n :element-type 'uint8\n :initial-element #xff)\n (:array (186 186 186 #.(+ 1 +max-complexity+))\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 (+ 1 +max-complexity+))\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": 1566532502, "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/s841704632.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s841704632", "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) (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-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(defconstant +max-complexity+ (ceiling (log (* 185 185) 2)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (cumuls (make-array '(186 186) :element-type 'uint16 :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 (186 186 186 #.(+ 1 +max-complexity+))\n :element-type 'uint8\n :initial-element #xff)\n (:array (186 186 186 #.(+ 1 +max-complexity+))\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 (+ 1 +max-complexity+))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 16002, "cpu_time_ms": 4528, "memory_kb": 248676}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s797745208", "group_id": "codeNet:p03060", "input_text": "(defun solve (v c)\n (let ((ans 0))\n (loop :for v-item :in v\n :for c-item :in c\n :if (> v-item c-item)\n :do (setf ans (+ ans (- v-item c-item))))\n ans))\n\n(defun main ()\n (let* ((n (read))\n (v (loop :repeat n :collect (read)))\n (c (loop :repeat n :collect (read))))\n (format t \"~A~%\" (solve v c))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1556413879, "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/s797745208.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s797745208", "user_id": "u736675286"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun solve (v c)\n (let ((ans 0))\n (loop :for v-item :in v\n :for c-item :in c\n :if (> v-item c-item)\n :do (setf ans (+ ans (- v-item c-item))))\n ans))\n\n(defun main ()\n (let* ((n (read))\n (v (loop :repeat n :collect (read)))\n (c (loop :repeat n :collect (read))))\n (format t \"~A~%\" (solve v c))))\n\n(main)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 134, "memory_kb": 15968}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s811843259", "group_id": "codeNet:p03062", "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(let* ((n (read))\n (a (input n))\n (c (count-if (lambda (x) (< x 0)) a))\n (s (loop for i below n sum (abs (aref a i)))))\n (format t \"~A~%\"\n (if (evenp c)\n s\n (- s (* 2(loop for i below n\n minimize (abs (aref a i))))))))", "language": "Lisp", "metadata": {"date": 1556422848, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03062.html", "problem_id": "p03062", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03062/input.txt", "sample_output_relpath": "derived/input_output/data/p03062/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03062/Lisp/s811843259.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s811843259", "user_id": "u672956630"}, "prompt_components": {"gold_output": "19\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(let* ((n (read))\n (a (input n))\n (c (count-if (lambda (x) (< x 0)) a))\n (s (loop for i below n sum (abs (aref a i)))))\n (format t \"~A~%\"\n (if (evenp c)\n s\n (- s (* 2(loop for i below n\n minimize (abs (aref a i))))))))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.\n\nYou can perform the following operation on this integer sequence any number of times:\n\nOperation: Choose an integer i satisfying 1 \\leq i \\leq N-1. Multiply both A_i and A_{i+1} by -1.\n\nLet B_1, B_2, ..., B_N be the integer sequence after your operations.\n\nFind the maximum possible value of B_1 + B_2 + ... + B_N.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n-10^9 \\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 value of B_1 + B_2 + ... + B_N.\n\nSample Input 1\n\n3\n-10 5 -4\n\nSample Output 1\n\n19\n\nIf we perform the operation as follows:\n\nChoose 1 as i, which changes the sequence to 10, -5, -4.\n\nChoose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4 = 19, is the maximum possible result.\n\nSample Input 2\n\n5\n10 -4 -8 -11 3\n\nSample Output 2\n\n30\n\nSample Input 3\n\n11\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000\n\nSample Output 3\n\n10000000000\n\nThe output may not fit into a 32-bit integer type.", "sample_input": "3\n-10 5 -4\n"}, "reference_outputs": ["19\n"], "source_document_id": "p03062", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.\n\nYou can perform the following operation on this integer sequence any number of times:\n\nOperation: Choose an integer i satisfying 1 \\leq i \\leq N-1. Multiply both A_i and A_{i+1} by -1.\n\nLet B_1, B_2, ..., B_N be the integer sequence after your operations.\n\nFind the maximum possible value of B_1 + B_2 + ... + B_N.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n-10^9 \\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 value of B_1 + B_2 + ... + B_N.\n\nSample Input 1\n\n3\n-10 5 -4\n\nSample Output 1\n\n19\n\nIf we perform the operation as follows:\n\nChoose 1 as i, which changes the sequence to 10, -5, -4.\n\nChoose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4 = 19, is the maximum possible result.\n\nSample Input 2\n\n5\n10 -4 -8 -11 3\n\nSample Output 2\n\n30\n\nSample Input 3\n\n11\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000\n\nSample Output 3\n\n10000000000\n\nThe output may not fit into a 32-bit integer type.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 339, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s204414300", "group_id": "codeNet:p03062", "input_text": "(defparameter *a* #())\n(defparameter *ans* 0)\n\n(defun solve ()\n (loop :for i :across *a*\n :do (setf *ans* (+ *ans* (abs i))))\n\n (if (oddp (loop :for i :across *a* :count (<= i 0)))\n (let ((minimum 1000000000000))\n (loop :for i :across *a* :do (setf minimum (min minimum (abs i))))\n (setf *ans* (- *ans* (abs minimum)))))\n *ans*)\n\n(defun main ()\n (let* ((n (read))\n (a (loop :repeat n :collect (read))))\n (setf *a* (make-array (length a) :initial-contents a))\n (format t \"~A~%\" (solve))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1556418421, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03062.html", "problem_id": "p03062", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03062/input.txt", "sample_output_relpath": "derived/input_output/data/p03062/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03062/Lisp/s204414300.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s204414300", "user_id": "u736675286"}, "prompt_components": {"gold_output": "19\n", "input_to_evaluate": "(defparameter *a* #())\n(defparameter *ans* 0)\n\n(defun solve ()\n (loop :for i :across *a*\n :do (setf *ans* (+ *ans* (abs i))))\n\n (if (oddp (loop :for i :across *a* :count (<= i 0)))\n (let ((minimum 1000000000000))\n (loop :for i :across *a* :do (setf minimum (min minimum (abs i))))\n (setf *ans* (- *ans* (abs minimum)))))\n *ans*)\n\n(defun main ()\n (let* ((n (read))\n (a (loop :repeat n :collect (read))))\n (setf *a* (make-array (length a) :initial-contents a))\n (format t \"~A~%\" (solve))))\n\n(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.\n\nYou can perform the following operation on this integer sequence any number of times:\n\nOperation: Choose an integer i satisfying 1 \\leq i \\leq N-1. Multiply both A_i and A_{i+1} by -1.\n\nLet B_1, B_2, ..., B_N be the integer sequence after your operations.\n\nFind the maximum possible value of B_1 + B_2 + ... + B_N.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n-10^9 \\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 value of B_1 + B_2 + ... + B_N.\n\nSample Input 1\n\n3\n-10 5 -4\n\nSample Output 1\n\n19\n\nIf we perform the operation as follows:\n\nChoose 1 as i, which changes the sequence to 10, -5, -4.\n\nChoose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4 = 19, is the maximum possible result.\n\nSample Input 2\n\n5\n10 -4 -8 -11 3\n\nSample Output 2\n\n30\n\nSample Input 3\n\n11\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000\n\nSample Output 3\n\n10000000000\n\nThe output may not fit into a 32-bit integer type.", "sample_input": "3\n-10 5 -4\n"}, "reference_outputs": ["19\n"], "source_document_id": "p03062", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.\n\nYou can perform the following operation on this integer sequence any number of times:\n\nOperation: Choose an integer i satisfying 1 \\leq i \\leq N-1. Multiply both A_i and A_{i+1} by -1.\n\nLet B_1, B_2, ..., B_N be the integer sequence after your operations.\n\nFind the maximum possible value of B_1 + B_2 + ... + B_N.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq N \\leq 10^5\n\n-10^9 \\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 value of B_1 + B_2 + ... + B_N.\n\nSample Input 1\n\n3\n-10 5 -4\n\nSample Output 1\n\n19\n\nIf we perform the operation as follows:\n\nChoose 1 as i, which changes the sequence to 10, -5, -4.\n\nChoose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4 = 19, is the maximum possible result.\n\nSample Input 2\n\n5\n10 -4 -8 -11 3\n\nSample Output 2\n\n30\n\nSample Input 3\n\n11\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000\n\nSample Output 3\n\n10000000000\n\nThe output may not fit into a 32-bit integer type.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 540, "cpu_time_ms": 338, "memory_kb": 59880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s106028894", "group_id": "codeNet:p03063", "input_text": "(defun solve (rocks)\n (let ((found nil))\n (loop :for rock :across (reverse rocks)\n :when (char= rock #\\.)\n :do (setf found t)\n :count (and found (char= rock #\\#)))))\n\n(defun reverse-solve (rocks)\n (let ((found nil))\n (loop :for rock :across rocks\n :when (char= rock #\\#)\n :do (setf found t)\n :count (and found (char= rock #\\.)))))\n\n(defun main ()\n (read)\n (let ((rocks (read-line)))\n (format t \"~A~%\" (min (reverse-solve rocks) (solve rocks)))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1555809649, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03063.html", "problem_id": "p03063", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03063/input.txt", "sample_output_relpath": "derived/input_output/data/p03063/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03063/Lisp/s106028894.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s106028894", "user_id": "u736675286"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun solve (rocks)\n (let ((found nil))\n (loop :for rock :across (reverse rocks)\n :when (char= rock #\\.)\n :do (setf found t)\n :count (and found (char= rock #\\#)))))\n\n(defun reverse-solve (rocks)\n (let ((found nil))\n (loop :for rock :across rocks\n :when (char= rock #\\#)\n :do (setf found t)\n :count (and found (char= rock #\\.)))))\n\n(defun main ()\n (read)\n (let ((rocks (read-line)))\n (format t \"~A~%\" (min (reverse-solve rocks) (solve rocks)))))\n\n(main)\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": "p03063", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 525, "cpu_time_ms": 210, "memory_kb": 20832}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s298565314", "group_id": "codeNet:p03064", "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;; (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 foo (a b c d) ...) ; C is ignored.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\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 (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)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint16)))\n (dotimes (i n) (setf (aref as i) (read)))\n (let* ((s (reduce #'+ as))\n (s/2 (ceiling s 2)))\n (declare (uint32 s/2 s))\n (with-memoizing (:array (301 90001) :initial-element -1 :element-type 'int32)\n (labels ((recur (x u)\n (if (zerop x)\n (if (zerop u)\n 1\n 0)\n (if (>= u (aref as (- x 1)))\n (mod (+ (recur (- x 1) (- u (aref as (- x 1))))\n (* 2 (recur (- x 1) u)))\n +mod+)\n (mod (* 2 (recur (- x 1) u)) +mod+)))))\n (with-memoizing (:array (301 90001) :initial-element -1 :element-type 'int32)\n (labels ((subrecur (x u)\n (if (zerop x)\n (if (zerop u)\n 1\n 0)\n (if (>= u (aref as (- x 1)))\n (mod (+ (subrecur (- x 1) (- u (aref as (- x 1))))\n (subrecur (- x 1) u))\n +mod+)\n (subrecur (- x 1) u)))))\n (println\n (mod\n (- (expt 3 n)\n (if (oddp s)\n (* 3\n (loop with res of-type uint32 = 0\n for r from s/2 to s\n do (setf res (mod (+ res (recur n r)) +mod+))\n finally (return res)))\n (-\n (* 3\n (loop with res of-type uint32 = 0\n for r from s/2 to s\n do (setf res (mod (+ res (recur n r)) +mod+))\n finally (return res)))\n (* 3 (subrecur n s/2)))))\n +mod+)))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1555819831, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03064.html", "problem_id": "p03064", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03064/input.txt", "sample_output_relpath": "derived/input_output/data/p03064/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03064/Lisp/s298565314.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s298565314", "user_id": "u352600849"}, "prompt_components": {"gold_output": "18\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;; (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 foo (a b c d) ...) ; C is ignored.\n(declaim (type (integer 0 #.most-positive-fixnum) *recursion-depth*))\n(defparameter *recursion-depth* 0)\n\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 (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)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (as (make-array n :element-type 'uint16)))\n (dotimes (i n) (setf (aref as i) (read)))\n (let* ((s (reduce #'+ as))\n (s/2 (ceiling s 2)))\n (declare (uint32 s/2 s))\n (with-memoizing (:array (301 90001) :initial-element -1 :element-type 'int32)\n (labels ((recur (x u)\n (if (zerop x)\n (if (zerop u)\n 1\n 0)\n (if (>= u (aref as (- x 1)))\n (mod (+ (recur (- x 1) (- u (aref as (- x 1))))\n (* 2 (recur (- x 1) u)))\n +mod+)\n (mod (* 2 (recur (- x 1) u)) +mod+)))))\n (with-memoizing (:array (301 90001) :initial-element -1 :element-type 'int32)\n (labels ((subrecur (x u)\n (if (zerop x)\n (if (zerop u)\n 1\n 0)\n (if (>= u (aref as (- x 1)))\n (mod (+ (subrecur (- x 1) (- u (aref as (- x 1))))\n (subrecur (- x 1) u))\n +mod+)\n (subrecur (- x 1) u)))))\n (println\n (mod\n (- (expt 3 n)\n (if (oddp s)\n (* 3\n (loop with res of-type uint32 = 0\n for r from s/2 to s\n do (setf res (mod (+ res (recur n r)) +mod+))\n finally (return res)))\n (-\n (* 3\n (loop with res of-type uint32 = 0\n for r from s/2 to s\n do (setf res (mod (+ res (recur n r)) +mod+))\n finally (return res)))\n (* 3 (subrecur n s/2)))))\n +mod+)))))))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nYou are given N integers. The i-th integer is a_i.\nFind the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied:\n\nLet R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B.\n\nConstraints\n\n3 \\leq N \\leq 300\n\n1 \\leq a_i \\leq 300(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\n:\na_N\n\nOutput\n\nPrint the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied.\n\nSample Input 1\n\n4\n1\n1\n1\n2\n\nSample Output 1\n\n18\n\nWe can only paint the integers so that the lengths of the sides of the triangle will be 1, 2 and 2, and there are 18 such ways.\n\nSample Input 2\n\n6\n1\n3\n2\n3\n5\n2\n\nSample Output 2\n\n150\n\nSample Input 3\n\n20\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9\n3\n2\n3\n8\n4\n\nSample Output 3\n\n563038556", "sample_input": "4\n1\n1\n1\n2\n"}, "reference_outputs": ["18\n"], "source_document_id": "p03064", "source_text": "Score : 600 points\n\nProblem Statement\n\nYou are given N integers. The i-th integer is a_i.\nFind the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied:\n\nLet R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B.\n\nConstraints\n\n3 \\leq N \\leq 300\n\n1 \\leq a_i \\leq 300(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\n:\na_N\n\nOutput\n\nPrint the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied.\n\nSample Input 1\n\n4\n1\n1\n1\n2\n\nSample Output 1\n\n18\n\nWe can only paint the integers so that the lengths of the sides of the triangle will be 1, 2 and 2, and there are 18 such ways.\n\nSample Input 2\n\n6\n1\n3\n2\n3\n5\n2\n\nSample Output 2\n\n150\n\nSample Input 3\n\n20\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9\n3\n2\n3\n8\n4\n\nSample Output 3\n\n563038556", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10340, "cpu_time_ms": 811, "memory_kb": 248292}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s595544362", "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) c)) \"Yes\" \"No\")))", "language": "Lisp", "metadata": {"date": 1555815836, "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/s595544362.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s595544362", "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) c)) \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 98, "memory_kb": 10212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s340807383", "group_id": "codeNet:p03068", "input_text": "(let ((n (read))\n (s (read-line))\n (k (read)))\n (loop for i across s do\n (princ(if (eq i (char s (1- k))) i #\\*))))", "language": "Lisp", "metadata": {"date": 1555816009, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s340807383.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s340807383", "user_id": "u994767958"}, "prompt_components": {"gold_output": "*rr*r\n", "input_to_evaluate": "(let ((n (read))\n (s (read-line))\n (k (read)))\n (loop for i across s do\n (princ(if (eq i (char s (1- k))) i #\\*))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 110, "memory_kb": 12640}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s399489846", "group_id": "codeNet:p03068", "input_text": "(defparameter n (read))\n(defparameter s (read-line))\n(defparameter k (read))\n\n(defun f (str i)\n (let ((not* (char str (1- i))))\n (map 'string\n (lambda (c) (if (char= not* c) c #\\*))\n str)))\n\n(princ (f s k))\n", "language": "Lisp", "metadata": {"date": 1555809217, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s399489846.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s399489846", "user_id": "u956039157"}, "prompt_components": {"gold_output": "*rr*r\n", "input_to_evaluate": "(defparameter n (read))\n(defparameter s (read-line))\n(defparameter k (read))\n\n(defun f (str i)\n (let ((not* (char str (1- i))))\n (map 'string\n (lambda (c) (if (char= not* c) c #\\*))\n str)))\n\n(princ (f s k))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 172, "memory_kb": 15076}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s070101707", "group_id": "codeNet:p03069", "input_text": "(defparameter n (read))\n(defparameter s (coerce (read-line) 'list))\n\n(defun remove-# (lst)\n (cond ((endp lst) lst)\n ((char= #\\# (car lst)) (remove-# (cdr lst)))\n (t lst)))\n\n(defun remove-. (lst)\n (cond ((endp lst) lst)\n ((char= #\\. (car lst)) (remove-. (cdr lst)))\n (t lst)))\n\n(princ (min (count #\\. (remove-. s))\n (count #\\# (remove-# (reverse s)))))\n", "language": "Lisp", "metadata": {"date": 1555812550, "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/s070101707.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s070101707", "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 remove-# (lst)\n (cond ((endp lst) lst)\n ((char= #\\# (car lst)) (remove-# (cdr lst)))\n (t lst)))\n\n(defun remove-. (lst)\n (cond ((endp lst) lst)\n ((char= #\\. (car lst)) (remove-. (cdr lst)))\n (t lst)))\n\n(princ (min (count #\\. (remove-. s))\n (count #\\# (remove-# (reverse s)))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 393, "cpu_time_ms": 165, "memory_kb": 18912}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s373991993", "group_id": "codeNet:p03071", "input_text": "(defun solve (A B)\n (if (= A B) (* 2 A)\n (1- (* (max A B) 2))))\n\n(princ(solve (read)(read)))", "language": "Lisp", "metadata": {"date": 1584554182, "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/s373991993.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s373991993", "user_id": "u334552723"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun solve (A B)\n (if (= A B) (* 2 A)\n (1- (* (max A B) 2))))\n\n(princ(solve (read)(read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 127, "memory_kb": 12128}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s847222899", "group_id": "codeNet:p03071", "input_text": "(defun f (a b n)\n (cond\n ((zerop n) 0)\n ((> a b) (+ a (f (1- a) b (1- n))))\n (t (+ b (f a (1- b) (1- n))))))\n\n(let ((a (read))\n (b (read)))\n\n (format t \"~A~%\" (f a b 2)))", "language": "Lisp", "metadata": {"date": 1556594297, "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/s847222899.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s847222899", "user_id": "u321226359"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun f (a b n)\n (cond\n ((zerop n) 0)\n ((> a b) (+ a (f (1- a) b (1- n))))\n (t (+ b (f a (1- b) (1- n))))))\n\n(let ((a (read))\n (b (read)))\n\n (format t \"~A~%\" (f a b 2)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 38, "memory_kb": 5472}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s635409164", "group_id": "codeNet:p03073", "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 main ()\n (let* ((s (read-line)))\n (loop for b = 0 then (logxor b 1)\n for c across s\n count (= b (- (char-code c) 48)) into res\n finally (println (min res (- (length s) res))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1555233239, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03073.html", "problem_id": "p03073", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03073/input.txt", "sample_output_relpath": "derived/input_output/data/p03073/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03073/Lisp/s635409164.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s635409164", "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 (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 main ()\n (let* ((s (read-line)))\n (loop for b = 0 then (logxor b 1)\n for c across s\n count (= b (- (char-code c) 48)) into res\n finally (println (min res (- (length s) res))))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nN tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.\n\nThe i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1.\n\nYou want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.\n\nAt least how many tiles need to be repainted to satisfy the condition?\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS_i is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum number of tiles that need to be repainted to satisfy the condition.\n\nSample Input 1\n\n000\n\nSample Output 1\n\n1\n\nThe condition can be satisfied by repainting the middle tile white.\n\nSample Input 2\n\n10010010\n\nSample Output 2\n\n3\n\nSample Input 3\n\n0\n\nSample Output 3\n\n0", "sample_input": "000\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03073", "source_text": "Score : 300 points\n\nProblem Statement\n\nN tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.\n\nThe i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1.\n\nYou want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.\n\nAt least how many tiles need to be repainted to satisfy the condition?\n\nConstraints\n\n1 \\leq |S| \\leq 10^5\n\nS_i is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum number of tiles that need to be repainted to satisfy the condition.\n\nSample Input 1\n\n000\n\nSample Output 1\n\n1\n\nThe condition can be satisfied by repainting the middle tile white.\n\nSample Input 2\n\n10010010\n\nSample Output 2\n\n3\n\nSample Input 3\n\n0\n\nSample Output 3\n\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1407, "cpu_time_ms": 59, "memory_kb": 8804}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s517575776", "group_id": "codeNet:p03074", "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 dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 (s (make-array n :element-type 'bit))\n (cumul (make-array (1+ n) :fill-pointer 0 :element-type 'uint32)))\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref s i) (- (read-byte *standard-input*) 48)))\n (vector-push 0 cumul)\n (loop with base = 0\n with base-bit = (aref s 0)\n for i below n\n unless (= base-bit (aref s i))\n do (vector-push (- i base) cumul)\n (setf base i\n base-bit (aref s i))\n finally (vector-push (- i base) cumul))\n (dotimes (i n)\n (incf (aref cumul (1+ i)) (aref cumul i)))\n (println\n (loop with len = (length cumul)\n for l below (- len 1)\n for width = (if (zerop (aref s 0))\n (if (evenp l)\n (* 2 k)\n (+ (* 2 k) 1))\n (if (evenp l)\n (+ (* 2 k) 1)\n (* 2 k)))\n for r = (min (- len 1) (+ l width))\n maximize (- (aref cumul r) (aref cumul l))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1555226360, "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/s517575776.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s517575776", "user_id": "u352600849"}, "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 :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 main ()\n (let* ((n (read))\n (k (read))\n (s (make-array n :element-type 'bit))\n (cumul (make-array (1+ n) :fill-pointer 0 :element-type 'uint32)))\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref s i) (- (read-byte *standard-input*) 48)))\n (vector-push 0 cumul)\n (loop with base = 0\n with base-bit = (aref s 0)\n for i below n\n unless (= base-bit (aref s i))\n do (vector-push (- i base) cumul)\n (setf base i\n base-bit (aref s i))\n finally (vector-push (- i base) cumul))\n (dotimes (i n)\n (incf (aref cumul (1+ i)) (aref cumul i)))\n (println\n (loop with len = (length cumul)\n for l below (- len 1)\n for width = (if (zerop (aref s 0))\n (if (evenp l)\n (* 2 k)\n (+ (* 2 k) 1))\n (if (evenp l)\n (+ (* 2 k) 1)\n (* 2 k)))\n for r = (min (- len 1) (+ l width))\n maximize (- (aref cumul r) (aref cumul l))))))\n\n#-swank(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2318, "cpu_time_ms": 90, "memory_kb": 13540}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s040562305", "group_id": "codeNet:p03074", "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 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 (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 (string (make-string n :element-type 'base-char))\n (s (make-array n :element-type 'bit :initial-element 0))\n (cumul (make-array (1+ n) :fill-pointer 0 :initial-element 0 :element-type 'uint32)))\n (declare (uint31 n k))\n (read-line-into string)\n (dotimes (i n)\n (setf (aref s i) (- (char-code (aref string i)) 48)))\n (vector-push 0 cumul)\n (loop with base = 0\n with base-bit = (aref s 0)\n for i below n\n do (unless (= base-bit (aref s i))\n (vector-push (- i base) cumul)\n (setf base i\n base-bit (aref s i)))\n finally (vector-push (- i base) cumul))\n (dotimes (i n)\n (incf (aref cumul (1+ i)) (aref cumul i)))\n (println\n (loop with width = (if (zerop (aref s 0))\n (* 2 k)\n (+ (* 2 k) 1))\n for l below (length cumul)\n for r = (min n (+ l width))\n maximize (- (aref cumul r) (aref cumul l))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1555225787, "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/s040562305.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s040562305", "user_id": "u352600849"}, "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 :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 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 (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 (string (make-string n :element-type 'base-char))\n (s (make-array n :element-type 'bit :initial-element 0))\n (cumul (make-array (1+ n) :fill-pointer 0 :initial-element 0 :element-type 'uint32)))\n (declare (uint31 n k))\n (read-line-into string)\n (dotimes (i n)\n (setf (aref s i) (- (char-code (aref string i)) 48)))\n (vector-push 0 cumul)\n (loop with base = 0\n with base-bit = (aref s 0)\n for i below n\n do (unless (= base-bit (aref s i))\n (vector-push (- i base) cumul)\n (setf base i\n base-bit (aref s i)))\n finally (vector-push (- i base) cumul))\n (dotimes (i n)\n (incf (aref cumul (1+ i)) (aref cumul i)))\n (println\n (loop with width = (if (zerop (aref s 0))\n (* 2 k)\n (+ (* 2 k) 1))\n for l below (length cumul)\n for r = (min n (+ l width))\n maximize (- (aref cumul r) (aref cumul l))))))\n\n#-swank(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2845, "cpu_time_ms": 73, "memory_kb": 14824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s739300737", "group_id": "codeNet:p03075", "input_text": "(defun judge (xs k)\n (cond\n ((null xs) \"Yay!\")\n (<= (- (second xs) (first xs)) k) (judge (rest xs) k)\n (t \":(\")))\n\n\n(let* ((s (read-from-string\n (concatenate 'string \"(\" (read-line) \")\")))\n (xs (butlast s 1))\n (k (first (last s))))\n (princ (judge xs k)))", "language": "Lisp", "metadata": {"date": 1590694447, "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/s739300737.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s739300737", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yay!\n", "input_to_evaluate": "(defun judge (xs k)\n (cond\n ((null xs) \"Yay!\")\n (<= (- (second xs) (first xs)) k) (judge (rest xs) k)\n (t \":(\")))\n\n\n(let* ((s (read-from-string\n (concatenate 'string \"(\" (read-line) \")\")))\n (xs (butlast s 1))\n (k (first (last s))))\n (princ (judge xs k)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 20, "memory_kb": 4324}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s276268251", "group_id": "codeNet:p03075", "input_text": "(setq a (read) b (read) c (read) d (read) e (read))\n(defparameter k (read))\n(setq L (sort (list a b c d e) #'<))\n\n(if (> (- (car (last L)) (first L)) k) (princ \":(\") (princ \"Yay!\"))", "language": "Lisp", "metadata": {"date": 1563203342, "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/s276268251.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s276268251", "user_id": "u480300350"}, "prompt_components": {"gold_output": "Yay!\n", "input_to_evaluate": "(setq a (read) b (read) c (read) d (read) e (read))\n(defparameter k (read))\n(setq L (sort (list a b c d e) #'<))\n\n(if (> (- (car (last L)) (first L)) k) (princ \":(\") (princ \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 78, "memory_kb": 9064}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s692683157", "group_id": "codeNet:p03076", "input_text": "(let* ((lst (loop :repeat 5 :collect (read)))\n (lst-a (mapcar (lambda (k) (if (= 10 (- 10 (mod k 10)))\n 0\n (- 10 (mod k 10)))) lst)))\n (princ (- (+ (reduce #'+ lst) (reduce #'+ lst-a)) (reduce #'max lst-a))))", "language": "Lisp", "metadata": {"date": 1560156684, "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/s692683157.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s692683157", "user_id": "u610490393"}, "prompt_components": {"gold_output": "215\n", "input_to_evaluate": "(let* ((lst (loop :repeat 5 :collect (read)))\n (lst-a (mapcar (lambda (k) (if (= 10 (- 10 (mod k 10)))\n 0\n (- 10 (mod k 10)))) lst)))\n (princ (- (+ (reduce #'+ lst) (reduce #'+ lst-a)) (reduce #'max lst-a))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 4456}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s895537802", "group_id": "codeNet:p03076", "input_text": "(let* ((lst (loop :repeat 5 :collect (read)))\n (lst-a (mapcar (lambda (k) (if (= 10 (- 10 (mod k 10)))\n 0\n (- 10 (mod k 10)))) lst)))\n (format t \"~A~%~A~%\" lst lst-a)\n (princ (- (+ (reduce #'+ lst) (reduce #'+ lst-a)) (reduce #'max lst-a))))", "language": "Lisp", "metadata": {"date": 1560156630, "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/s895537802.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s895537802", "user_id": "u610490393"}, "prompt_components": {"gold_output": "215\n", "input_to_evaluate": "(let* ((lst (loop :repeat 5 :collect (read)))\n (lst-a (mapcar (lambda (k) (if (= 10 (- 10 (mod k 10)))\n 0\n (- 10 (mod k 10)))) lst)))\n (format t \"~A~%~A~%\" lst lst-a)\n (princ (- (+ (reduce #'+ lst) (reduce #'+ lst-a)) (reduce #'max lst-a))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 323, "cpu_time_ms": 120, "memory_kb": 12776}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s052999254", "group_id": "codeNet:p03078", "input_text": "(defparameter x (read))\n(defparameter y (read))\n(defparameter z (read))\n(defparameter k (read))\n(defparameter as\n (loop repeat x\n collect (read)))\n(defparameter bs\n (loop repeat y\n collect (read)))\n(defparameter cs\n (loop repeat z\n collect (read)))\n\n(defparameter sorted-as\n (sort as #'>=))\n(defparameter sorted-bs\n (sort bs #'>=))\n(defparameter sorted-cs\n (sort cs #'>=))\n\n(defun f (as bs cs k)\n (sort (loop for a in as nconc\n (loop for b in bs nconc\n (loop for c in cs collect\n (+ a b c))))\n #'>=))\n\n(loop repeat k\n for n in (f sorted-as sorted-bs sorted-cs k) do\n (format t \"~a~%\"\n n))\n", "language": "Lisp", "metadata": {"date": 1554582349, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03078.html", "problem_id": "p03078", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03078/input.txt", "sample_output_relpath": "derived/input_output/data/p03078/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03078/Lisp/s052999254.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s052999254", "user_id": "u956039157"}, "prompt_components": {"gold_output": "19\n17\n15\n14\n13\n12\n10\n8\n", "input_to_evaluate": "(defparameter x (read))\n(defparameter y (read))\n(defparameter z (read))\n(defparameter k (read))\n(defparameter as\n (loop repeat x\n collect (read)))\n(defparameter bs\n (loop repeat y\n collect (read)))\n(defparameter cs\n (loop repeat z\n collect (read)))\n\n(defparameter sorted-as\n (sort as #'>=))\n(defparameter sorted-bs\n (sort bs #'>=))\n(defparameter sorted-cs\n (sort cs #'>=))\n\n(defun f (as bs cs k)\n (sort (loop for a in as nconc\n (loop for b in bs nconc\n (loop for c in cs collect\n (+ a b c))))\n #'>=))\n\n(loop repeat k\n for n in (f sorted-as sorted-bs sorted-cs k) do\n (format t \"~a~%\"\n n))\n", "problem_context": "Score: 400 points\n\nProblem Statement\n\nThe Patisserie AtCoder sells cakes with number-shaped candles.\nThere are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively.\nEach cake has an integer value called deliciousness, as follows:\n\nThe deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.\n\nThe deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.\n\nThe deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.\n\nTakahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.\n\nThere are X \\times Y \\times Z such ways to choose three cakes.\n\nWe will arrange these X \\times Y \\times Z ways in descending order of the sum of the deliciousness of the cakes.\n\nPrint the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.\n\nConstraints\n\n1 \\leq X \\leq 1 \\ 000\n\n1 \\leq Y \\leq 1 \\ 000\n\n1 \\leq Z \\leq 1 \\ 000\n\n1 \\leq K \\leq \\min(3 \\ 000, X \\times Y \\times Z)\n\n1 \\leq A_i \\leq 10 \\ 000 \\ 000 \\ 000\n\n1 \\leq B_i \\leq 10 \\ 000 \\ 000 \\ 000\n\n1 \\leq C_i \\leq 10 \\ 000 \\ 000 \\ 000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y Z K\nA_1 \\ A_2 \\ A_3 \\ ... \\ A_X\nB_1 \\ B_2 \\ B_3 \\ ... \\ B_Y\nC_1 \\ C_2 \\ C_3 \\ ... \\ C_Z\n\nOutput\n\nPrint K lines. The i-th line should contain the i-th value stated in the problem statement.\n\nSample Input 1\n\n2 2 2 8\n4 6\n1 5\n3 8\n\nSample Output 1\n\n19\n17\n15\n14\n13\n12\n10\n8\n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:\n\n(A_2, B_2, C_2): 6 + 5 + 8 = 19\n\n(A_1, B_2, C_2): 4 + 5 + 8 = 17\n\n(A_2, B_1, C_2): 6 + 1 + 8 = 15\n\n(A_2, B_2, C_1): 6 + 5 + 3 = 14\n\n(A_1, B_1, C_2): 4 + 1 + 8 = 13\n\n(A_1, B_2, C_1): 4 + 5 + 3 = 12\n\n(A_2, B_1, C_1): 6 + 1 + 3 = 10\n\n(A_1, B_1, C_1): 4 + 1 + 3 = 8\n\nSample Input 2\n\n3 3 3 5\n1 10 100\n2 20 200\n1 10 100\n\nSample Output 2\n\n400\n310\n310\n301\n301\n\nThere may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301.\nHowever, they are different ways of choosing cakes, so 301 occurs twice in the output.\n\nSample Input 3\n\n10 10 10 20\n7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736\n\nSample Output 3\n\n23379871545\n22444657051\n22302177772\n22095691512\n21667941469\n21366963278\n21287912315\n21279176669\n21160477018\n21085311041\n21059876163\n21017997739\n20703329561\n20702387965\n20590247696\n20383761436\n20343962175\n20254073196\n20210218542\n20150096547\n\nNote that the input or output may not fit into a 32-bit integer type.", "sample_input": "2 2 2 8\n4 6\n1 5\n3 8\n"}, "reference_outputs": ["19\n17\n15\n14\n13\n12\n10\n8\n"], "source_document_id": "p03078", "source_text": "Score: 400 points\n\nProblem Statement\n\nThe Patisserie AtCoder sells cakes with number-shaped candles.\nThere are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively.\nEach cake has an integer value called deliciousness, as follows:\n\nThe deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.\n\nThe deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.\n\nThe deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.\n\nTakahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.\n\nThere are X \\times Y \\times Z such ways to choose three cakes.\n\nWe will arrange these X \\times Y \\times Z ways in descending order of the sum of the deliciousness of the cakes.\n\nPrint the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.\n\nConstraints\n\n1 \\leq X \\leq 1 \\ 000\n\n1 \\leq Y \\leq 1 \\ 000\n\n1 \\leq Z \\leq 1 \\ 000\n\n1 \\leq K \\leq \\min(3 \\ 000, X \\times Y \\times Z)\n\n1 \\leq A_i \\leq 10 \\ 000 \\ 000 \\ 000\n\n1 \\leq B_i \\leq 10 \\ 000 \\ 000 \\ 000\n\n1 \\leq C_i \\leq 10 \\ 000 \\ 000 \\ 000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y Z K\nA_1 \\ A_2 \\ A_3 \\ ... \\ A_X\nB_1 \\ B_2 \\ B_3 \\ ... \\ B_Y\nC_1 \\ C_2 \\ C_3 \\ ... \\ C_Z\n\nOutput\n\nPrint K lines. The i-th line should contain the i-th value stated in the problem statement.\n\nSample Input 1\n\n2 2 2 8\n4 6\n1 5\n3 8\n\nSample Output 1\n\n19\n17\n15\n14\n13\n12\n10\n8\n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:\n\n(A_2, B_2, C_2): 6 + 5 + 8 = 19\n\n(A_1, B_2, C_2): 4 + 5 + 8 = 17\n\n(A_2, B_1, C_2): 6 + 1 + 8 = 15\n\n(A_2, B_2, C_1): 6 + 5 + 3 = 14\n\n(A_1, B_1, C_2): 4 + 1 + 8 = 13\n\n(A_1, B_2, C_1): 4 + 5 + 3 = 12\n\n(A_2, B_1, C_1): 6 + 1 + 3 = 10\n\n(A_1, B_1, C_1): 4 + 1 + 3 = 8\n\nSample Input 2\n\n3 3 3 5\n1 10 100\n2 20 200\n1 10 100\n\nSample Output 2\n\n400\n310\n310\n301\n301\n\nThere may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301.\nHowever, they are different ways of choosing cakes, so 301 occurs twice in the output.\n\nSample Input 3\n\n10 10 10 20\n7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736\n\nSample Output 3\n\n23379871545\n22444657051\n22302177772\n22095691512\n21667941469\n21366963278\n21287912315\n21279176669\n21160477018\n21085311041\n21059876163\n21017997739\n20703329561\n20702387965\n20590247696\n20383761436\n20343962175\n20254073196\n20210218542\n20150096547\n\nNote that the input or output may not fit into a 32-bit integer type.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 704, "cpu_time_ms": 2109, "memory_kb": 934752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s735417515", "group_id": "codeNet:p03078", "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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:defknown init-vector (vector) vector (sb-c:flushable)\n :derive-type (sb-c::sequence-result-nth-arg 1 :preserve-dimensions t\n :preserve-vector-type t)\n :overwrite-fndb-silently t)\n\n (defun init-vector (vector)\n (make-array (length vector) :element-type (array-element-type vector)\n :adjustable (adjustable-array-p vector))))\n\n(declaim (inline %merge))\n(defun %merge (l mid r source-vec dest-vec predicate key)\n (declare ((mod #.array-total-size-limit) l mid r)\n (function predicate key))\n (loop 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 t))\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 t))\n do (if (funcall predicate\n (funcall key (aref source-vec i))\n (funcall key (aref source-vec j)))\n (setf (aref dest-vec idx) (aref source-vec i)\n i (1+ i))\n (setf (aref dest-vec idx) (aref source-vec j)\n j (1+ j)))))\n\n(declaim (inline %insertion-sort!))\n(defun %insertion-sort! (vec predicate l r key)\n (declare (function predicate key)\n ((mod #.array-total-size-limit) l r))\n (loop for end from (+ l 1) below r\n do (loop for i from end above l\n while (funcall predicate\n (funcall key (aref vec i))\n (funcall key (aref vec (- i 1))))\n do (rotatef (aref vec (- i 1)) (aref vec i)))\n finally (return vec)))\n\n(declaim (inline merge-sort!))\n(defun merge-sort! (vector predicate &key (start 0) end (key #'identity))\n (declare (vector vector)\n (function predicate key))\n (let ((end (or end (length vector))))\n (declare ((mod #.array-total-size-limit) 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))\n ((and (<= (- r l) 32) merge-to-vec1-p)\n (%insertion-sort! vec1 predicate l r key))\n ;; ((= (+ l 1) r)\n ;; (unless merge-to-vec1-p\n ;; (setf (aref vec2 l) (aref vec1 l))))\n ;; ((= (+ l 2) r)\n ;; ;; I put this clause just for efficiency.\n ;; (if (funcall predicate\n ;; (funcall key (aref vec1 l))\n ;; (funcall key (aref vec1 (- r 1))))\n ;; (unless merge-to-vec1-p\n ;; (setf (aref vec2 l) (aref vec1 l)\n ;; (aref vec2 (- r 1)) (aref vec1 (- r 1))))\n ;; (if merge-to-vec1-p\n ;; (rotatef (aref vec1 l) (aref vec1 (- r 1)))\n ;; (setf (aref vec2 l) (aref vec1 (- r 1))\n ;; (aref vec2 (- r 1)) (aref vec1 l)))))\n (t (let ((mid (floor (+ l r) 2)))\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 l mid r vec2 vec1 predicate key)\n (%merge l mid r vec1 vec2 predicate key)))))))\n (recurse start end t)\n vector)))))\n\n(defmacro with-output-buffer (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* and flushes them to\n*STANDARD-OUTPUT* at the end. Note that only BASE-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) (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 (inline sort))\n (let* ((x (read))\n (y (read))\n (z (read))\n (k (read))\n (as (make-array x :element-type 'uint62 :initial-element 0))\n (bs (make-array y :element-type 'uint62 :initial-element 0))\n (cs (make-array z :element-type 'uint62 :initial-element 0))\n (abs (make-array (* x y) :element-type 'uint62))\n (abcs (make-array (* k z) :element-type 'uint62)))\n (declare (uint16 x y z k))\n (dotimes (i x) (setf (aref as i) (read-fixnum)))\n (dotimes (i y) (setf (aref bs i) (read-fixnum)))\n (dotimes (i z) (setf (aref cs i) (read-fixnum)))\n (let ((index 0))\n (dotimes (i x)\n (dotimes (j y)\n (setf (aref abs index) (+ (aref as i) (aref bs j)))\n (incf index))))\n (merge-sort! abs #'>)\n (let ((index 0))\n (dotimes (i (min k (* x y)))\n (dotimes (j z)\n (setf (aref abcs index) (+ (aref abs i) (aref cs j)))\n (incf index))))\n (merge-sort! abcs #'>)\n (with-output-buffer\n (dotimes (i k)\n (println (aref abcs i))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1554579751, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03078.html", "problem_id": "p03078", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03078/input.txt", "sample_output_relpath": "derived/input_output/data/p03078/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03078/Lisp/s735417515.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s735417515", "user_id": "u352600849"}, "prompt_components": {"gold_output": "19\n17\n15\n14\n13\n12\n10\n8\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(eval-when (:compile-toplevel :load-toplevel :execute)\n (sb-c:defknown init-vector (vector) vector (sb-c:flushable)\n :derive-type (sb-c::sequence-result-nth-arg 1 :preserve-dimensions t\n :preserve-vector-type t)\n :overwrite-fndb-silently t)\n\n (defun init-vector (vector)\n (make-array (length vector) :element-type (array-element-type vector)\n :adjustable (adjustable-array-p vector))))\n\n(declaim (inline %merge))\n(defun %merge (l mid r source-vec dest-vec predicate key)\n (declare ((mod #.array-total-size-limit) l mid r)\n (function predicate key))\n (loop 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 t))\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 t))\n do (if (funcall predicate\n (funcall key (aref source-vec i))\n (funcall key (aref source-vec j)))\n (setf (aref dest-vec idx) (aref source-vec i)\n i (1+ i))\n (setf (aref dest-vec idx) (aref source-vec j)\n j (1+ j)))))\n\n(declaim (inline %insertion-sort!))\n(defun %insertion-sort! (vec predicate l r key)\n (declare (function predicate key)\n ((mod #.array-total-size-limit) l r))\n (loop for end from (+ l 1) below r\n do (loop for i from end above l\n while (funcall predicate\n (funcall key (aref vec i))\n (funcall key (aref vec (- i 1))))\n do (rotatef (aref vec (- i 1)) (aref vec i)))\n finally (return vec)))\n\n(declaim (inline merge-sort!))\n(defun merge-sort! (vector predicate &key (start 0) end (key #'identity))\n (declare (vector vector)\n (function predicate key))\n (let ((end (or end (length vector))))\n (declare ((mod #.array-total-size-limit) 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))\n ((and (<= (- r l) 32) merge-to-vec1-p)\n (%insertion-sort! vec1 predicate l r key))\n ;; ((= (+ l 1) r)\n ;; (unless merge-to-vec1-p\n ;; (setf (aref vec2 l) (aref vec1 l))))\n ;; ((= (+ l 2) r)\n ;; ;; I put this clause just for efficiency.\n ;; (if (funcall predicate\n ;; (funcall key (aref vec1 l))\n ;; (funcall key (aref vec1 (- r 1))))\n ;; (unless merge-to-vec1-p\n ;; (setf (aref vec2 l) (aref vec1 l)\n ;; (aref vec2 (- r 1)) (aref vec1 (- r 1))))\n ;; (if merge-to-vec1-p\n ;; (rotatef (aref vec1 l) (aref vec1 (- r 1)))\n ;; (setf (aref vec2 l) (aref vec1 (- r 1))\n ;; (aref vec2 (- r 1)) (aref vec1 l)))))\n (t (let ((mid (floor (+ l r) 2)))\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 l mid r vec2 vec1 predicate key)\n (%merge l mid r vec1 vec2 predicate key)))))))\n (recurse start end t)\n vector)))))\n\n(defmacro with-output-buffer (&body body)\n \"Buffers all outputs to *STANDARD-OUTPUT* and flushes them to\n*STANDARD-OUTPUT* at the end. Note that only BASE-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) (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 (inline sort))\n (let* ((x (read))\n (y (read))\n (z (read))\n (k (read))\n (as (make-array x :element-type 'uint62 :initial-element 0))\n (bs (make-array y :element-type 'uint62 :initial-element 0))\n (cs (make-array z :element-type 'uint62 :initial-element 0))\n (abs (make-array (* x y) :element-type 'uint62))\n (abcs (make-array (* k z) :element-type 'uint62)))\n (declare (uint16 x y z k))\n (dotimes (i x) (setf (aref as i) (read-fixnum)))\n (dotimes (i y) (setf (aref bs i) (read-fixnum)))\n (dotimes (i z) (setf (aref cs i) (read-fixnum)))\n (let ((index 0))\n (dotimes (i x)\n (dotimes (j y)\n (setf (aref abs index) (+ (aref as i) (aref bs j)))\n (incf index))))\n (merge-sort! abs #'>)\n (let ((index 0))\n (dotimes (i (min k (* x y)))\n (dotimes (j z)\n (setf (aref abcs index) (+ (aref abs i) (aref cs j)))\n (incf index))))\n (merge-sort! abcs #'>)\n (with-output-buffer\n (dotimes (i k)\n (println (aref abcs i))))))\n\n#-swank(main)\n", "problem_context": "Score: 400 points\n\nProblem Statement\n\nThe Patisserie AtCoder sells cakes with number-shaped candles.\nThere are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively.\nEach cake has an integer value called deliciousness, as follows:\n\nThe deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.\n\nThe deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.\n\nThe deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.\n\nTakahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.\n\nThere are X \\times Y \\times Z such ways to choose three cakes.\n\nWe will arrange these X \\times Y \\times Z ways in descending order of the sum of the deliciousness of the cakes.\n\nPrint the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.\n\nConstraints\n\n1 \\leq X \\leq 1 \\ 000\n\n1 \\leq Y \\leq 1 \\ 000\n\n1 \\leq Z \\leq 1 \\ 000\n\n1 \\leq K \\leq \\min(3 \\ 000, X \\times Y \\times Z)\n\n1 \\leq A_i \\leq 10 \\ 000 \\ 000 \\ 000\n\n1 \\leq B_i \\leq 10 \\ 000 \\ 000 \\ 000\n\n1 \\leq C_i \\leq 10 \\ 000 \\ 000 \\ 000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y Z K\nA_1 \\ A_2 \\ A_3 \\ ... \\ A_X\nB_1 \\ B_2 \\ B_3 \\ ... \\ B_Y\nC_1 \\ C_2 \\ C_3 \\ ... \\ C_Z\n\nOutput\n\nPrint K lines. The i-th line should contain the i-th value stated in the problem statement.\n\nSample Input 1\n\n2 2 2 8\n4 6\n1 5\n3 8\n\nSample Output 1\n\n19\n17\n15\n14\n13\n12\n10\n8\n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:\n\n(A_2, B_2, C_2): 6 + 5 + 8 = 19\n\n(A_1, B_2, C_2): 4 + 5 + 8 = 17\n\n(A_2, B_1, C_2): 6 + 1 + 8 = 15\n\n(A_2, B_2, C_1): 6 + 5 + 3 = 14\n\n(A_1, B_1, C_2): 4 + 1 + 8 = 13\n\n(A_1, B_2, C_1): 4 + 5 + 3 = 12\n\n(A_2, B_1, C_1): 6 + 1 + 3 = 10\n\n(A_1, B_1, C_1): 4 + 1 + 3 = 8\n\nSample Input 2\n\n3 3 3 5\n1 10 100\n2 20 200\n1 10 100\n\nSample Output 2\n\n400\n310\n310\n301\n301\n\nThere may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301.\nHowever, they are different ways of choosing cakes, so 301 occurs twice in the output.\n\nSample Input 3\n\n10 10 10 20\n7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736\n\nSample Output 3\n\n23379871545\n22444657051\n22302177772\n22095691512\n21667941469\n21366963278\n21287912315\n21279176669\n21160477018\n21085311041\n21059876163\n21017997739\n20703329561\n20702387965\n20590247696\n20383761436\n20343962175\n20254073196\n20210218542\n20150096547\n\nNote that the input or output may not fit into a 32-bit integer type.", "sample_input": "2 2 2 8\n4 6\n1 5\n3 8\n"}, "reference_outputs": ["19\n17\n15\n14\n13\n12\n10\n8\n"], "source_document_id": "p03078", "source_text": "Score: 400 points\n\nProblem Statement\n\nThe Patisserie AtCoder sells cakes with number-shaped candles.\nThere are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively.\nEach cake has an integer value called deliciousness, as follows:\n\nThe deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.\n\nThe deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.\n\nThe deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.\n\nTakahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.\n\nThere are X \\times Y \\times Z such ways to choose three cakes.\n\nWe will arrange these X \\times Y \\times Z ways in descending order of the sum of the deliciousness of the cakes.\n\nPrint the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.\n\nConstraints\n\n1 \\leq X \\leq 1 \\ 000\n\n1 \\leq Y \\leq 1 \\ 000\n\n1 \\leq Z \\leq 1 \\ 000\n\n1 \\leq K \\leq \\min(3 \\ 000, X \\times Y \\times Z)\n\n1 \\leq A_i \\leq 10 \\ 000 \\ 000 \\ 000\n\n1 \\leq B_i \\leq 10 \\ 000 \\ 000 \\ 000\n\n1 \\leq C_i \\leq 10 \\ 000 \\ 000 \\ 000\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y Z K\nA_1 \\ A_2 \\ A_3 \\ ... \\ A_X\nB_1 \\ B_2 \\ B_3 \\ ... \\ B_Y\nC_1 \\ C_2 \\ C_3 \\ ... \\ C_Z\n\nOutput\n\nPrint K lines. The i-th line should contain the i-th value stated in the problem statement.\n\nSample Input 1\n\n2 2 2 8\n4 6\n1 5\n3 8\n\nSample Output 1\n\n19\n17\n15\n14\n13\n12\n10\n8\n\nThere are 2 \\times 2 \\times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:\n\n(A_2, B_2, C_2): 6 + 5 + 8 = 19\n\n(A_1, B_2, C_2): 4 + 5 + 8 = 17\n\n(A_2, B_1, C_2): 6 + 1 + 8 = 15\n\n(A_2, B_2, C_1): 6 + 5 + 3 = 14\n\n(A_1, B_1, C_2): 4 + 1 + 8 = 13\n\n(A_1, B_2, C_1): 4 + 5 + 3 = 12\n\n(A_2, B_1, C_1): 6 + 1 + 3 = 10\n\n(A_1, B_1, C_1): 4 + 1 + 3 = 8\n\nSample Input 2\n\n3 3 3 5\n1 10 100\n2 20 200\n1 10 100\n\nSample Output 2\n\n400\n310\n310\n301\n301\n\nThere may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301.\nHowever, they are different ways of choosing cakes, so 301 occurs twice in the output.\n\nSample Input 3\n\n10 10 10 20\n7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488\n1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338\n4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736\n\nSample Output 3\n\n23379871545\n22444657051\n22302177772\n22095691512\n21667941469\n21366963278\n21287912315\n21279176669\n21160477018\n21085311041\n21059876163\n21017997739\n20703329561\n20702387965\n20590247696\n20383761436\n20343962175\n20254073196\n20210218542\n20150096547\n\nNote that the input or output may not fit into a 32-bit integer type.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7941, "cpu_time_ms": 79, "memory_kb": 8416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s081726972", "group_id": "codeNet:p03079", "input_text": "(defun solve (a b c)\n (if (= a b c)\n \"Yes\"\n \"No\"))\n\n(defun main ()\n (let ((a (read))\n (b (read))\n (c (read)))\n (format t \"~A~%\" (solve a b c))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1553976680, "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/s081726972.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s081726972", "user_id": "u736675286"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun solve (a b c)\n (if (= a b c)\n \"Yes\"\n \"No\"))\n\n(defun main ()\n (let ((a (read))\n (b (read))\n (c (read)))\n (format t \"~A~%\" (solve a b c))))\n\n(main)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 102, "memory_kb": 10856}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s309856124", "group_id": "codeNet:p03079", "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 main ()\n (let* ((a (read))\n (b (read))\n (c (read)))\n (write-line (if (= a b c ) \"Yes\" \"No\"))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1553976166, "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/s309856124.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s309856124", "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 (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 main ()\n (let* ((a (read))\n (b (read))\n (c (read)))\n (write-line (if (= a b c ) \"Yes\" \"No\"))))\n\n#-swank(main)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1313, "cpu_time_ms": 289, "memory_kb": 14436}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s859387863", "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 (declare (optimize (speed 3) (debug 0) (safety 0)))\n (loop for magic-word in magic-words\n do (destructuring-bind (ti di) magic-word\n (let* ((positions (char-positions ti address))\n (golems (mapcar (lambda (pos) (svref golem-vector pos))\n positions)))\n (loop pos in positions\n golem in golems do\n (let ((r-pos (1+ pos))\n (l-pos (1- pos)))\n (decf (svref golem-vector pos) golem)\n (cond ((and (char= di #\\R)\n (<= 0 r-pos (1- size)))\n (incf (svref golem-vector r-pos)\n golem))\n ((and (char= di #\\L)\n (<= 0 l-pos (1- size)))\n (incf (svref golem-vector l-pos)\n golem))))))))\n golem-vector)\n\n(defun vector-sum (vector)\n (declare (optimize (speed 3) (debug 0) (safety 0)))\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": 1553983931, "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/s859387863.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s859387863", "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 (declare (optimize (speed 3) (debug 0) (safety 0)))\n (loop for magic-word in magic-words\n do (destructuring-bind (ti di) magic-word\n (let* ((positions (char-positions ti address))\n (golems (mapcar (lambda (pos) (svref golem-vector pos))\n positions)))\n (loop pos in positions\n golem in golems do\n (let ((r-pos (1+ pos))\n (l-pos (1- pos)))\n (decf (svref golem-vector pos) golem)\n (cond ((and (char= di #\\R)\n (<= 0 r-pos (1- size)))\n (incf (svref golem-vector r-pos)\n golem))\n ((and (char= di #\\L)\n (<= 0 l-pos (1- size)))\n (incf (svref golem-vector l-pos)\n golem))))))))\n golem-vector)\n\n(defun vector-sum (vector)\n (declare (optimize (speed 3) (debug 0) (safety 0)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2023, "cpu_time_ms": 582, "memory_kb": 68168}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s851801684", "group_id": "codeNet:p03081", "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 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 (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,terminate-char))\n (return (values ,buffer ,idx))))))\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 (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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(declaim (inline to-code))\n(defun to-code (c) (- (char-code C) 65))\n\n(defun main ()\n (let* ((n (read))\n (q (read))\n (s (make-string n :element-type 'base-char))\n (seq (make-array n :element-type 'uint7))\n (operations (make-array q :element-type '(cons int32 int32))))\n (declare (uint32 n q))\n (read-line-into s)\n (dotimes (i n)\n (setf (aref seq i) (to-code (aref s i))))\n (dotimes (i q)\n (let* ((line (buffered-read-line 3))\n (code (to-code (char line 0)))\n (direction (if (char= #\\L (char line 2)) -1 1)))\n (setf (aref operations i) (cons code direction))))\n (labels ((escape-right-p (pos)\n (declare (int32 pos))\n (dotimes (i q nil)\n (when (= pos -1)\n (return nil))\n (when (= pos n)\n (return t))\n (let* ((op (aref operations i))\n (dir (cdr op))\n (object (car op)))\n (declare (int32 object dir))\n (when (= (aref seq pos) object)\n (incf pos dir))))\n (if (= pos n) t nil))\n (escape-left-p (pos)\n (declare (int32 pos))\n (dotimes (i q nil)\n (when (= pos -1)\n (return t))\n (when (= pos n)\n (return nil))\n (let* ((op (aref operations i))\n (dir (cdr op))\n (object (car op)))\n (declare (int32 object dir))\n (when (= (aref seq pos) object)\n (incf pos dir))))\n (if (= pos -1) t nil)))\n (let ((p (if (escape-right-p 0)\n 0\n (if (not (escape-right-p (- n 1)))\n n\n (nlet bisect ((ng 0) (ok n))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (floor (+ ng ok) 2)))\n (if (escape-right-p mid)\n (bisect ng mid)\n (bisect mid ok))))))))\n (q (if (escape-left-p (- n 1))\n (- n 1)\n (if (not (escape-left-p 0))\n -1\n (nlet bisect ((ok 0) (ng (- n 1)))\n (declare (int32 ng ok))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (floor (+ ng ok) 2)))\n (if (escape-left-p mid)\n (bisect mid ng)\n (bisect ok mid)))))))))\n (println (if (<= p q)\n 0\n (- p q 1)))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1553981784, "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/s851801684.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s851801684", "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 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 (when (< ,idx ,buffer-size)\n (setf (schar ,buffer ,idx) ,terminate-char))\n (return (values ,buffer ,idx))))))\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 (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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(declaim (inline to-code))\n(defun to-code (c) (- (char-code C) 65))\n\n(defun main ()\n (let* ((n (read))\n (q (read))\n (s (make-string n :element-type 'base-char))\n (seq (make-array n :element-type 'uint7))\n (operations (make-array q :element-type '(cons int32 int32))))\n (declare (uint32 n q))\n (read-line-into s)\n (dotimes (i n)\n (setf (aref seq i) (to-code (aref s i))))\n (dotimes (i q)\n (let* ((line (buffered-read-line 3))\n (code (to-code (char line 0)))\n (direction (if (char= #\\L (char line 2)) -1 1)))\n (setf (aref operations i) (cons code direction))))\n (labels ((escape-right-p (pos)\n (declare (int32 pos))\n (dotimes (i q nil)\n (when (= pos -1)\n (return nil))\n (when (= pos n)\n (return t))\n (let* ((op (aref operations i))\n (dir (cdr op))\n (object (car op)))\n (declare (int32 object dir))\n (when (= (aref seq pos) object)\n (incf pos dir))))\n (if (= pos n) t nil))\n (escape-left-p (pos)\n (declare (int32 pos))\n (dotimes (i q nil)\n (when (= pos -1)\n (return t))\n (when (= pos n)\n (return nil))\n (let* ((op (aref operations i))\n (dir (cdr op))\n (object (car op)))\n (declare (int32 object dir))\n (when (= (aref seq pos) object)\n (incf pos dir))))\n (if (= pos -1) t nil)))\n (let ((p (if (escape-right-p 0)\n 0\n (if (not (escape-right-p (- n 1)))\n n\n (nlet bisect ((ng 0) (ok n))\n (declare (int32 ng ok))\n (if (<= (- ok ng) 1)\n ok\n (let ((mid (floor (+ ng ok) 2)))\n (if (escape-right-p mid)\n (bisect ng mid)\n (bisect mid ok))))))))\n (q (if (escape-left-p (- n 1))\n (- n 1)\n (if (not (escape-left-p 0))\n -1\n (nlet bisect ((ok 0) (ng (- n 1)))\n (declare (int32 ng ok))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (floor (+ ng ok) 2)))\n (if (escape-left-p mid)\n (bisect mid ng)\n (bisect ok mid)))))))))\n (println (if (<= p q)\n 0\n (- p q 1)))))))\n\n#-swank(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5866, "cpu_time_ms": 251, "memory_kb": 31332}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s646443132", "group_id": "codeNet:p03085", "input_text": "(defun solve (b)\n (cond\n ((equal b \"A\") \"T\")\n ((equal b \"T\") \"A\")\n ((equal b \"G\") \"C\")\n ((equal b \"C\") \"G\")))\n\n\n(let ((b (read)))\n (princ (solve b)))", "language": "Lisp", "metadata": {"date": 1590694765, "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/s646443132.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s646443132", "user_id": "u425762225"}, "prompt_components": {"gold_output": "T\n", "input_to_evaluate": "(defun solve (b)\n (cond\n ((equal b \"A\") \"T\")\n ((equal b \"T\") \"A\")\n ((equal b \"G\") \"C\")\n ((equal b \"C\") \"G\")))\n\n\n(let ((b (read)))\n (princ (solve b)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 166, "cpu_time_ms": 9, "memory_kb": 3304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s220524469", "group_id": "codeNet:p03085", "input_text": "(defun solve (b)\n (cond\n ((string-equal b \"A\") \"T\")\n ((string-equal b \"T\") \"A\")\n ((string-equal b \"G\") \"C\")\n ((string-equal b \"C\") \"G\")))\n\n(defun main ()\n (let ((b (read)))\n (format t \"~A~%\" (solve b))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1553458319, "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/s220524469.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s220524469", "user_id": "u736675286"}, "prompt_components": {"gold_output": "T\n", "input_to_evaluate": "(defun solve (b)\n (cond\n ((string-equal b \"A\") \"T\")\n ((string-equal b \"T\") \"A\")\n ((string-equal b \"G\") \"C\")\n ((string-equal b \"C\") \"G\")))\n\n(defun main ()\n (let ((b (read)))\n (format t \"~A~%\" (solve b))))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 229, "cpu_time_ms": 298, "memory_kb": 10216}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s283266236", "group_id": "codeNet:p03086", "input_text": "(setq s(concatenate 'list(read-line)))\n(setq p 0)\n(princ(loop for c in s maximize(if(or(char= c #\\A)(char= c #\\T)(char= c #\\G)(char= c #\\C))(incf p)(setq p 0))))", "language": "Lisp", "metadata": {"date": 1553468400, "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/s283266236.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s283266236", "user_id": "u657913472"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(setq s(concatenate 'list(read-line)))\n(setq p 0)\n(princ(loop for c in s maximize(if(or(char= c #\\A)(char= c #\\T)(char= c #\\G)(char= c #\\C))(incf p)(setq p 0))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 146, "memory_kb": 14184}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s827667305", "group_id": "codeNet:p03086", "input_text": "(setq s(concatenate 'list(read-line)))\n(setq m 0)\n(setq p 0)\n(loop for i from 0 to(1-(length s))do\n (if(or(char= (nth i s)#\\A)(char= (nth i s)#\\T)(char= (nth i s)#\\G)(char= (nth i s)#\\C))\n (incf p)\n (progn(setq m(max m p))(setq p 0))))\n(princ(max m p))", "language": "Lisp", "metadata": {"date": 1553468255, "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/s827667305.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s827667305", "user_id": "u657913472"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(setq s(concatenate 'list(read-line)))\n(setq m 0)\n(setq p 0)\n(loop for i from 0 to(1-(length s))do\n (if(or(char= (nth i s)#\\A)(char= (nth i s)#\\T)(char= (nth i s)#\\G)(char= (nth i s)#\\C))\n (incf p)\n (progn(setq m(max m p))(setq p 0))))\n(princ(max m p))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 273, "cpu_time_ms": 146, "memory_kb": 14052}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s231205195", "group_id": "codeNet:p03087", "input_text": "(let* ((n (read))\n (q (read))\n (s (read-line))\n (ll (loop :repeat q :collect (cons (1- (read)) (1- (read)))))\n (ss (map 'vector (lambda (x) x)\n (cons 0 (loop :for k :from 1 :upto (1- n)\n :with j = 0\n :if (and (char= (aref s (1- k)) #\\A)\n (char= (aref s k) #\\C))\n :do (incf j) :end\n :collect j)))))\n (loop :for (x . y) :in ll\n :do (format t \"~A~%\" (- (aref ss y) (aref ss x)))))", "language": "Lisp", "metadata": {"date": 1583814025, "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/s231205195.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s231205195", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2\n0\n3\n", "input_to_evaluate": "(let* ((n (read))\n (q (read))\n (s (read-line))\n (ll (loop :repeat q :collect (cons (1- (read)) (1- (read)))))\n (ss (map 'vector (lambda (x) x)\n (cons 0 (loop :for k :from 1 :upto (1- n)\n :with j = 0\n :if (and (char= (aref s (1- k)) #\\A)\n (char= (aref s k) #\\C))\n :do (incf j) :end\n :collect j)))))\n (loop :for (x . y) :in ll\n :do (format t \"~A~%\" (- (aref ss y) (aref ss x)))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 636, "memory_kb": 62436}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s908500183", "group_id": "codeNet:p03090", "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 map-graph (n)\n;; (let ((sum (* n n))\n;; (table (make-array n :element-type 'uint32 :initial-element 0)))\n;; (dotimes (mask (expt 2 sum))\n;; (fill table 0)\n;; (dotimes (k sum)\n;; (let* ((j (mod k n))\n;; (i (floor k n)))\n;; (when (and (/= j i)\n;; (logbitp k mask))\n;; (incf (aref table i) (1+ j)))))\n;; (when (loop for i from 1 below n\n;; always (= (aref table i) (aref table (- i 1))))\n;; (format t \"~D:~%\" (aref table 0))\n;; (dotimes (i n)\n;; (dotimes (j n (terpri))\n;; (princ (ldb (byte 1 (+ (* n i) j)) mask))))))))\n\n;; (defun %test (n &optional (sample 1000))\n;; (let ((adja (make-array (list n n) :element-type 'bit :initial-element 0))\n;; (table (make-array n :element-type 'uint32 :initial-element 0)))\n;; (dotimes (i sample)\n;; (fill table 0)\n;; (fill (array-storage-vector adja) 0)\n;; (dotimes (i n)\n;; (loop for j from (1+ i) below n\n;; do (when (> (random 1.0) 0.5)\n;; (setf (aref adja i j) 1\n;; (aref adja j i) 1)\n;; (incf (aref table i) (+ 1 j))\n;; (incf (aref table j) (+ 1 i))))\n;; (when (loop for i from 1 below n\n;; always (and (not (zerop (aref table i)))\n;; (= (aref table i) (aref table (- i 1)))))\n;; (format t \"~D:~%\" (aref table 0))\n;; #>adja)))))\n\n;; ADJA => #2A((0 1 1 1 1 0 1)\n;; (1 0 1 1 0 1 1)\n;; (1 1 0 0 1 1 1)\n;; (1 1 0 0 1 1 1)\n;; (1 0 1 1 0 1 1)\n;; (0 1 1 1 1 0 1)\n;; (1 1 1 1 1 1 0))\n(defun main ()\n (let* ((n (read))\n (adja (make-array n :element-type 'bit :initial-element 0))\n res)\n (if (evenp n)\n (progn\n (dotimes (i n)\n (loop for j from (1+ i) below n\n do (unless (= (+ i j) (- n 1))\n (push (cons (1+ i) (1+ j)) res)))))\n (progn\n (dotimes (i n)\n (loop for j from (1+ i) below (- n 1)\n do (unless (= (+ i j) (- n 2))\n (push (cons (1+ i) (1+ j)) res))))\n (dotimes (i (- n 1))\n (push (cons (1+ i) n) res))))\n (println (length res))\n (dolist (pair res)\n (format t \"~D ~D~%\" (car pair) (cdr pair)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1553380685, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03090.html", "problem_id": "p03090", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03090/input.txt", "sample_output_relpath": "derived/input_output/data/p03090/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03090/Lisp/s908500183.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s908500183", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n1 3\n2 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 define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 map-graph (n)\n;; (let ((sum (* n n))\n;; (table (make-array n :element-type 'uint32 :initial-element 0)))\n;; (dotimes (mask (expt 2 sum))\n;; (fill table 0)\n;; (dotimes (k sum)\n;; (let* ((j (mod k n))\n;; (i (floor k n)))\n;; (when (and (/= j i)\n;; (logbitp k mask))\n;; (incf (aref table i) (1+ j)))))\n;; (when (loop for i from 1 below n\n;; always (= (aref table i) (aref table (- i 1))))\n;; (format t \"~D:~%\" (aref table 0))\n;; (dotimes (i n)\n;; (dotimes (j n (terpri))\n;; (princ (ldb (byte 1 (+ (* n i) j)) mask))))))))\n\n;; (defun %test (n &optional (sample 1000))\n;; (let ((adja (make-array (list n n) :element-type 'bit :initial-element 0))\n;; (table (make-array n :element-type 'uint32 :initial-element 0)))\n;; (dotimes (i sample)\n;; (fill table 0)\n;; (fill (array-storage-vector adja) 0)\n;; (dotimes (i n)\n;; (loop for j from (1+ i) below n\n;; do (when (> (random 1.0) 0.5)\n;; (setf (aref adja i j) 1\n;; (aref adja j i) 1)\n;; (incf (aref table i) (+ 1 j))\n;; (incf (aref table j) (+ 1 i))))\n;; (when (loop for i from 1 below n\n;; always (and (not (zerop (aref table i)))\n;; (= (aref table i) (aref table (- i 1)))))\n;; (format t \"~D:~%\" (aref table 0))\n;; #>adja)))))\n\n;; ADJA => #2A((0 1 1 1 1 0 1)\n;; (1 0 1 1 0 1 1)\n;; (1 1 0 0 1 1 1)\n;; (1 1 0 0 1 1 1)\n;; (1 0 1 1 0 1 1)\n;; (0 1 1 1 1 0 1)\n;; (1 1 1 1 1 1 0))\n(defun main ()\n (let* ((n (read))\n (adja (make-array n :element-type 'bit :initial-element 0))\n res)\n (if (evenp n)\n (progn\n (dotimes (i n)\n (loop for j from (1+ i) below n\n do (unless (= (+ i j) (- n 1))\n (push (cons (1+ i) (1+ j)) res)))))\n (progn\n (dotimes (i n)\n (loop for j from (1+ i) below (- n 1)\n do (unless (= (+ i j) (- n 2))\n (push (cons (1+ i) (1+ j)) res))))\n (dotimes (i (- n 1))\n (push (cons (1+ i) n) res))))\n (println (length res))\n (dolist (pair res)\n (format t \"~D ~D~%\" (car pair) (cdr pair)))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nYou are given an integer N.\nBuild an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:\n\nThe graph is simple and connected.\n\nThere exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.\n\nIt can be proved that at least one such graph exists under the constraints of this problem.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIn the first line, print the number of edges, M, in the graph you made. In the i-th of the following M lines, print two integers a_i and b_i, representing the endpoints of the i-th edge.\n\nThe output will be judged correct if the graph satisfies the conditions.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2\n1 3\n2 3\n\nFor every vertex, the sum of the indices of the vertices adjacent to that vertex is 3.", "sample_input": "3\n"}, "reference_outputs": ["2\n1 3\n2 3\n"], "source_document_id": "p03090", "source_text": "Score : 700 points\n\nProblem Statement\n\nYou are given an integer N.\nBuild an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:\n\nThe graph is simple and connected.\n\nThere exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.\n\nIt can be proved that at least one such graph exists under the constraints of this problem.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq N \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nIn the first line, print the number of edges, M, in the graph you made. In the i-th of the following M lines, print two integers a_i and b_i, representing the endpoints of the i-th edge.\n\nThe output will be judged correct if the graph satisfies the conditions.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2\n1 3\n2 3\n\nFor every vertex, the sum of the indices of the vertices adjacent to that vertex is 3.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3414, "cpu_time_ms": 451, "memory_kb": 18916}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s664591403", "group_id": "codeNet:p03096", "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\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 (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 ((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 ,@(extract-declarations body)\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 ,@(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 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 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) (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 (stones (make-array n :element-type 'uint31)))\n (dotimes (i n) (setf (aref stones i) (- (read) 1)))\n (let ((table (make-array n :element-type 'int32 :initial-element -1))\n (last-poses (make-array 200000 :element-type 'int32 :initial-element -1)))\n (loop with prev-color = -1\n for i from 0 below n\n do (let ((c (aref stones i)))\n (if (= prev-color c)\n (setf (aref table i) (aref table (- i 1)))\n (setf (aref table i) (aref last-poses c)\n (aref last-poses c) i\n prev-color c))))\n (println\n (with-memoizing (:array (200000) :element-type 'int32 :initial-element -1)\n (nlet recur ((i (- n 1)))\n (cond ((zerop i) 1)\n ((= (aref stones (- i 1)) (aref stones i))\n (recur (- i 1)))\n (t (loop with res = 0\n for last-pos = i then (aref table last-pos)\n until (= -1 last-pos)\n do (setf res (mod (+ res (recur (max 0 (- last-pos 1)))) +mod+))\n finally (return res))))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1552944099, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03096.html", "problem_id": "p03096", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03096/input.txt", "sample_output_relpath": "derived/input_output/data/p03096/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03096/Lisp/s664591403.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s664591403", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\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\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 (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 ((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 ,@(extract-declarations body)\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 ,@(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 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 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) (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 (stones (make-array n :element-type 'uint31)))\n (dotimes (i n) (setf (aref stones i) (- (read) 1)))\n (let ((table (make-array n :element-type 'int32 :initial-element -1))\n (last-poses (make-array 200000 :element-type 'int32 :initial-element -1)))\n (loop with prev-color = -1\n for i from 0 below n\n do (let ((c (aref stones i)))\n (if (= prev-color c)\n (setf (aref table i) (aref table (- i 1)))\n (setf (aref table i) (aref last-poses c)\n (aref last-poses c) i\n prev-color c))))\n (println\n (with-memoizing (:array (200000) :element-type 'int32 :initial-element -1)\n (nlet recur ((i (- n 1)))\n (cond ((zerop i) 1)\n ((= (aref stones (- i 1)) (aref stones i))\n (recur (- i 1)))\n (t (loop with res = 0\n for last-pos = i then (aref table last-pos)\n until (= -1 last-pos)\n do (setf res (mod (+ res (recur (max 0 (- last-pos 1)))) +mod+))\n finally (return res))))))))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nThere are N stones arranged in a row. The i-th stone from the left is painted in the color C_i.\n\nSnuke will perform the following operation zero or more times:\n\nChoose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.\n\nFind the number of possible final sequences of colors of the stones, modulo 10^9+7.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n1 \\leq C_i \\leq 2\\times 10^5(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\nC_1\n:\nC_N\n\nOutput\n\nPrint the number of possible final sequences of colors of the stones, modulo 10^9+7.\n\nSample Input 1\n\n5\n1\n2\n1\n2\n2\n\nSample Output 1\n\n3\n\nWe can make three sequences of colors of stones, as follows:\n\n(1,2,1,2,2), by doing nothing.\n\n(1,1,1,2,2), by choosing the first and third stones to perform the operation.\n\n(1,2,2,2,2), by choosing the second and fourth stones to perform the operation.\n\nSample Input 2\n\n6\n4\n2\n5\n4\n2\n4\n\nSample Output 2\n\n5\n\nSample Input 3\n\n7\n1\n3\n1\n2\n3\n3\n2\n\nSample Output 3\n\n5", "sample_input": "5\n1\n2\n1\n2\n2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03096", "source_text": "Score : 700 points\n\nProblem Statement\n\nThere are N stones arranged in a row. The i-th stone from the left is painted in the color C_i.\n\nSnuke will perform the following operation zero or more times:\n\nChoose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.\n\nFind the number of possible final sequences of colors of the stones, modulo 10^9+7.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 10^5\n\n1 \\leq C_i \\leq 2\\times 10^5(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\nC_1\n:\nC_N\n\nOutput\n\nPrint the number of possible final sequences of colors of the stones, modulo 10^9+7.\n\nSample Input 1\n\n5\n1\n2\n1\n2\n2\n\nSample Output 1\n\n3\n\nWe can make three sequences of colors of stones, as follows:\n\n(1,2,1,2,2), by doing nothing.\n\n(1,1,1,2,2), by choosing the first and third stones to perform the operation.\n\n(1,2,2,2,2), by choosing the second and fourth stones to perform the operation.\n\nSample Input 2\n\n6\n4\n2\n5\n4\n2\n4\n\nSample Output 2\n\n5\n\nSample Input 3\n\n7\n1\n3\n1\n2\n3\n3\n2\n\nSample Output 3\n\n5", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9521, "cpu_time_ms": 2112, "memory_kb": 95512}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s030126259", "group_id": "codeNet:p03101", "input_text": "(let ((h (read))\n (w (read))\n (h-b (read))\n (w-b (read)))\n (princ (* (- h h-b) (- w w-b))))", "language": "Lisp", "metadata": {"date": 1590695076, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03101.html", "problem_id": "p03101", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03101/input.txt", "sample_output_relpath": "derived/input_output/data/p03101/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03101/Lisp/s030126259.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s030126259", "user_id": "u425762225"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((h (read))\n (w (read))\n (h-b (read))\n (w-b (read)))\n (princ (* (- h h-b) (- w w-b))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are H rows and W columns of white square cells.\n\nYou will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns.\n\nHow many white cells will remain?\n\nIt can be proved that this count does not depend on what rows and columns are chosen.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq H, W \\leq 20\n\n1 \\leq h \\leq H\n\n1 \\leq w \\leq W\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nh w\n\nOutput\n\nPrint the number of white cells that will remain.\n\nSample Input 1\n\n3 2\n2 1\n\nSample Output 1\n\n1\n\nThere are 3 rows and 2 columns of cells. When two rows and one column are chosen and painted in black, there is always one white cell that remains.\n\nSample Input 2\n\n5 5\n2 3\n\nSample Output 2\n\n6\n\nSample Input 3\n\n2 4\n2 4\n\nSample Output 3\n\n0", "sample_input": "3 2\n2 1\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03101", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are H rows and W columns of white square cells.\n\nYou will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns.\n\nHow many white cells will remain?\n\nIt can be proved that this count does not depend on what rows and columns are chosen.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq H, W \\leq 20\n\n1 \\leq h \\leq H\n\n1 \\leq w \\leq W\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nh w\n\nOutput\n\nPrint the number of white cells that will remain.\n\nSample Input 1\n\n3 2\n2 1\n\nSample Output 1\n\n1\n\nThere are 3 rows and 2 columns of cells. When two rows and one column are chosen and painted in black, there is always one white cell that remains.\n\nSample Input 2\n\n5 5\n2 3\n\nSample Output 2\n\n6\n\nSample Input 3\n\n2 4\n2 4\n\nSample Output 3\n\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 79, "memory_kb": 9444}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s713370617", "group_id": "codeNet:p03101", "input_text": "(let ((a (cons (read) (read)))\n (b (cons (read) (read))))\n (princ (* (- (car a) (car b)) (- (cdr a) (cdr b)))))", "language": "Lisp", "metadata": {"date": 1552576426, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03101.html", "problem_id": "p03101", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03101/input.txt", "sample_output_relpath": "derived/input_output/data/p03101/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03101/Lisp/s713370617.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s713370617", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((a (cons (read) (read)))\n (b (cons (read) (read))))\n (princ (* (- (car a) (car b)) (- (cdr a) (cdr b)))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere are H rows and W columns of white square cells.\n\nYou will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns.\n\nHow many white cells will remain?\n\nIt can be proved that this count does not depend on what rows and columns are chosen.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq H, W \\leq 20\n\n1 \\leq h \\leq H\n\n1 \\leq w \\leq W\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nh w\n\nOutput\n\nPrint the number of white cells that will remain.\n\nSample Input 1\n\n3 2\n2 1\n\nSample Output 1\n\n1\n\nThere are 3 rows and 2 columns of cells. When two rows and one column are chosen and painted in black, there is always one white cell that remains.\n\nSample Input 2\n\n5 5\n2 3\n\nSample Output 2\n\n6\n\nSample Input 3\n\n2 4\n2 4\n\nSample Output 3\n\n0", "sample_input": "3 2\n2 1\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03101", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere are H rows and W columns of white square cells.\n\nYou will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns.\n\nHow many white cells will remain?\n\nIt can be proved that this count does not depend on what rows and columns are chosen.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq H, W \\leq 20\n\n1 \\leq h \\leq H\n\n1 \\leq w \\leq W\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\nh w\n\nOutput\n\nPrint the number of white cells that will remain.\n\nSample Input 1\n\n3 2\n2 1\n\nSample Output 1\n\n1\n\nThere are 3 rows and 2 columns of cells. When two rows and one column are chosen and painted in black, there is always one white cell that remains.\n\nSample Input 2\n\n5 5\n2 3\n\nSample Output 2\n\n6\n\nSample Input 3\n\n2 4\n2 4\n\nSample Output 3\n\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 97, "memory_kb": 9824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s997354075", "group_id": "codeNet:p03102", "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(let* ((n (read))\n\t (m (read))\n\t (c (read))\n\t (b (loop repeat m collect (read))))\n (princ \n\t(loop repeat n sum \n\t\t (if (> (+ c\n\t\t\t\t\t (loop for i in (loop repeat m collect (read))\n\t\t\t\t\t\t for j in b\n\t\t\t\t\t\t sum (* i j)))\n\t\t\t\t 0)\n\t\t\t1\n\t\t\t0))))\n", "language": "Lisp", "metadata": {"date": 1579984321, "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/s997354075.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s997354075", "user_id": "u493610446"}, "prompt_components": {"gold_output": "1\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(let* ((n (read))\n\t (m (read))\n\t (c (read))\n\t (b (loop repeat m collect (read))))\n (princ \n\t(loop repeat n sum \n\t\t (if (> (+ c\n\t\t\t\t\t (loop for i in (loop repeat m collect (read))\n\t\t\t\t\t\t for j in b\n\t\t\t\t\t\t sum (* i j)))\n\t\t\t\t 0)\n\t\t\t1\n\t\t\t0))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 31, "memory_kb": 9404}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s047659575", "group_id": "codeNet:p03102", "input_text": "(let ((n (read))\n (m (read))\n (c (read))\n (b (make-array 0 :element-type 'integer\n :adjustable t\n :fill-pointer 0))\n (ans 0))\n (loop repeat m do\n (vector-push-extend (read) b))\n (loop repeat n do\n (let ((temp c))\n (dotimes (i m)\n (incf temp (* (aref b i) (read))))\n (if (< 0 temp) (incf ans))))\n (princ ans))\n", "language": "Lisp", "metadata": {"date": 1552917705, "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/s047659575.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s047659575", "user_id": "u994767958"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((n (read))\n (m (read))\n (c (read))\n (b (make-array 0 :element-type 'integer\n :adjustable t\n :fill-pointer 0))\n (ans 0))\n (loop repeat m do\n (vector-push-extend (read) b))\n (loop repeat n do\n (let ((temp c))\n (dotimes (i m)\n (incf temp (* (aref b i) (read))))\n (if (< 0 temp) (incf ans))))\n (princ ans))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 419, "cpu_time_ms": 44, "memory_kb": 7784}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s317732748", "group_id": "codeNet:p03102", "input_text": "(let* ((n (read))\n (m (read))\n (c (read))\n (a (loop :repeat m :collect (read)))\n (lst (loop :repeat n :collect\n (loop :repeat m :collect (read)))))\n (defun func (b)\n (< 0 (reduce #'+ (cons c (mapcar #'* a b)))))\n (princ (count t (mapcar #'func lst)))\n )", "language": "Lisp", "metadata": {"date": 1552577213, "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/s317732748.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s317732748", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (c (read))\n (a (loop :repeat m :collect (read)))\n (lst (loop :repeat n :collect\n (loop :repeat m :collect (read)))))\n (defun func (b)\n (< 0 (reduce #'+ (cons c (mapcar #'* a b)))))\n (princ (count t (mapcar #'func lst)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 310, "cpu_time_ms": 74, "memory_kb": 9440}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s923011442", "group_id": "codeNet:p03102", "input_text": "(defun calc (B C)\n (let ((result 0)\n (tmp (list nil)))\n (dolist (x B)\n (push (* x (read)) tmp))\n (setq tmp (cdr (reverse tmp)))\n (dolist (x tmp)\n (setq result (+ result x)))\n (+ result C)))\n\n(defun main ()\n (let ((N (read))\n (M (read))\n (C (read))\n (B (list nil)))\n (dotimes (x M)\n (push (read) B))\n (setq B (cdr (reverse B)))\n (let ((count 0))\n (dotimes (x N)\n (let ((tmp (calc B C)))\n (when (> tmp 0)\n (incf count))))\n (print count))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1552165971, "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/s923011442.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s923011442", "user_id": "u631655863"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun calc (B C)\n (let ((result 0)\n (tmp (list nil)))\n (dolist (x B)\n (push (* x (read)) tmp))\n (setq tmp (cdr (reverse tmp)))\n (dolist (x tmp)\n (setq result (+ result x)))\n (+ result C)))\n\n(defun main ()\n (let ((N (read))\n (M (read))\n (C (read))\n (B (list nil)))\n (dotimes (x M)\n (push (read) B))\n (setq B (cdr (reverse B)))\n (let ((count 0))\n (dotimes (x N)\n (let ((tmp (calc B C)))\n (when (> tmp 0)\n (incf count))))\n (print count))))\n\n(main)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 548, "cpu_time_ms": 169, "memory_kb": 12900}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s932692900", "group_id": "codeNet:p03103", "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(defun main (m shops)\n (loop for shop in (sort shops (lambda (a b) (< (car a) (car b))))\n until (zerop m)\n sum \n (progn\n (let ((buy (min m (cdr shop))))\n (decf m buy)\n (* buy (car shop))))))\n\n(let* ((n (read))\n (m (read))\n (shops (collect-times n (cons (read) (read)))))\n (princ (main m shops)))\n", "language": "Lisp", "metadata": {"date": 1586290123, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s932692900.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s932692900", "user_id": "u493610446"}, "prompt_components": {"gold_output": "12\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(defun main (m shops)\n (loop for shop in (sort shops (lambda (a b) (< (car a) (car b))))\n until (zerop m)\n sum \n (progn\n (let ((buy (min m (cdr shop))))\n (decf m buy)\n (* buy (car shop))))))\n\n(let* ((n (read))\n (m (read))\n (shops (collect-times n (cons (read) (read)))))\n (princ (main m shops)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1407, "cpu_time_ms": 537, "memory_kb": 64572}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s357669500", "group_id": "codeNet:p03103", "input_text": "(defun main ()\n (let ((n (read))\n (m (read))\n (ab (list))\n (sab (list))\n (ans 0)\n temp)\n (loop repeat n do (setf ab (append ab (list (list (read) (read))))))\n (setf sab (sort ab #'(lambda (x y) (< (first x) (first y)))))\n (loop while (> m 0) do\n (setf temp (car ab))\n (incf ans (* (first temp) (min m (second temp))))\n (decf m (min m (second temp)))\n (setf ab (cdr ab)))\n (princ ans)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1552930259, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s357669500.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s357669500", "user_id": "u994767958"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(defun main ()\n (let ((n (read))\n (m (read))\n (ab (list))\n (sab (list))\n (ans 0)\n temp)\n (loop repeat n do (setf ab (append ab (list (list (read) (read))))))\n (setf sab (sort ab #'(lambda (x y) (< (first x) (first y)))))\n (loop while (> m 0) do\n (setf temp (car ab))\n (incf ans (* (first temp) (min m (second temp))))\n (decf m (min m (second temp)))\n (setf ab (cdr ab)))\n (princ ans)))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2106, "memory_kb": 71908}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s295259514", "group_id": "codeNet:p03103", "input_text": "(let ((n (read))\n (m (read))\n (ab (list))\n (sab (list))\n (ans 0))\n (loop repeat n do (setf ab (append ab (list (list (read) (read))))))\n (setf sab (sort ab #'(lambda (x y) (< (first x) (first y)))))\n (loop while (> m 0)\n do (incf ans (* (first (car ab)) (min m (second (car ab)))))\n (decf m (min m (second (car ab))))\n (setf ab (cdr ab)))\n (princ ans))\n", "language": "Lisp", "metadata": {"date": 1552929279, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s295259514.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s295259514", "user_id": "u994767958"}, "prompt_components": {"gold_output": "12\n", "input_to_evaluate": "(let ((n (read))\n (m (read))\n (ab (list))\n (sab (list))\n (ans 0))\n (loop repeat n do (setf ab (append ab (list (list (read) (read))))))\n (setf sab (sort ab #'(lambda (x y) (< (first x) (first y)))))\n (loop while (> m 0)\n do (incf ans (* (first (car ab)) (min m (second (car ab)))))\n (decf m (min m (second (car ab))))\n (setf ab (cdr ab)))\n (princ ans))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 404, "cpu_time_ms": 2106, "memory_kb": 71916}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s854214259", "group_id": "codeNet:p03106", "input_text": "(let ((a (read))\n (b (read))\n (k (read))\n (ans 0))\n\n (if (< a b)\n (let ((tmp a))\n (setq a b)\n (setq b tmp)\n )\n )\n (loop for i from 1 to a do\n (if (and (zerop (rem a i)) (zerop (rem b i)))\n (progn\n (decf k)\n (if (= k 0)\n (progn\n (princ i)\n (return)\n )\n )\n )\n )\n )\n)", "language": "Lisp", "metadata": {"date": 1594277426, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s854214259.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s854214259", "user_id": "u136500538"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (k (read))\n (ans 0))\n\n (if (< a b)\n (let ((tmp a))\n (setq a b)\n (setq b tmp)\n )\n )\n (loop for i from 1 to a do\n (if (and (zerop (rem a i)) (zerop (rem b i)))\n (progn\n (decf k)\n (if (= k 0)\n (progn\n (princ i)\n (return)\n )\n )\n )\n )\n )\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 24212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s794250664", "group_id": "codeNet:p03106", "input_text": "(defun calc-gcd (a b)\n (if (zerop (mod a b)) b (calc-gcd b (mod a b))))\n\n(defun calc-divisor (a)\n (loop :for x :from 1 :to a\n :when (zerop (mod a x))\n :collect x))\n\n(defun solve (a b k)\n (let* ((gcd (calc-gcd a b))\n (divisors (calc-divisor gcd)))\n (nth (1- k) (reverse divisors))))\n\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (k (read)))\n (format t \"~A~%\" (solve a b k))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1551645950, "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/s794250664.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s794250664", "user_id": "u736675286"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun calc-gcd (a b)\n (if (zerop (mod a b)) b (calc-gcd b (mod a b))))\n\n(defun calc-divisor (a)\n (loop :for x :from 1 :to a\n :when (zerop (mod a x))\n :collect x))\n\n(defun solve (a b k)\n (let* ((gcd (calc-gcd a b))\n (divisors (calc-divisor gcd)))\n (nth (1- k) (reverse divisors))))\n\n\n(defun main ()\n (let* ((a (read))\n (b (read))\n (k (read)))\n (format t \"~A~%\" (solve a b k))))\n\n(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 141, "memory_kb": 15976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s059047817", "group_id": "codeNet:p03107", "input_text": "(let ((s (read-line)))\n (princ (- (length s) (abs (- (count #\\1 s) (count #\\0 s))))))\n", "language": "Lisp", "metadata": {"date": 1551657146, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03107.html", "problem_id": "p03107", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03107/input.txt", "sample_output_relpath": "derived/input_output/data/p03107/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03107/Lisp/s059047817.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s059047817", "user_id": "u994767958"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((s (read-line)))\n (princ (- (length s) (abs (- (count #\\1 s) (count #\\0 s))))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N cubes stacked vertically on a desk.\n\nYou are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0, and blue if that character is 1.\n\nYou can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.\n\nAt most how many cubes can be removed?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n|S| = N\n\nEach character in S is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the maximum number of cubes that can be removed.\n\nSample Input 1\n\n0011\n\nSample Output 1\n\n4\n\nAll four cubes can be removed, by performing the operation as follows:\n\nRemove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n\nRemove the first and second cubes from the bottom.\n\nSample Input 2\n\n11011010001011\n\nSample Output 2\n\n12\n\nSample Input 3\n\n0\n\nSample Output 3\n\n0", "sample_input": "0011\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03107", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N cubes stacked vertically on a desk.\n\nYou are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0, and blue if that character is 1.\n\nYou can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.\n\nAt most how many cubes can be removed?\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n|S| = N\n\nEach character in S is 0 or 1.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the maximum number of cubes that can be removed.\n\nSample Input 1\n\n0011\n\nSample Output 1\n\n4\n\nAll four cubes can be removed, by performing the operation as follows:\n\nRemove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.\n\nRemove the first and second cubes from the bottom.\n\nSample Input 2\n\n11011010001011\n\nSample Output 2\n\n12\n\nSample Input 3\n\n0\n\nSample Output 3\n\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 24, "memory_kb": 6376}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s035264644", "group_id": "codeNet:p03108", "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* and flushes them to\n*STANDARD-OUTPUT* at the end. Note that only BASE-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;; Disjoint set by Union-Find\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 uint31 (*))))\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 #.OPT\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 \"Unites X1 and X2 destructively.\"\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 ;; guarantees 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 \"Checks if 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 (- (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 (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 define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 (as (make-array m :element-type 'uint31))\n (bs (make-array m :element-type 'uint31))\n (tree (make-disjoint-set n))\n (inconvs (make-array (1+ m) :element-type 'uint62)))\n (declare (uint31 n m))\n (setf (aref inconvs m) (floor (* n (- n 1)) 2))\n (dotimes (i m)\n (setf (aref as i) (- (read-fixnum) 1))\n (setf (aref bs i) (- (read-fixnum) 1)))\n (loop for i from (1- m) downto 0\n do (let* ((a (aref as i))\n (b (aref bs i)))\n (if (ds-connected-p a b tree)\n (setf (aref inconvs i)\n (aref inconvs (1+ i)))\n (setf (aref inconvs i)\n (- (aref inconvs (1+ i))\n (* (the uint31 (ds-size a tree))\n (the uint31 (ds-size b tree))))))\n (ds-unite! a b tree)))\n (with-output-buffer\n (loop for i from 1 to m\n do (println (aref inconvs i))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1555731158, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03108.html", "problem_id": "p03108", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03108/input.txt", "sample_output_relpath": "derived/input_output/data/p03108/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03108/Lisp/s035264644.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s035264644", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\n0\n4\n5\n6\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* and flushes them to\n*STANDARD-OUTPUT* at the end. Note that only BASE-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;; Disjoint set by Union-Find\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 uint31 (*))))\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 #.OPT\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 \"Unites X1 and X2 destructively.\"\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 ;; guarantees 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 \"Checks if 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 (- (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 (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 define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 (as (make-array m :element-type 'uint31))\n (bs (make-array m :element-type 'uint31))\n (tree (make-disjoint-set n))\n (inconvs (make-array (1+ m) :element-type 'uint62)))\n (declare (uint31 n m))\n (setf (aref inconvs m) (floor (* n (- n 1)) 2))\n (dotimes (i m)\n (setf (aref as i) (- (read-fixnum) 1))\n (setf (aref bs i) (- (read-fixnum) 1)))\n (loop for i from (1- m) downto 0\n do (let* ((a (aref as i))\n (b (aref bs i)))\n (if (ds-connected-p a b tree)\n (setf (aref inconvs i)\n (aref inconvs (1+ i)))\n (setf (aref inconvs i)\n (- (aref inconvs (1+ i))\n (* (the uint31 (ds-size a tree))\n (the uint31 (ds-size b tree))))))\n (ds-unite! a b tree)))\n (with-output-buffer\n (loop for i from 1 to m\n do (println (aref inconvs i))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N islands and M bridges.\n\nThe i-th bridge connects the A_i-th and B_i-th islands bidirectionally.\n\nInitially, we can travel between any two islands using some of these bridges.\n\nHowever, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge.\n\nLet the inconvenience be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining.\n\nFor each i (1 \\leq i \\leq M), find the inconvenience just after the i-th bridge collapses.\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 A_i < B_i \\leq N\n\nAll pairs (A_i, B_i) are distinct.\n\nThe inconvenience is initially 0.\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_M B_M\n\nOutput\n\nIn the order i = 1, 2, ..., M, print the inconvenience just after the i-th bridge collapses.\nNote that the answer may not fit into a 32-bit integer type.\n\nSample Input 1\n\n4 5\n1 2\n3 4\n1 3\n2 3\n1 4\n\nSample Output 1\n\n0\n0\n4\n5\n6\n\nFor example, when the first to third bridges have collapsed, the inconvenience is 4 since we can no longer travel between the pairs (1, 2), (1, 3), (2, 4) and (3, 4).\n\nSample Input 2\n\n6 5\n2 3\n1 2\n5 6\n3 4\n4 5\n\nSample Output 2\n\n8\n9\n12\n14\n15\n\nSample Input 3\n\n2 1\n1 2\n\nSample Output 3\n\n1", "sample_input": "4 5\n1 2\n3 4\n1 3\n2 3\n1 4\n"}, "reference_outputs": ["0\n0\n4\n5\n6\n"], "source_document_id": "p03108", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N islands and M bridges.\n\nThe i-th bridge connects the A_i-th and B_i-th islands bidirectionally.\n\nInitially, we can travel between any two islands using some of these bridges.\n\nHowever, the results of a survey show that these bridges will all collapse because of aging, in the order from the first bridge to the M-th bridge.\n\nLet the inconvenience be the number of pairs of islands (a, b) (a < b) such that we are no longer able to travel between the a-th and b-th islands using some of the bridges remaining.\n\nFor each i (1 \\leq i \\leq M), find the inconvenience just after the i-th bridge collapses.\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 A_i < B_i \\leq N\n\nAll pairs (A_i, B_i) are distinct.\n\nThe inconvenience is initially 0.\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_M B_M\n\nOutput\n\nIn the order i = 1, 2, ..., M, print the inconvenience just after the i-th bridge collapses.\nNote that the answer may not fit into a 32-bit integer type.\n\nSample Input 1\n\n4 5\n1 2\n3 4\n1 3\n2 3\n1 4\n\nSample Output 1\n\n0\n0\n4\n5\n6\n\nFor example, when the first to third bridges have collapsed, the inconvenience is 4 since we can no longer travel between the pairs (1, 2), (1, 3), (2, 4) and (3, 4).\n\nSample Input 2\n\n6 5\n2 3\n1 2\n5 6\n3 4\n4 5\n\nSample Output 2\n\n8\n9\n12\n14\n15\n\nSample Input 3\n\n2 1\n1 2\n\nSample Output 3\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4987, "cpu_time_ms": 249, "memory_kb": 39656}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s652679090", "group_id": "codeNet:p03109", "input_text": "(let ((s (read-line)))\n (if (string<= s \"2019/04/30\")\n (princ \"Heisei\")\n (princ \"TBD\"))) ", "language": "Lisp", "metadata": {"date": 1552419660, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03109.html", "problem_id": "p03109", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03109/input.txt", "sample_output_relpath": "derived/input_output/data/p03109/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03109/Lisp/s652679090.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s652679090", "user_id": "u652695471"}, "prompt_components": {"gold_output": "Heisei\n", "input_to_evaluate": "(let ((s (read-line)))\n (if (string<= s \"2019/04/30\")\n (princ \"Heisei\")\n (princ \"TBD\"))) ", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a string S as input. This represents a valid date in the year 2019 in the yyyy/mm/dd format. (For example, April 30, 2019 is represented as 2019/04/30.)\n\nWrite a program that prints Heisei if the date represented by S is not later than April 30, 2019, and prints TBD otherwise.\n\nConstraints\n\nS is a string that represents a valid date in the year 2019 in the yyyy/mm/dd format.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint Heisei if the date represented by S is not later than April 30, 2019, and print TBD otherwise.\n\nSample Input 1\n\n2019/04/30\n\nSample Output 1\n\nHeisei\n\nSample Input 2\n\n2019/11/01\n\nSample Output 2\n\nTBD", "sample_input": "2019/04/30\n"}, "reference_outputs": ["Heisei\n"], "source_document_id": "p03109", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a string S as input. This represents a valid date in the year 2019 in the yyyy/mm/dd format. (For example, April 30, 2019 is represented as 2019/04/30.)\n\nWrite a program that prints Heisei if the date represented by S is not later than April 30, 2019, and prints TBD otherwise.\n\nConstraints\n\nS is a string that represents a valid date in the year 2019 in the yyyy/mm/dd format.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint Heisei if the date represented by S is not later than April 30, 2019, and print TBD otherwise.\n\nSample Input 1\n\n2019/04/30\n\nSample Output 1\n\nHeisei\n\nSample Input 2\n\n2019/11/01\n\nSample Output 2\n\nTBD", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 87, "memory_kb": 8420}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s142444122", "group_id": "codeNet:p03110", "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(let ((n (read)))\n (princ \n\t(loop repeat n sum\n\t\t (let ((money (read))\n\t\t\t\t(kind (read)))\n\t\t\t(* money (if (eq kind 'JPY) 1 380000))))))\n", "language": "Lisp", "metadata": {"date": 1579984676, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03110.html", "problem_id": "p03110", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03110/input.txt", "sample_output_relpath": "derived/input_output/data/p03110/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03110/Lisp/s142444122.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s142444122", "user_id": "u493610446"}, "prompt_components": {"gold_output": "48000.0\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(let ((n (read)))\n (princ \n\t(loop repeat n sum\n\t\t (let ((money (read))\n\t\t\t\t(kind (read)))\n\t\t\t(* money (if (eq kind 'JPY) 1 380000))))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "sample_input": "2\n10000 JPY\n0.10000000 BTC\n"}, "reference_outputs": ["48000.0\n"], "source_document_id": "p03110", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 520, "cpu_time_ms": 171, "memory_kb": 15928}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s290523522", "group_id": "codeNet:p03110", "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(defvar n (read))\n(defun gifts (lst)\n (if (eq (cdr lst) 'BTC)\n (* (car lst) 380000.0)\n (car lst)))\n(defun main ()\n (println\n (loop for i below n\n sum (gifts (cons (read) (read))))))\n \n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559579774, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03110.html", "problem_id": "p03110", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03110/input.txt", "sample_output_relpath": "derived/input_output/data/p03110/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03110/Lisp/s290523522.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s290523522", "user_id": "u432998668"}, "prompt_components": {"gold_output": "48000.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))))\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(defvar n (read))\n(defun gifts (lst)\n (if (eq (cdr lst) 'BTC)\n (* (car lst) 380000.0)\n (car lst)))\n(defun main ()\n (println\n (loop for i below n\n sum (gifts (cons (read) (read))))))\n \n#-swank(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "sample_input": "2\n10000 JPY\n0.10000000 BTC\n"}, "reference_outputs": ["48000.0\n"], "source_document_id": "p03110", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2214, "cpu_time_ms": 179, "memory_kb": 19940}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s620756885", "group_id": "codeNet:p03110", "input_text": " (defun b (n &optional (stack nil))\n (let* ((line (read-line))\n (px (multiple-value-list (read-from-string line)))\n (x (car px))\n (u (read-from-string line t nil :start (cadr px))))\n (cond ((= n 1) \n (reduce #'+ (sort stack #'<)))\n ((eq u 'JPY) (b (1- n) (cons x stack)))\n ((eq u 'BTC) (b (1- n) (cons (* x 380000) stack))))))\n \n (format t \"~F\" (b (parse-integer (read-line))))", "language": "Lisp", "metadata": {"date": 1558793841, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03110.html", "problem_id": "p03110", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03110/input.txt", "sample_output_relpath": "derived/input_output/data/p03110/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03110/Lisp/s620756885.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s620756885", "user_id": "u608227593"}, "prompt_components": {"gold_output": "48000.0\n", "input_to_evaluate": " (defun b (n &optional (stack nil))\n (let* ((line (read-line))\n (px (multiple-value-list (read-from-string line)))\n (x (car px))\n (u (read-from-string line t nil :start (cadr px))))\n (cond ((= n 1) \n (reduce #'+ (sort stack #'<)))\n ((eq u 'JPY) (b (1- n) (cons x stack)))\n ((eq u 'BTC) (b (1- n) (cons (* x 380000) stack))))))\n \n (format t \"~F\" (b (parse-integer (read-line))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "sample_input": "2\n10000 JPY\n0.10000000 BTC\n"}, "reference_outputs": ["48000.0\n"], "source_document_id": "p03110", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 124, "memory_kb": 12132}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s721931458", "group_id": "codeNet:p03110", "input_text": "(princ(loop for i from 1 to(read)sum(*(read)(if(String=(read)\"BTC\")38e4 1))))", "language": "Lisp", "metadata": {"date": 1551367283, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03110.html", "problem_id": "p03110", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03110/input.txt", "sample_output_relpath": "derived/input_output/data/p03110/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03110/Lisp/s721931458.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s721931458", "user_id": "u657913472"}, "prompt_components": {"gold_output": "48000.0\n", "input_to_evaluate": "(princ(loop for i from 1 to(read)sum(*(read)(if(String=(read)\"BTC\")38e4 1))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "sample_input": "2\n10000 JPY\n0.10000000 BTC\n"}, "reference_outputs": ["48000.0\n"], "source_document_id": "p03110", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 94, "memory_kb": 9700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s218335543", "group_id": "codeNet:p03110", "input_text": "(defun solve (lst)\n (let ((prices (mapcar\n (lambda (price-and-unit)\n (let ((price (car price-and-unit))\n (unit (cadr price-and-unit)))\n (if (string-equal unit \"JPY\")\n price\n (* price 380000))))\n lst)))\n (apply '+ prices)))\n\n(defun main ()\n (let* ((n (read))\n (lst (loop for x from 1 to n\n collect `(,(read) ,(read)))))\n (format t \"~A~%\" (solve lst))))\n\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1551042112, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03110.html", "problem_id": "p03110", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03110/input.txt", "sample_output_relpath": "derived/input_output/data/p03110/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03110/Lisp/s218335543.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s218335543", "user_id": "u736675286"}, "prompt_components": {"gold_output": "48000.0\n", "input_to_evaluate": "(defun solve (lst)\n (let ((prices (mapcar\n (lambda (price-and-unit)\n (let ((price (car price-and-unit))\n (unit (cadr price-and-unit)))\n (if (string-equal unit \"JPY\")\n price\n (* price 380000))))\n lst)))\n (apply '+ prices)))\n\n(defun main ()\n (let* ((n (read))\n (lst (loop for x from 1 to n\n collect `(,(read) ,(read)))))\n (format t \"~A~%\" (solve lst))))\n\n\n(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "sample_input": "2\n10000 JPY\n0.10000000 BTC\n"}, "reference_outputs": ["48000.0\n"], "source_document_id": "p03110", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 538, "cpu_time_ms": 169, "memory_kb": 13284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s847537388", "group_id": "codeNet:p03110", "input_text": "(defun b (n &optional (jpy 0) (btc 0))\n (let* ((line (read-line))\n (px (multiple-value-list (read-from-string line)))\n (x (car px))\n (u (read-from-string line t nil :start (cadr px))))\n (cond ((= n 1) (+ jpy btc))\n ((string= u \"JPY\") (b (1- n) (+ jpy x) btc))\n ((string= u \"BTC\") (b (1- n) jpy (+ btc (* x 380000)))))))\n \n(format t \"~A\" (b (parse-integer (read-line))))", "language": "Lisp", "metadata": {"date": 1551041579, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03110.html", "problem_id": "p03110", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03110/input.txt", "sample_output_relpath": "derived/input_output/data/p03110/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03110/Lisp/s847537388.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s847537388", "user_id": "u608227593"}, "prompt_components": {"gold_output": "48000.0\n", "input_to_evaluate": "(defun b (n &optional (jpy 0) (btc 0))\n (let* ((line (read-line))\n (px (multiple-value-list (read-from-string line)))\n (x (car px))\n (u (read-from-string line t nil :start (cadr px))))\n (cond ((= n 1) (+ jpy btc))\n ((string= u \"JPY\") (b (1- n) (+ jpy x) btc))\n ((string= u \"BTC\") (b (1- n) jpy (+ btc (* x 380000)))))))\n \n(format t \"~A\" (b (parse-integer (read-line))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "sample_input": "2\n10000 JPY\n0.10000000 BTC\n"}, "reference_outputs": ["48000.0\n"], "source_document_id": "p03110", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi received otoshidama (New Year's money gifts) from N of his relatives.\n\nYou are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either JPY or BTC, and x_i and u_i represent the content of the otoshidama from the i-th relative.\n\nFor example, if x_1 = 10000 and u_1 = JPY, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = 0.10000000 and u_2 = BTC, the otoshidama from the second relative is 0.1 bitcoins.\n\nIf we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?\n\nConstraints\n\n2 \\leq N \\leq 10\n\nu_i = JPY or BTC.\n\nIf u_i = JPY, x_i is an integer such that 1 \\leq x_i \\leq 10^8.\n\nIf u_i = BTC, x_i is a decimal with 8 decimal digits, such that 0.00000001 \\leq x_i \\leq 100.00000000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 u_1\nx_2 u_2\n:\nx_N u_N\n\nOutput\n\nIf the gifts are worth Y yen in total, print the value Y (not necessarily an integer).\n\nOutput will be judged correct when the absolute or relative error from the judge's output is at most 10^{-5}.\n\nSample Input 1\n\n2\n10000 JPY\n0.10000000 BTC\n\nSample Output 1\n\n48000.0\n\nThe otoshidama from the first relative is 10000 yen. The otoshidama from the second relative is 0.1 bitcoins, which is worth 38000.0 yen if converted at the rate of 380000.0 JPY per 1.0 BTC. The sum of these is 48000.0 yen.\n\nOutputs such as 48000 and 48000.1 will also be judged correct.\n\nSample Input 2\n\n3\n100000000 JPY\n100.00000000 BTC\n0.00000001 BTC\n\nSample Output 2\n\n138000000.0038\n\nIn this case, outputs such as 138001000 and 1.38e8 will also be judged correct.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 419, "cpu_time_ms": 131, "memory_kb": 12644}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s568656727", "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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\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(defun main ()\n (let* ((a (read))\n (b (read))\n (q (read))\n (ss (make-array (+ a 4) :element-type 'fixnum :initial-element 0))\n (ts (make-array (+ b 4) :element-type 'fixnum :initial-element 0)))\n (setf (aref ss 0) most-negative-fixnum\n (aref ss 1) most-negative-fixnum\n (aref ss (+ a 2)) most-positive-fixnum\n (aref ss (+ a 3)) most-positive-fixnum\n (aref ts 0) most-negative-fixnum\n (aref ts 1) most-negative-fixnum\n (aref ts (+ b 2)) most-positive-fixnum\n (aref ts (+ b 3)) most-positive-fixnum)\n (loop for i from 2 to (+ a 1)\n do (setf (aref ss i) (read-fixnum)))\n (loop for i from 2 to (+ b 1)\n do (setf (aref ts i) (read-fixnum)))\n (labels ((find-s (x) (bisect-left ss x))\n (find-t (x) (bisect-left ts x))\n (find-smin (x)\n (if (< most-negative-fixnum x most-positive-fixnum)\n (let* ((r (bisect-left ss x))\n (l (- r 1)))\n (min (abs (- (aref ss r) x))\n (abs (- (aref ss l) x))))\n most-positive-fixnum))\n (find-tmin (x)\n (if (< most-negative-fixnum x most-positive-fixnum)\n (let* ((r (bisect-left ts x))\n (l (- r 1)))\n (min (abs (- (aref ts r) x))\n (abs (- (aref ts l) x))))\n most-positive-fixnum)))\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 (find-s x))\n (sl (- sr 1))\n (tr (find-t x))\n (tl (- tr 1)))\n (println\n (min (+ (abs (- x (aref ss sr)))\n (find-tmin (aref ss sr)))\n (+ (abs (- x (aref ss sl)))\n (find-tmin (aref ss sl)))\n (+ (abs (- x (aref ts tr)))\n (find-smin (aref ts tr)))\n (+ (abs (- x (aref ts tl)))\n (find-smin (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": 1599346509, "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/s568656727.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s568656727", "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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\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(defun main ()\n (let* ((a (read))\n (b (read))\n (q (read))\n (ss (make-array (+ a 4) :element-type 'fixnum :initial-element 0))\n (ts (make-array (+ b 4) :element-type 'fixnum :initial-element 0)))\n (setf (aref ss 0) most-negative-fixnum\n (aref ss 1) most-negative-fixnum\n (aref ss (+ a 2)) most-positive-fixnum\n (aref ss (+ a 3)) most-positive-fixnum\n (aref ts 0) most-negative-fixnum\n (aref ts 1) most-negative-fixnum\n (aref ts (+ b 2)) most-positive-fixnum\n (aref ts (+ b 3)) most-positive-fixnum)\n (loop for i from 2 to (+ a 1)\n do (setf (aref ss i) (read-fixnum)))\n (loop for i from 2 to (+ b 1)\n do (setf (aref ts i) (read-fixnum)))\n (labels ((find-s (x) (bisect-left ss x))\n (find-t (x) (bisect-left ts x))\n (find-smin (x)\n (if (< most-negative-fixnum x most-positive-fixnum)\n (let* ((r (bisect-left ss x))\n (l (- r 1)))\n (min (abs (- (aref ss r) x))\n (abs (- (aref ss l) x))))\n most-positive-fixnum))\n (find-tmin (x)\n (if (< most-negative-fixnum x most-positive-fixnum)\n (let* ((r (bisect-left ts x))\n (l (- r 1)))\n (min (abs (- (aref ts r) x))\n (abs (- (aref ts l) x))))\n most-positive-fixnum)))\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 (find-s x))\n (sl (- sr 1))\n (tr (find-t x))\n (tl (- tr 1)))\n (println\n (min (+ (abs (- x (aref ss sr)))\n (find-tmin (aref ss sr)))\n (+ (abs (- x (aref ss sl)))\n (find-tmin (aref ss sl)))\n (+ (abs (- x (aref ts tr)))\n (find-smin (aref ts tr)))\n (+ (abs (- x (aref ts tl)))\n (find-smin (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10785, "cpu_time_ms": 149, "memory_kb": 29188}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s367239675", "group_id": "codeNet:p03125", "input_text": "(defun aba (a b)\n (if (= (rem b a) 0)\n (+ b a)\n (- b a)\n )\n )\n(format t \"~A~%\"\n (aba (read) (read))\n )", "language": "Lisp", "metadata": {"date": 1561157675, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03125.html", "problem_id": "p03125", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03125/input.txt", "sample_output_relpath": "derived/input_output/data/p03125/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03125/Lisp/s367239675.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s367239675", "user_id": "u606976120"}, "prompt_components": {"gold_output": "16\n", "input_to_evaluate": "(defun aba (a b)\n (if (= (rem b a) 0)\n (+ b a)\n (- b a)\n )\n )\n(format t \"~A~%\"\n (aba (read) (read))\n )", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given positive integers A and B.\n\nIf A is a divisor of B, print A + B; otherwise, print B - A.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A \\leq B \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf A is a divisor of B, print A + B; otherwise, print B - A.\n\nSample Input 1\n\n4 12\n\nSample Output 1\n\n16\n\nAs 4 is a divisor of 12, 4 + 12 = 16 should be printed.\n\nSample Input 2\n\n8 20\n\nSample Output 2\n\n12\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\n2\n\n1 is a divisor of 1.", "sample_input": "4 12\n"}, "reference_outputs": ["16\n"], "source_document_id": "p03125", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given positive integers A and B.\n\nIf A is a divisor of B, print A + B; otherwise, print B - A.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq A \\leq B \\leq 20\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nIf A is a divisor of B, print A + B; otherwise, print B - A.\n\nSample Input 1\n\n4 12\n\nSample Output 1\n\n16\n\nAs 4 is a divisor of 12, 4 + 12 = 16 should be printed.\n\nSample Input 2\n\n8 20\n\nSample Output 2\n\n12\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\n2\n\n1 is a divisor of 1.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 11, "memory_kb": 3560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s336414114", "group_id": "codeNet:p03126", "input_text": "(let* ((n (read))\n (m (read))\n (counts (make-array (1+ m) :initial-element 0))\n (table ))\n (loop for i below n\n do\n (let ((ki (read)))\n (loop for j below ki\n do\n (incf (aref counts (read))))))\n (format t \"~A~%\"\n (loop for i from 1 to m\n count (= (aref counts i) n))))\n", "language": "Lisp", "metadata": {"date": 1556803382, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03126.html", "problem_id": "p03126", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03126/input.txt", "sample_output_relpath": "derived/input_output/data/p03126/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03126/Lisp/s336414114.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s336414114", "user_id": "u321226359"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (counts (make-array (1+ m) :initial-element 0))\n (table ))\n (loop for i below n\n do\n (let ((ki (read)))\n (loop for j below ki\n do\n (incf (aref counts (read))))))\n (format t \"~A~%\"\n (loop for i from 1 to m\n count (= (aref counts i) n))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nKatsusando loves omelette rice.\n\nBesides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.\n\nTo prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like these foods or not.\n\nThe i-th person answered that he/she only likes the A_{i1}-th, A_{i2}-th, ..., A_{iK_i}-th food.\n\nFind the number of the foods liked by all the N people.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, M \\leq 30\n\n1 \\leq K_i \\leq M\n\n1 \\leq A_{ij} \\leq M\n\nFor each i (1 \\leq i \\leq N), A_{i1}, A_{i2}, ..., A_{iK_i} are distinct.\n\nConstraints\n\nInput is given from Standard Input in the following format:\n\nN M\nK_1 A_{11} A_{12} ... A_{1K_1}\nK_2 A_{21} A_{22} ... A_{2K_2}\n:\nK_N A_{N1} A_{N2} ... A_{NK_N}\n\nOutput\n\nPrint the number of the foods liked by all the N people.\n\nSample Input 1\n\n3 4\n2 1 3\n3 1 2 3\n2 3 2\n\nSample Output 1\n\n1\n\nAs only the third food is liked by all the three people, 1 should be printed.\n\nSample Input 2\n\n5 5\n4 2 3 4 5\n4 1 3 4 5\n4 1 2 4 5\n4 1 2 3 5\n4 1 2 3 4\n\nSample Output 2\n\n0\n\nKatsusando's hypothesis turned out to be wrong.\n\nSample Input 3\n\n1 30\n3 5 10 30\n\nSample Output 3\n\n3", "sample_input": "3 4\n2 1 3\n3 1 2 3\n2 3 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03126", "source_text": "Score : 200 points\n\nProblem Statement\n\nKatsusando loves omelette rice.\n\nBesides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.\n\nTo prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like these foods or not.\n\nThe i-th person answered that he/she only likes the A_{i1}-th, A_{i2}-th, ..., A_{iK_i}-th food.\n\nFind the number of the foods liked by all the N people.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N, M \\leq 30\n\n1 \\leq K_i \\leq M\n\n1 \\leq A_{ij} \\leq M\n\nFor each i (1 \\leq i \\leq N), A_{i1}, A_{i2}, ..., A_{iK_i} are distinct.\n\nConstraints\n\nInput is given from Standard Input in the following format:\n\nN M\nK_1 A_{11} A_{12} ... A_{1K_1}\nK_2 A_{21} A_{22} ... A_{2K_2}\n:\nK_N A_{N1} A_{N2} ... A_{NK_N}\n\nOutput\n\nPrint the number of the foods liked by all the N people.\n\nSample Input 1\n\n3 4\n2 1 3\n3 1 2 3\n2 3 2\n\nSample Output 1\n\n1\n\nAs only the third food is liked by all the three people, 1 should be printed.\n\nSample Input 2\n\n5 5\n4 2 3 4 5\n4 1 3 4 5\n4 1 2 4 5\n4 1 2 3 5\n4 1 2 3 4\n\nSample Output 2\n\n0\n\nKatsusando's hypothesis turned out to be wrong.\n\nSample Input 3\n\n1 30\n3 5 10 30\n\nSample Output 3\n\n3", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 351, "cpu_time_ms": 23, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s212255158", "group_id": "codeNet:p03130", "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(defun main(likes)\n (length (reduce #'intersection likes)))\n\n(defun main (lines)\n (equal (sort (loop for i from 1 to 4\n collect\n (count i lines))\n #'<)\n (list 1 1 2 2)))\n\n(princ (if (main (read-times 6)) \"YES\" \"NO\"))\n", "language": "Lisp", "metadata": {"date": 1586312759, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03130.html", "problem_id": "p03130", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03130/input.txt", "sample_output_relpath": "derived/input_output/data/p03130/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03130/Lisp/s212255158.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s212255158", "user_id": "u493610446"}, "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(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(defun main(likes)\n (length (reduce #'intersection likes)))\n\n(defun main (lines)\n (equal (sort (loop for i from 1 to 4\n collect\n (count i lines))\n #'<)\n (list 1 1 2 2)))\n\n(princ (if (main (read-times 6)) \"YES\" \"NO\"))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are four towns, numbered 1,2,3 and 4.\nAlso, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally.\nNo two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.\n\nDetermine if we can visit all the towns by traversing each of the roads exactly once.\n\nConstraints\n\n1 \\leq a_i,b_i \\leq 4(1\\leq i\\leq 3)\n\na_i and b_i are different. (1\\leq i\\leq 3)\n\nNo two roads connect the same pair of towns.\n\nAny town can be reached from any other town using the roads.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na_1 b_1\na_2 b_2\na_3 b_3\n\nOutput\n\nIf we can visit all the towns by traversing each of the roads exactly once, print YES; otherwise, print NO.\n\nSample Input 1\n\n4 2\n1 3\n2 3\n\nSample Output 1\n\nYES\n\nWe can visit all the towns in the order 1,3,2,4.\n\nSample Input 2\n\n3 2\n2 4\n1 2\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n2 1\n3 2\n4 3\n\nSample Output 3\n\nYES", "sample_input": "4 2\n1 3\n2 3\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03130", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are four towns, numbered 1,2,3 and 4.\nAlso, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally.\nNo two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.\n\nDetermine if we can visit all the towns by traversing each of the roads exactly once.\n\nConstraints\n\n1 \\leq a_i,b_i \\leq 4(1\\leq i\\leq 3)\n\na_i and b_i are different. (1\\leq i\\leq 3)\n\nNo two roads connect the same pair of towns.\n\nAny town can be reached from any other town using the roads.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na_1 b_1\na_2 b_2\na_3 b_3\n\nOutput\n\nIf we can visit all the towns by traversing each of the roads exactly once, print YES; otherwise, print NO.\n\nSample Input 1\n\n4 2\n1 3\n2 3\n\nSample Output 1\n\nYES\n\nWe can visit all the towns in the order 1,3,2,4.\n\nSample Input 2\n\n3 2\n2 4\n1 2\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n2 1\n3 2\n4 3\n\nSample Output 3\n\nYES", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1315, "cpu_time_ms": 139, "memory_kb": 18616}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s773618446", "group_id": "codeNet:p03130", "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* (lst)\n (dotimes (i 6) (push (read) lst))\n (if (or (= 3 (count 1 lst))\n (= 3 (count 2 lst))\n (= 3 (count 3 lst))\n (= 3 (count 4 lst)))\n (println \"NO\")\n (println \"YES\"))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1549764311, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03130.html", "problem_id": "p03130", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03130/input.txt", "sample_output_relpath": "derived/input_output/data/p03130/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03130/Lisp/s773618446.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s773618446", "user_id": "u352600849"}, "prompt_components": {"gold_output": "YES\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* (lst)\n (dotimes (i 6) (push (read) lst))\n (if (or (= 3 (count 1 lst))\n (= 3 (count 2 lst))\n (= 3 (count 3 lst))\n (= 3 (count 4 lst)))\n (println \"NO\")\n (println \"YES\"))))\n\n#-swank(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are four towns, numbered 1,2,3 and 4.\nAlso, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally.\nNo two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.\n\nDetermine if we can visit all the towns by traversing each of the roads exactly once.\n\nConstraints\n\n1 \\leq a_i,b_i \\leq 4(1\\leq i\\leq 3)\n\na_i and b_i are different. (1\\leq i\\leq 3)\n\nNo two roads connect the same pair of towns.\n\nAny town can be reached from any other town using the roads.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na_1 b_1\na_2 b_2\na_3 b_3\n\nOutput\n\nIf we can visit all the towns by traversing each of the roads exactly once, print YES; otherwise, print NO.\n\nSample Input 1\n\n4 2\n1 3\n2 3\n\nSample Output 1\n\nYES\n\nWe can visit all the towns in the order 1,3,2,4.\n\nSample Input 2\n\n3 2\n2 4\n1 2\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n2 1\n3 2\n4 3\n\nSample Output 3\n\nYES", "sample_input": "4 2\n1 3\n2 3\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03130", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are four towns, numbered 1,2,3 and 4.\nAlso, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally.\nNo two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.\n\nDetermine if we can visit all the towns by traversing each of the roads exactly once.\n\nConstraints\n\n1 \\leq a_i,b_i \\leq 4(1\\leq i\\leq 3)\n\na_i and b_i are different. (1\\leq i\\leq 3)\n\nNo two roads connect the same pair of towns.\n\nAny town can be reached from any other town using the roads.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na_1 b_1\na_2 b_2\na_3 b_3\n\nOutput\n\nIf we can visit all the towns by traversing each of the roads exactly once, print YES; otherwise, print NO.\n\nSample Input 1\n\n4 2\n1 3\n2 3\n\nSample Output 1\n\nYES\n\nWe can visit all the towns in the order 1,3,2,4.\n\nSample Input 2\n\n3 2\n2 4\n1 2\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n2 1\n3 2\n4 3\n\nSample Output 3\n\nYES", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1179, "cpu_time_ms": 131, "memory_kb": 14820}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s160528039", "group_id": "codeNet:p03132", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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* ((l (read))\n (dp (make-array (list (+ l 1) 5) :element-type 'uint62 :initial-element 0))\n (as (make-array l :element-type 'uint32)))\n (declare (uint31 l))\n (dotimes (i l)\n (setf (aref as i) (read-fixnum)))\n (loop for x from 1 to l\n do (setf (aref dp x 0)\n (+ (aref dp (- x 1) 0)\n (aref as (- x 1))))\n (setf (aref dp x 1)\n (+ (min (aref dp (- x 1) 0)\n (aref dp (- x 1) 1))\n (if (evenp (aref as (- x 1)))\n (if (zerop (aref as (- x 1)))\n 2\n 0)\n 1)))\n (setf (aref dp x 2)\n (+ (min (aref dp (- x 1) 0)\n (aref dp (- x 1) 1)\n (aref dp (- x 1) 2))\n (if (oddp (aref as (- x 1))) 0 1)))\n (setf (aref dp x 3)\n (+ (min (aref dp (- x 1) 0)\n (aref dp (- x 1) 1)\n (aref dp (- x 1) 2)\n (aref dp (- x 1) 3))\n (if (evenp (aref as (- x 1)))\n (if (zerop (aref as (- x 1)))\n 2\n 0)\n 1)))\n (setf (aref dp x 4)\n (+ (min (aref dp (- x 1) 0)\n (aref dp (- x 1) 1)\n (aref dp (- x 1) 2)\n (aref dp (- x 1) 3)\n (aref dp (- x 1) 4))\n (aref as (- x 1)))))\n (println (min (aref dp l 0)\n (aref dp l 1)\n (aref dp l 2)\n (aref dp l 3)\n (aref dp l 4)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1568685161, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03132.html", "problem_id": "p03132", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03132/input.txt", "sample_output_relpath": "derived/input_output/data/p03132/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03132/Lisp/s160528039.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s160528039", "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(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* ((l (read))\n (dp (make-array (list (+ l 1) 5) :element-type 'uint62 :initial-element 0))\n (as (make-array l :element-type 'uint32)))\n (declare (uint31 l))\n (dotimes (i l)\n (setf (aref as i) (read-fixnum)))\n (loop for x from 1 to l\n do (setf (aref dp x 0)\n (+ (aref dp (- x 1) 0)\n (aref as (- x 1))))\n (setf (aref dp x 1)\n (+ (min (aref dp (- x 1) 0)\n (aref dp (- x 1) 1))\n (if (evenp (aref as (- x 1)))\n (if (zerop (aref as (- x 1)))\n 2\n 0)\n 1)))\n (setf (aref dp x 2)\n (+ (min (aref dp (- x 1) 0)\n (aref dp (- x 1) 1)\n (aref dp (- x 1) 2))\n (if (oddp (aref as (- x 1))) 0 1)))\n (setf (aref dp x 3)\n (+ (min (aref dp (- x 1) 0)\n (aref dp (- x 1) 1)\n (aref dp (- x 1) 2)\n (aref dp (- x 1) 3))\n (if (evenp (aref as (- x 1)))\n (if (zerop (aref as (- x 1)))\n 2\n 0)\n 1)))\n (setf (aref dp x 4)\n (+ (min (aref dp (- x 1) 0)\n (aref dp (- x 1) 1)\n (aref dp (- x 1) 2)\n (aref dp (- x 1) 3)\n (aref dp (- x 1) 4))\n (aref as (- x 1)))))\n (println (min (aref dp l 0)\n (aref dp l 1)\n (aref dp l 2)\n (aref dp l 3)\n (aref dp l 4)))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:\n\nHe never visits a point with coordinate less than 0, or a point with coordinate greater than L.\n\nHe starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.\n\nHe only changes direction at a point with integer coordinate.\n\nEach time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.\n\nAfter Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:\n\nPut a stone in one of Snuke's ears.\n\nRemove a stone from one of Snuke's ears.\n\nFind the minimum number of operations required when Ringo can freely decide how Snuke walks.\n\nConstraints\n\n1 \\leq L \\leq 2\\times 10^5\n\n0 \\leq A_i \\leq 10^9(1\\leq i\\leq L)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\nA_1\n:\nA_L\n\nOutput\n\nPrint the minimum number of operations required when Ringo can freely decide how Snuke walks.\n\nSample Input 1\n\n4\n1\n0\n2\n3\n\nSample Output 1\n\n1\n\nAssume that Snuke walks as follows:\n\nHe starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively.\nRingo can satisfy the requirement by putting one stone in the first ear.\n\nSample Input 2\n\n8\n2\n0\n0\n2\n1\n3\n4\n1\n\nSample Output 2\n\n3\n\nSample Input 3\n\n7\n314159265\n358979323\n846264338\n327950288\n419716939\n937510582\n0\n\nSample Output 3\n\n1", "sample_input": "4\n1\n0\n2\n3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03132", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions:\n\nHe never visits a point with coordinate less than 0, or a point with coordinate greater than L.\n\nHe starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.\n\nHe only changes direction at a point with integer coordinate.\n\nEach time when Snuke passes a point with coordinate i-0.5, where i is an integer, he put a stone in his i-th ear.\n\nAfter Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each i, Snuke's i-th ear contains A_i stones:\n\nPut a stone in one of Snuke's ears.\n\nRemove a stone from one of Snuke's ears.\n\nFind the minimum number of operations required when Ringo can freely decide how Snuke walks.\n\nConstraints\n\n1 \\leq L \\leq 2\\times 10^5\n\n0 \\leq A_i \\leq 10^9(1\\leq i\\leq L)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\nA_1\n:\nA_L\n\nOutput\n\nPrint the minimum number of operations required when Ringo can freely decide how Snuke walks.\n\nSample Input 1\n\n4\n1\n0\n2\n3\n\nSample Output 1\n\n1\n\nAssume that Snuke walks as follows:\n\nHe starts walking at coordinate 3 and finishes walking at coordinate 4, visiting coordinates 3,4,3,2,3,4 in this order.\n\nThen, Snuke's four ears will contain 0,0,2,3 stones, respectively.\nRingo can satisfy the requirement by putting one stone in the first ear.\n\nSample Input 2\n\n8\n2\n0\n0\n2\n1\n3\n4\n1\n\nSample Output 2\n\n3\n\nSample Input 3\n\n7\n314159265\n358979323\n846264338\n327950288\n419716939\n937510582\n0\n\nSample Output 3\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4344, "cpu_time_ms": 314, "memory_kb": 36960}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s998873933", "group_id": "codeNet:p03134", "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(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+ 10000)\n(defconstant +binom-mod+ +mod+)\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(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 stirling2))\n(defun stirling2 (n k)\n \"Returns the stirling number of the second kind S2(n, k). Time complexity is\nO(klog(n)).\"\n (declare ((integer 0 #.most-positive-fixnum) n k))\n (labels ((mod-power (base exp)\n (declare ((integer 0 #.most-positive-fixnum) base exp))\n (loop with res of-type (integer 0 #.most-positive-fixnum) = 1\n while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) +binom-mod+))\n do (setq base (mod (* base base) +binom-mod+)\n exp (ash exp -1))\n finally (return res))))\n (loop with result of-type fixnum = 0\n for i from 0 to k\n for delta = (mod (* (binom k i) (mod-power i n)) +binom-mod+)\n when (evenp (- k i))\n do (incf result delta)\n (when (>= result +binom-mod+)\n (decf result +binom-mod+))\n else\n do (decf result delta)\n (when (< result 0)\n (incf result +binom-mod+))\n finally (return (mod (* result (aref *fact-inv* k)) +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;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\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(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\n;;;\n;;; Body\n;;;\n\n;; (defun solve-small (s)\n;; (let ((n (length s))\n;; (table (make-hash-table :test #'equal)))\n;; (sb-int:named-let dfs ((list1 (loop for i below n\n;; collect (ecase (aref s i)\n;; (#\\0 0) (#\\1 0) (#\\2 1))))\n;; (list2 (loop for i below n\n;; collect (ecase (aref s i)\n;; (#\\0 0) (#\\1 1) (#\\2 1)))))\n;; (loop for b1 in list1\n;; for b2 in list2\n;; collect (cond ((and (= b1 b2 0)) 0)\n;; ((and (= b1 b2 1)) 1)\n;; (t 0))))))\n\n(define-mod-operations +mod+)\n(defun main ()\n (declare #.opt)\n (let* ((s (map '(simple-array uint8 (*)) #'digit-char-p (read-line)))\n (n (length s))\n (dp (make-array (list (+ n 1) (+ 1 (* 2 n)))\n :element-type 'uint31\n :initial-element 0)))\n (setf (aref dp 0 0) 1)\n #>s\n (dotimes (x n)\n (let ((c (aref s x)))\n (dotimes (y (+ 1 (* 2 n)))\n (unless (zerop (aref dp x y))\n (let ((num0 (+ y (- 2 c)))\n (num1 (+ (- x y) c)))\n (when (> num0 0)\n (incfmod (aref dp (+ x 1) (- num0 1))\n (aref dp x y)))\n (when (> num1 0)\n (incfmod (aref dp (+ x 1) num0)\n (aref dp x y))))))))\n (let ((res 0))\n (loop for y from 0 to n\n do (incfmod res (mod* (aref dp n y) (binom n y))))\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 \"02\n\" nil)))\n (it.bese.fiveam:is\n (equal \"55\n\"\n (run \"1210\n\" nil)))\n (it.bese.fiveam:is\n (equal \"543589959\n\"\n (run \"12001021211100201020\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1596775685, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03134.html", "problem_id": "p03134", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03134/input.txt", "sample_output_relpath": "derived/input_output/data/p03134/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03134/Lisp/s998873933.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s998873933", "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(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+ 10000)\n(defconstant +binom-mod+ +mod+)\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(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 stirling2))\n(defun stirling2 (n k)\n \"Returns the stirling number of the second kind S2(n, k). Time complexity is\nO(klog(n)).\"\n (declare ((integer 0 #.most-positive-fixnum) n k))\n (labels ((mod-power (base exp)\n (declare ((integer 0 #.most-positive-fixnum) base exp))\n (loop with res of-type (integer 0 #.most-positive-fixnum) = 1\n while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) +binom-mod+))\n do (setq base (mod (* base base) +binom-mod+)\n exp (ash exp -1))\n finally (return res))))\n (loop with result of-type fixnum = 0\n for i from 0 to k\n for delta = (mod (* (binom k i) (mod-power i n)) +binom-mod+)\n when (evenp (- k i))\n do (incf result delta)\n (when (>= result +binom-mod+)\n (decf result +binom-mod+))\n else\n do (decf result delta)\n (when (< result 0)\n (incf result +binom-mod+))\n finally (return (mod (* result (aref *fact-inv* k)) +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;;;\n;;; Arithmetic operations with static modulus\n;;;\n\n;; NOTE: Currently MOD* and MOD+ doesn't apply MOD when the number of\n;; parameters is one. For simplicity I won't fix it for now.\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(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\n;;;\n;;; Body\n;;;\n\n;; (defun solve-small (s)\n;; (let ((n (length s))\n;; (table (make-hash-table :test #'equal)))\n;; (sb-int:named-let dfs ((list1 (loop for i below n\n;; collect (ecase (aref s i)\n;; (#\\0 0) (#\\1 0) (#\\2 1))))\n;; (list2 (loop for i below n\n;; collect (ecase (aref s i)\n;; (#\\0 0) (#\\1 1) (#\\2 1)))))\n;; (loop for b1 in list1\n;; for b2 in list2\n;; collect (cond ((and (= b1 b2 0)) 0)\n;; ((and (= b1 b2 1)) 1)\n;; (t 0))))))\n\n(define-mod-operations +mod+)\n(defun main ()\n (declare #.opt)\n (let* ((s (map '(simple-array uint8 (*)) #'digit-char-p (read-line)))\n (n (length s))\n (dp (make-array (list (+ n 1) (+ 1 (* 2 n)))\n :element-type 'uint31\n :initial-element 0)))\n (setf (aref dp 0 0) 1)\n #>s\n (dotimes (x n)\n (let ((c (aref s x)))\n (dotimes (y (+ 1 (* 2 n)))\n (unless (zerop (aref dp x y))\n (let ((num0 (+ y (- 2 c)))\n (num1 (+ (- x y) c)))\n (when (> num0 0)\n (incfmod (aref dp (+ x 1) (- num0 1))\n (aref dp x y)))\n (when (> num1 0)\n (incfmod (aref dp (+ x 1) num0)\n (aref dp x y))))))))\n (let ((res 0))\n (loop for y from 0 to n\n do (incfmod res (mod* (aref dp n y) (binom n y))))\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 \"02\n\" nil)))\n (it.bese.fiveam:is\n (equal \"55\n\"\n (run \"1210\n\" nil)))\n (it.bese.fiveam:is\n (equal \"543589959\n\"\n (run \"12001021211100201020\n\" nil))))\n", "problem_context": "Score : 900 points\n\nProblem Statement\n\nThere are N Snukes lining up in a row.\nYou are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is 0; one red ball and one blue ball if the i-th character in S is 1; two blue balls if the i-th character in S is 2.\n\nTakahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:\n\nEach Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.\n\nTakahashi receives the ball and put it to the end of his sequence.\n\nConstraints\n\n1 \\leq |S| \\leq 2000\n\nS consists of 0,1 and 2.\n\nNote that the integer N is not directly given in input; it is given indirectly as the length of the string S.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.\n\nSample Input 1\n\n02\n\nSample Output 1\n\n3\n\nThere are three sequences that Takahashi may have: rrbb, rbrb and rbbr, where r and b stand for red and blue balls, respectively.\n\nSample Input 2\n\n1210\n\nSample Output 2\n\n55\n\nSample Input 3\n\n12001021211100201020\n\nSample Output 3\n\n543589959", "sample_input": "02\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03134", "source_text": "Score : 900 points\n\nProblem Statement\n\nThere are N Snukes lining up in a row.\nYou are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is 0; one red ball and one blue ball if the i-th character in S is 1; two blue balls if the i-th character in S is 2.\n\nTakahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:\n\nEach Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.\n\nTakahashi receives the ball and put it to the end of his sequence.\n\nConstraints\n\n1 \\leq |S| \\leq 2000\n\nS consists of 0,1 and 2.\n\nNote that the integer N is not directly given in input; it is given indirectly as the length of the string S.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.\n\nSample Input 1\n\n02\n\nSample Output 1\n\n3\n\nThere are three sequences that Takahashi may have: rrbb, rbrb and rbbr, where r and b stand for red and blue balls, respectively.\n\nSample Input 2\n\n1210\n\nSample Output 2\n\n55\n\nSample Input 3\n\n12001021211100201020\n\nSample Output 3\n\n543589959", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9754, "cpu_time_ms": 62, "memory_kb": 41140}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s175190638", "group_id": "codeNet:p03135", "input_text": "(format t \"~A~%\" (float (/ (read) (read))))", "language": "Lisp", "metadata": {"date": 1561158279, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03135.html", "problem_id": "p03135", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03135/input.txt", "sample_output_relpath": "derived/input_output/data/p03135/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03135/Lisp/s175190638.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s175190638", "user_id": "u606976120"}, "prompt_components": {"gold_output": "2.6666666667\n", "input_to_evaluate": "(format t \"~A~%\" (float (/ (read) (read))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn order to pass the entrance examination tomorrow, Taro has to study for T more hours.\n\nFortunately, he can leap to World B where time passes X times as fast as it does in our world (World A).\n\nWhile (X \\times t) hours pass in World B, t hours pass in World A.\n\nHow many hours will pass in World A while Taro studies for T hours in World B?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq T \\leq 100\n\n1 \\leq X \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nT X\n\nOutput\n\nPrint the number of hours that will pass in World A.\n\nThe output will be regarded as correct when its absolute or relative error from the judge's output is at most 10^{-3}.\n\nSample Input 1\n\n8 3\n\nSample Output 1\n\n2.6666666667\n\nWhile Taro studies for eight hours in World B where time passes three times as fast, 2.6666... hours will pass in World A.\n\nNote that an absolute or relative error of at most 10^{-3} is allowed.\n\nSample Input 2\n\n99 1\n\nSample Output 2\n\n99.0000000000\n\nSample Input 3\n\n1 100\n\nSample Output 3\n\n0.0100000000", "sample_input": "8 3\n"}, "reference_outputs": ["2.6666666667\n"], "source_document_id": "p03135", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn order to pass the entrance examination tomorrow, Taro has to study for T more hours.\n\nFortunately, he can leap to World B where time passes X times as fast as it does in our world (World A).\n\nWhile (X \\times t) hours pass in World B, t hours pass in World A.\n\nHow many hours will pass in World A while Taro studies for T hours in World B?\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq T \\leq 100\n\n1 \\leq X \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nT X\n\nOutput\n\nPrint the number of hours that will pass in World A.\n\nThe output will be regarded as correct when its absolute or relative error from the judge's output is at most 10^{-3}.\n\nSample Input 1\n\n8 3\n\nSample Output 1\n\n2.6666666667\n\nWhile Taro studies for eight hours in World B where time passes three times as fast, 2.6666... hours will pass in World A.\n\nNote that an absolute or relative error of at most 10^{-3} is allowed.\n\nSample Input 2\n\n99 1\n\nSample Output 2\n\n99.0000000000\n\nSample Input 3\n\n1 100\n\nSample Output 3\n\n0.0100000000", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 43, "cpu_time_ms": 10, "memory_kb": 3048}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s961028921", "group_id": "codeNet:p03136", "input_text": "(let ((n (read))\n (s 0)\n (temp 0)\n (m 0))\n (loop repeat n do\n (setf temp (read))\n (incf s temp)\n (setf m (max m temp)))\n (princ (if (< m (- s m)) \"Yes\" \"No\")))", "language": "Lisp", "metadata": {"date": 1549745246, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03136.html", "problem_id": "p03136", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03136/input.txt", "sample_output_relpath": "derived/input_output/data/p03136/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03136/Lisp/s961028921.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s961028921", "user_id": "u994767958"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read))\n (s 0)\n (temp 0)\n (m 0))\n (loop repeat n do\n (setf temp (read))\n (incf s temp)\n (setf m (max m temp)))\n (princ (if (< m (- s m)) \"Yes\" \"No\")))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nDetermine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.\n\nYou can use the following theorem:\n\nTheorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq N \\leq 10\n\n1 \\leq L_i \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nL_1 L_2 ... L_N\n\nOutput\n\nIf an N-sided polygon satisfying the condition can be drawn, print Yes; otherwise, print No.\n\nSample Input 1\n\n4\n3 8 5 1\n\nSample Output 1\n\nYes\n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can be drawn on a plane.\n\nSample Input 2\n\n4\n3 8 4 1\n\nSample Output 2\n\nNo\n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon cannot be drawn on a plane.\n\nSample Input 3\n\n10\n1 8 10 5 8 12 34 100 11 3\n\nSample Output 3\n\nNo", "sample_input": "4\n3 8 5 1\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03136", "source_text": "Score : 200 points\n\nProblem Statement\n\nDetermine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.\n\nYou can use the following theorem:\n\nTheorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq N \\leq 10\n\n1 \\leq L_i \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nL_1 L_2 ... L_N\n\nOutput\n\nIf an N-sided polygon satisfying the condition can be drawn, print Yes; otherwise, print No.\n\nSample Input 1\n\n4\n3 8 5 1\n\nSample Output 1\n\nYes\n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can be drawn on a plane.\n\nSample Input 2\n\n4\n3 8 4 1\n\nSample Output 2\n\nNo\n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon cannot be drawn on a plane.\n\nSample Input 3\n\n10\n1 8 10 5 8 12 34 100 11 3\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 139, "memory_kb": 13152}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s025895476", "group_id": "codeNet:p03136", "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 (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 (ls (make-array n :element-type 'uint32)))\n (split-ints-into-vector (read-line) ls)\n (setf ls (sort ls #'>))\n (if (< (aref ls 0)\n (loop for i from 1 below n\n sum (aref ls i)))\n (println \"Yes\")\n (println \"No\"))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1549247230, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03136.html", "problem_id": "p03136", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03136/input.txt", "sample_output_relpath": "derived/input_output/data/p03136/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03136/Lisp/s025895476.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s025895476", "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 (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 (ls (make-array n :element-type 'uint32)))\n (split-ints-into-vector (read-line) ls)\n (setf ls (sort ls #'>))\n (if (< (aref ls 0)\n (loop for i from 1 below n\n sum (aref ls i)))\n (println \"Yes\")\n (println \"No\"))))\n\n#-swank(main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nDetermine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.\n\nYou can use the following theorem:\n\nTheorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq N \\leq 10\n\n1 \\leq L_i \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nL_1 L_2 ... L_N\n\nOutput\n\nIf an N-sided polygon satisfying the condition can be drawn, print Yes; otherwise, print No.\n\nSample Input 1\n\n4\n3 8 5 1\n\nSample Output 1\n\nYes\n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can be drawn on a plane.\n\nSample Input 2\n\n4\n3 8 4 1\n\nSample Output 2\n\nNo\n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon cannot be drawn on a plane.\n\nSample Input 3\n\n10\n1 8 10 5 8 12 34 100 11 3\n\nSample Output 3\n\nNo", "sample_input": "4\n3 8 5 1\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03136", "source_text": "Score : 200 points\n\nProblem Statement\n\nDetermine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.\n\nYou can use the following theorem:\n\nTheorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.\n\nConstraints\n\nAll values in input are integers.\n\n3 \\leq N \\leq 10\n\n1 \\leq L_i \\leq 100\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nL_1 L_2 ... L_N\n\nOutput\n\nIf an N-sided polygon satisfying the condition can be drawn, print Yes; otherwise, print No.\n\nSample Input 1\n\n4\n3 8 5 1\n\nSample Output 1\n\nYes\n\nSince 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can be drawn on a plane.\n\nSample Input 2\n\n4\n3 8 4 1\n\nSample Output 2\n\nNo\n\nSince 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon cannot be drawn on a plane.\n\nSample Input 3\n\n10\n1 8 10 5 8 12 34 100 11 3\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1867, "cpu_time_ms": 178, "memory_kb": 21732}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s233080428", "group_id": "codeNet:p03137", "input_text": "def solve(n, m, x)\n return 0 if m == 1 || n >= m\n\n x.map!(&:to_i).sort!\n total = x[-1] - x[0]\n return total if n == 1\n\n d = (0...(x.size - 1)).map {|i| x[i + 1] - x[i] }\n total - d.sort! { |a, b| b <=> a }.take(n - 1).sum\nend\n\ndef main\n stdin = STDIN.gets\n nm = stdin.split(/\\s/)\n n = nm[0].to_i\n m = nm[1].to_i\n stdin = STDIN.gets\n x = stdin.split(/\\s/)\n\n puts(solve(n, m, x))\nend\n\nmain", "language": "Lisp", "metadata": {"date": 1561168789, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03137.html", "problem_id": "p03137", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03137/input.txt", "sample_output_relpath": "derived/input_output/data/p03137/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03137/Lisp/s233080428.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s233080428", "user_id": "u923888512"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "def solve(n, m, x)\n return 0 if m == 1 || n >= m\n\n x.map!(&:to_i).sort!\n total = x[-1] - x[0]\n return total if n == 1\n\n d = (0...(x.size - 1)).map {|i| x[i + 1] - x[i] }\n total - d.sort! { |a, b| b <=> a }.take(n - 1).sum\nend\n\ndef main\n stdin = STDIN.gets\n nm = stdin.split(/\\s/)\n n = nm[0].to_i\n m = nm[1].to_i\n stdin = STDIN.gets\n x = stdin.split(/\\s/)\n\n puts(solve(n, m, x))\nend\n\nmain", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe will play a one-player game using a number line and N pieces.\n\nFirst, we place each of these pieces at some integer coordinate.\n\nHere, multiple pieces can be placed at the same coordinate.\n\nOur objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move:\n\nMove: Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1.\n\nNote that the coordinates where we initially place the pieces are already regarded as visited.\n\nFind the minimum number of moves required to achieve the objective.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n-10^5 \\leq X_i \\leq 10^5\n\nX_1, X_2, ..., X_M are all different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nX_1 X_2 ... X_M\n\nOutput\n\nFind the minimum number of moves required to achieve the objective.\n\nSample Input 1\n\n2 5\n10 12 1 2 14\n\nSample Output 1\n\n5\n\nThe objective can be achieved in five moves as follows, and this is the minimum number of moves required.\n\nInitially, put the two pieces at coordinates 1 and 10.\n\nMove the piece at coordinate 1 to 2.\n\nMove the piece at coordinate 10 to 11.\n\nMove the piece at coordinate 11 to 12.\n\nMove the piece at coordinate 12 to 13.\n\nMove the piece at coordinate 13 to 14.\n\nSample Input 2\n\n3 7\n-10 -3 0 9 -100 2 17\n\nSample Output 2\n\n19\n\nSample Input 3\n\n100 1\n-100000\n\nSample Output 3\n\n0", "sample_input": "2 5\n10 12 1 2 14\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03137", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe will play a one-player game using a number line and N pieces.\n\nFirst, we place each of these pieces at some integer coordinate.\n\nHere, multiple pieces can be placed at the same coordinate.\n\nOur objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move:\n\nMove: Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1.\n\nNote that the coordinates where we initially place the pieces are already regarded as visited.\n\nFind the minimum number of moves required to achieve the objective.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 10^5\n\n1 \\leq M \\leq 10^5\n\n-10^5 \\leq X_i \\leq 10^5\n\nX_1, X_2, ..., X_M are all different.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nX_1 X_2 ... X_M\n\nOutput\n\nFind the minimum number of moves required to achieve the objective.\n\nSample Input 1\n\n2 5\n10 12 1 2 14\n\nSample Output 1\n\n5\n\nThe objective can be achieved in five moves as follows, and this is the minimum number of moves required.\n\nInitially, put the two pieces at coordinates 1 and 10.\n\nMove the piece at coordinate 1 to 2.\n\nMove the piece at coordinate 10 to 11.\n\nMove the piece at coordinate 11 to 12.\n\nMove the piece at coordinate 12 to 13.\n\nMove the piece at coordinate 13 to 14.\n\nSample Input 2\n\n3 7\n-10 -3 0 9 -100 2 17\n\nSample Output 2\n\n19\n\nSample Input 3\n\n100 1\n-100000\n\nSample Output 3\n\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 400, "cpu_time_ms": 75, "memory_kb": 8032}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s279577042", "group_id": "codeNet:p03139", "input_text": "(setq n(read))(format t\"~A ~A\"(min(setq a(read))(setq b(read)))(-(max(+ a b)n)n))", "language": "Lisp", "metadata": {"date": 1548654195, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03139.html", "problem_id": "p03139", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03139/input.txt", "sample_output_relpath": "derived/input_output/data/p03139/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03139/Lisp/s279577042.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s279577042", "user_id": "u657913472"}, "prompt_components": {"gold_output": "3 0\n", "input_to_evaluate": "(setq n(read))(format t\"~A ~A\"(min(setq a(read))(setq b(read)))(-(max(+ a b)n)n))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe conducted a survey on newspaper subscriptions.\nMore specifically, we asked each of the N respondents the following two questions:\n\nQuestion 1: Are you subscribing to Newspaper X?\n\nQuestion 2: Are you subscribing to Newspaper Y?\n\nAs the result, A respondents answered \"yes\" to Question 1, and B respondents answered \"yes\" to Question 2.\n\nWhat are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?\n\nWrite a program to answer this question.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n0 \\leq A \\leq N\n\n0 \\leq B \\leq N\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 maximum possible number and the minimum possible number of respondents subscribing to both newspapers, in this order, with a space in between.\n\nSample Input 1\n\n10 3 5\n\nSample Output 1\n\n3 0\n\nIn this sample, out of the 10 respondents, 3 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.\n\nHere, the number of respondents subscribing to both newspapers is at most 3 and at least 0.\n\nSample Input 2\n\n10 7 5\n\nSample Output 2\n\n5 2\n\nIn this sample, out of the 10 respondents, 7 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.\n\nHere, the number of respondents subscribing to both newspapers is at most 5 and at least 2.\n\nSample Input 3\n\n100 100 100\n\nSample Output 3\n\n100 100", "sample_input": "10 3 5\n"}, "reference_outputs": ["3 0\n"], "source_document_id": "p03139", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe conducted a survey on newspaper subscriptions.\nMore specifically, we asked each of the N respondents the following two questions:\n\nQuestion 1: Are you subscribing to Newspaper X?\n\nQuestion 2: Are you subscribing to Newspaper Y?\n\nAs the result, A respondents answered \"yes\" to Question 1, and B respondents answered \"yes\" to Question 2.\n\nWhat are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?\n\nWrite a program to answer this question.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n0 \\leq A \\leq N\n\n0 \\leq B \\leq N\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 maximum possible number and the minimum possible number of respondents subscribing to both newspapers, in this order, with a space in between.\n\nSample Input 1\n\n10 3 5\n\nSample Output 1\n\n3 0\n\nIn this sample, out of the 10 respondents, 3 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.\n\nHere, the number of respondents subscribing to both newspapers is at most 3 and at least 0.\n\nSample Input 2\n\n10 7 5\n\nSample Output 2\n\n5 2\n\nIn this sample, out of the 10 respondents, 7 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.\n\nHere, the number of respondents subscribing to both newspapers is at most 5 and at least 2.\n\nSample Input 3\n\n100 100 100\n\nSample Output 3\n\n100 100", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 83, "memory_kb": 8420}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s744571734", "group_id": "codeNet:p03139", "input_text": "(defun main ()\n (let* ((n (read))\n (a (read))\n (b (read)))\n (format t \"~A ~A~%\"\n (min a b)\n (max 0 (- (+ a b) n)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1548643572, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03139.html", "problem_id": "p03139", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03139/input.txt", "sample_output_relpath": "derived/input_output/data/p03139/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03139/Lisp/s744571734.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s744571734", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3 0\n", "input_to_evaluate": "(defun main ()\n (let* ((n (read))\n (a (read))\n (b (read)))\n (format t \"~A ~A~%\"\n (min a b)\n (max 0 (- (+ a b) n)))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe conducted a survey on newspaper subscriptions.\nMore specifically, we asked each of the N respondents the following two questions:\n\nQuestion 1: Are you subscribing to Newspaper X?\n\nQuestion 2: Are you subscribing to Newspaper Y?\n\nAs the result, A respondents answered \"yes\" to Question 1, and B respondents answered \"yes\" to Question 2.\n\nWhat are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?\n\nWrite a program to answer this question.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n0 \\leq A \\leq N\n\n0 \\leq B \\leq N\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 maximum possible number and the minimum possible number of respondents subscribing to both newspapers, in this order, with a space in between.\n\nSample Input 1\n\n10 3 5\n\nSample Output 1\n\n3 0\n\nIn this sample, out of the 10 respondents, 3 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.\n\nHere, the number of respondents subscribing to both newspapers is at most 3 and at least 0.\n\nSample Input 2\n\n10 7 5\n\nSample Output 2\n\n5 2\n\nIn this sample, out of the 10 respondents, 7 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.\n\nHere, the number of respondents subscribing to both newspapers is at most 5 and at least 2.\n\nSample Input 3\n\n100 100 100\n\nSample Output 3\n\n100 100", "sample_input": "10 3 5\n"}, "reference_outputs": ["3 0\n"], "source_document_id": "p03139", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe conducted a survey on newspaper subscriptions.\nMore specifically, we asked each of the N respondents the following two questions:\n\nQuestion 1: Are you subscribing to Newspaper X?\n\nQuestion 2: Are you subscribing to Newspaper Y?\n\nAs the result, A respondents answered \"yes\" to Question 1, and B respondents answered \"yes\" to Question 2.\n\nWhat are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?\n\nWrite a program to answer this question.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n0 \\leq A \\leq N\n\n0 \\leq B \\leq N\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 maximum possible number and the minimum possible number of respondents subscribing to both newspapers, in this order, with a space in between.\n\nSample Input 1\n\n10 3 5\n\nSample Output 1\n\n3 0\n\nIn this sample, out of the 10 respondents, 3 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.\n\nHere, the number of respondents subscribing to both newspapers is at most 3 and at least 0.\n\nSample Input 2\n\n10 7 5\n\nSample Output 2\n\n5 2\n\nIn this sample, out of the 10 respondents, 7 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.\n\nHere, the number of respondents subscribing to both newspapers is at most 5 and at least 2.\n\nSample Input 3\n\n100 100 100\n\nSample Output 3\n\n100 100", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 122, "memory_kb": 12520}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s143677393", "group_id": "codeNet:p03140", "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-line))\n (b (read-line))\n (c (read-line)))\n (loop for c1 across a\n for c2 across b\n for c3 across c\n with cumul = 0\n do (cond ((char= c1 c2 c3) nil)\n ((char= c1 c2) (incf cumul))\n ((char= c2 c3) (incf cumul))\n ((char= c3 c1) (incf cumul))\n (t (incf cumul 2)))\n finally (println cumul))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1548643853, "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/s143677393.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s143677393", "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 define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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-line))\n (b (read-line))\n (c (read-line)))\n (loop for c1 across a\n for c2 across b\n for c3 across c\n with cumul = 0\n do (cond ((char= c1 c2 c3) nil)\n ((char= c1 c2) (incf cumul))\n ((char= c2 c3) (incf cumul))\n ((char= c3 c1) (incf cumul))\n (t (incf cumul 2)))\n finally (println cumul))))\n\n#-swank(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1409, "cpu_time_ms": 143, "memory_kb": 16228}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s696296135", "group_id": "codeNet:p03146", "input_text": "(let ((n (read)))\n (defun collatz (a)\n (let ((cont 1))\n (loop :while (not (= a 1)) :do(if (oddp a)\n (setq a (+ (* 3 a) 1))\n (setq a (/ a 2)))\n :do(incf cont))\n cont))\n (princ (1+ (collatz n))))", "language": "Lisp", "metadata": {"date": 1548096969, "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/s696296135.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s696296135", "user_id": "u610490393"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((n (read)))\n (defun collatz (a)\n (let ((cont 1))\n (loop :while (not (= a 1)) :do(if (oddp a)\n (setq a (+ (* 3 a) 1))\n (setq a (/ a 2)))\n :do(incf cont))\n cont))\n (princ (1+ (collatz n))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 297, "cpu_time_ms": 332, "memory_kb": 22880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s374533390", "group_id": "codeNet:p03152", "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(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+ #.(+ (expt 10 9) 7))\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (nm (* n m))\n (as (make-array n :element-type 'uint32))\n (bs (make-array m :element-type 'uint32))\n (x<=as (make-array (1+ nm) :element-type 'uint32))\n (x<=bs (make-array (1+ nm) :element-type 'uint32))\n (a-set (make-hash-table :test #'eql))\n (b-set (make-hash-table :test #'eql)))\n (declare (uint15 n m))\n (split-ints-into-vector (read-line) as)\n (split-ints-into-vector (read-line) bs)\n (setf as (sort as #'<))\n (setf bs (sort bs #'<))\n (nlet recurse ((x 0) (a-idx 0))\n (declare (uint32 x a-idx))\n (when (< a-idx n)\n (loop for x from x below (length x<=as)\n while (<= x (aref as a-idx))\n do (setf (aref x<=as x) (- n a-idx))\n finally (return (recurse x (+ a-idx 1))))))\n (nlet recurse ((x 0) (b-idx 0))\n (declare (uint32 x b-idx))\n (when (< b-idx m)\n (loop for x from x below (length x<=bs)\n while (<= x (aref bs b-idx))\n do (setf (aref x<=bs x) (- m b-idx))\n finally (return (recurse x (+ b-idx 1))))))\n (dotimes (i n)\n (setf (gethash (aref as i) a-set) t))\n (dotimes (j m)\n (setf (gethash (aref bs j) b-set) t))\n (dotimes (i (- n 1))\n (when (= (aref as i) (aref as (+ i 1)))\n (println 0)\n (return-from main)))\n (dotimes (j (- m 1))\n (when (= (aref bs j) (aref bs (+ j 1)))\n (println 0)\n (return-from main)))\n (loop with res of-type uint32 = 1\n for x from nm downto 1\n do (if (gethash x a-set)\n (unless (gethash x b-set)\n (setf res (mod (* res (aref x<=bs x)) +magic+)))\n (if (gethash x b-set)\n (setf res (mod (* res (aref x<=as x)) +magic+))\n (setf res (mod (* res\n (the uint32\n (- (mod (* (aref x<=as x) (aref x<=bs x))\n +magic+)\n (- nm x))))\n +magic+))))\n finally (println res))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547423068, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03152.html", "problem_id": "p03152", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03152/input.txt", "sample_output_relpath": "derived/input_output/data/p03152/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03152/Lisp/s374533390.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s374533390", "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 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-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+ #.(+ (expt 10 9) 7))\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (m (read))\n (nm (* n m))\n (as (make-array n :element-type 'uint32))\n (bs (make-array m :element-type 'uint32))\n (x<=as (make-array (1+ nm) :element-type 'uint32))\n (x<=bs (make-array (1+ nm) :element-type 'uint32))\n (a-set (make-hash-table :test #'eql))\n (b-set (make-hash-table :test #'eql)))\n (declare (uint15 n m))\n (split-ints-into-vector (read-line) as)\n (split-ints-into-vector (read-line) bs)\n (setf as (sort as #'<))\n (setf bs (sort bs #'<))\n (nlet recurse ((x 0) (a-idx 0))\n (declare (uint32 x a-idx))\n (when (< a-idx n)\n (loop for x from x below (length x<=as)\n while (<= x (aref as a-idx))\n do (setf (aref x<=as x) (- n a-idx))\n finally (return (recurse x (+ a-idx 1))))))\n (nlet recurse ((x 0) (b-idx 0))\n (declare (uint32 x b-idx))\n (when (< b-idx m)\n (loop for x from x below (length x<=bs)\n while (<= x (aref bs b-idx))\n do (setf (aref x<=bs x) (- m b-idx))\n finally (return (recurse x (+ b-idx 1))))))\n (dotimes (i n)\n (setf (gethash (aref as i) a-set) t))\n (dotimes (j m)\n (setf (gethash (aref bs j) b-set) t))\n (dotimes (i (- n 1))\n (when (= (aref as i) (aref as (+ i 1)))\n (println 0)\n (return-from main)))\n (dotimes (j (- m 1))\n (when (= (aref bs j) (aref bs (+ j 1)))\n (println 0)\n (return-from main)))\n (loop with res of-type uint32 = 1\n for x from nm downto 1\n do (if (gethash x a-set)\n (unless (gethash x b-set)\n (setf res (mod (* res (aref x<=bs x)) +magic+)))\n (if (gethash x b-set)\n (setf res (mod (* res (aref x<=as x)) +magic+))\n (setf res (mod (* res\n (the uint32\n (- (mod (* (aref x<=as x) (aref x<=bs x))\n +magic+)\n (- nm x))))\n +magic+))))\n finally (println res))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nConsider writing each of the integers from 1 to N \\times M in a grid with N rows and M columns, without duplicates.\nTakahashi thinks it is not fun enough, and he will write the numbers under the following conditions:\n\nThe largest among the values in the i-th row (1 \\leq i \\leq N) is A_i.\n\nThe largest among the values in the j-th column (1 \\leq j \\leq M) is B_j.\n\nFor him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.\n\nConstraints\n\n1 \\leq N \\leq 1000\n\n1 \\leq M \\leq 1000\n\n1 \\leq A_i \\leq N \\times M\n\n1 \\leq B_j \\leq N \\times M\n\nA_i and B_j are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_{N}\nB_1 B_2 ... B_{M}\n\nOutput\n\nPrint the number of ways to write the numbers under the conditions, modulo 10^9 + 7.\n\nSample Input 1\n\n2 2\n4 3\n3 4\n\nSample Output 1\n\n2\n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways to write the numbers, as follows:\n\n1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n\n2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\nSample Input 2\n\n3 3\n5 9 7\n3 6 9\n\nSample Output 2\n\n0\n\nSince there is no way to write the numbers under the condition, 0 should be printed.\n\nSample Input 3\n\n2 2\n4 4\n4 4\n\nSample Output 3\n\n0\n\nSample Input 4\n\n14 13\n158 167 181 147 178 151 179 182 176 169 180 129 175 168\n181 150 178 179 167 180 176 169 182 177 175 159 173\n\nSample Output 4\n\n343772227", "sample_input": "2 2\n4 3\n3 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03152", "source_text": "Score : 500 points\n\nProblem Statement\n\nConsider writing each of the integers from 1 to N \\times M in a grid with N rows and M columns, without duplicates.\nTakahashi thinks it is not fun enough, and he will write the numbers under the following conditions:\n\nThe largest among the values in the i-th row (1 \\leq i \\leq N) is A_i.\n\nThe largest among the values in the j-th column (1 \\leq j \\leq M) is B_j.\n\nFor him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.\n\nConstraints\n\n1 \\leq N \\leq 1000\n\n1 \\leq M \\leq 1000\n\n1 \\leq A_i \\leq N \\times M\n\n1 \\leq B_j \\leq N \\times M\n\nA_i and B_j are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M\nA_1 A_2 ... A_{N}\nB_1 B_2 ... B_{M}\n\nOutput\n\nPrint the number of ways to write the numbers under the conditions, modulo 10^9 + 7.\n\nSample Input 1\n\n2 2\n4 3\n3 4\n\nSample Output 1\n\n2\n\n(A_1, A_2) = (4, 3) and (B_1, B_2) = (3, 4). In this case, there are two ways to write the numbers, as follows:\n\n1 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 2 in (2, 2).\n\n2 in (1, 1), 4 in (1, 2), 3 in (2, 1) and 1 in (2, 2).\n\nHere, (i, j) denotes the square at the i-th row and the j-th column.\n\nSample Input 2\n\n3 3\n5 9 7\n3 6 9\n\nSample Output 2\n\n0\n\nSince there is no way to write the numbers under the condition, 0 should be printed.\n\nSample Input 3\n\n2 2\n4 4\n4 4\n\nSample Output 3\n\n0\n\nSample Input 4\n\n14 13\n158 167 181 147 178 151 179 182 176 169 180 129 175 168\n181 150 178 179 167 180 176 169 182 177 175 159 173\n\nSample Output 4\n\n343772227", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3967, "cpu_time_ms": 317, "memory_kb": 39008}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s652350500", "group_id": "codeNet:p03153", "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;;; 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 (inline find-argopt))\n(defun find-argopt (iterable predicate &key start end (key #'identity))\n \"Returns an index (or key) x at which ITERABLE takes the minimal (or maximal,\ndepending on PREDICATE) value, and returns ITERABLE[x] as the second value.\n\nTo explain the behaviour briefly, when (FUNCALL PREDICATE (AREF ITERABLE\n) (AREF ITERABLE )) holds, and are swapped.\n\nWhen ITERABLE is a hash-table, START and END are ignored.\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) start end)\n ((or hash-table sequence) iterable))\n (labels ((invalid-range-error ()\n (error \"Can't find optimal value in null interval [~A, ~A) on ~A\" start end iterable)))\n (etypecase iterable\n (list\n (let* ((start (or start 0))\n (end (or end most-positive-fixnum))\n (iterable (nthcdr start iterable)))\n (when (or (null iterable)\n (>= start end))\n (invalid-range-error))\n (let ((opt-element (car iterable))\n (opt-index start)\n (pos start))\n (dolist (x iterable)\n (when (>= pos end)\n (return-from find-argopt (values opt-index opt-element)))\n (when (funcall predicate\n (funcall key x pos)\n (funcall key opt-element pos))\n (setq opt-element x\n opt-index pos))\n (incf pos))\n (values opt-index opt-element))))\n (vector\n (let ((start (or start 0))\n (end (or end (length iterable))))\n (when (or (>= start end)\n (>= start (length iterable)))\n (invalid-range-error))\n (let ((opt-element (aref iterable start))\n (opt-index start))\n (loop for i from start below end\n for x = (aref iterable i)\n do (when (funcall predicate\n (funcall key x i)\n (funcall key opt-element i))\n (setq opt-element x\n opt-index i)))\n (values opt-index opt-element))))\n (hash-table\n (assert (and (null start) (null end)))\n (when (zerop (hash-table-count iterable))\n (invalid-range-error))\n (let* ((opt-value (gensym))\n (opt-key opt-value))\n (maphash\n (lambda (hash-key x)\n (when (or (eq opt-key opt-value)\n (funcall predicate\n (funcall key x hash-key)\n (funcall key opt-value hash-key)))\n (setq opt-value x\n opt-key hash-key)))\n iterable)\n (values opt-key opt-value))))))\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 (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 (inline sort sb-impl::stable-sort-list))\n (let* ((n (read))\n (d (read))\n (as (make-array n :element-type 'uint31))\n edges)\n (declare (uint31 n d))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (labels ((calc-cost (i j)\n (declare (uint31 i j)\n (values uint62 &optional))\n (+ (aref as i) (aref as j)\n (* d (abs (- i j))))))\n (sb-int:named-let recur ((l 0) (r n))\n (declare (uint31 l r))\n (when (>= (- r l) 2)\n (let ((mid (ash (+ l r) -1)))\n (recur l mid)\n (recur mid r)\n (let ((pivot1\n (find-argopt as #'< :start l :end mid :key (lambda (a i) (- a (* i d)))))\n (pivot2\n (find-argopt as #'< :start mid :end r :key (lambda (a i) (+ a (* i d))))))\n (loop for i from l below mid\n do (push (cons i pivot2) edges))\n (loop for i from mid below r\n do (push (cons i pivot1) edges))))))\n (setq edges (sort edges #'<\n :key (lambda (edge)\n (calc-cost (car edge) (cdr edge)))))\n (let ((dset (make-disjoint-set n))\n (res 0))\n (dolist (edge edges)\n (let ((i (car edge))\n (j (cdr edge)))\n (unless (ds-connected-p dset i j)\n (ds-unite! dset i j)\n (incf res (calc-cost i j)))))\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 1\n1 100 1\n\"\n \"106\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 1000\n1 100 1\n\"\n \"2202\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 14\n25 171 7 1 17 162\n\"\n \"497\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"12 5\n43 94 27 3 69 99 56 25 8 15 46 8\n\"\n \"658\n\")))\n", "language": "Lisp", "metadata": {"date": 1578257513, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03153.html", "problem_id": "p03153", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03153/input.txt", "sample_output_relpath": "derived/input_output/data/p03153/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03153/Lisp/s652350500.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s652350500", "user_id": "u352600849"}, "prompt_components": {"gold_output": "106\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;;; 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 (inline find-argopt))\n(defun find-argopt (iterable predicate &key start end (key #'identity))\n \"Returns an index (or key) x at which ITERABLE takes the minimal (or maximal,\ndepending on PREDICATE) value, and returns ITERABLE[x] as the second value.\n\nTo explain the behaviour briefly, when (FUNCALL PREDICATE (AREF ITERABLE\n) (AREF ITERABLE )) holds, and are swapped.\n\nWhen ITERABLE is a hash-table, START and END are ignored.\"\n (declare ((or null (integer 0 #.most-positive-fixnum)) start end)\n ((or hash-table sequence) iterable))\n (labels ((invalid-range-error ()\n (error \"Can't find optimal value in null interval [~A, ~A) on ~A\" start end iterable)))\n (etypecase iterable\n (list\n (let* ((start (or start 0))\n (end (or end most-positive-fixnum))\n (iterable (nthcdr start iterable)))\n (when (or (null iterable)\n (>= start end))\n (invalid-range-error))\n (let ((opt-element (car iterable))\n (opt-index start)\n (pos start))\n (dolist (x iterable)\n (when (>= pos end)\n (return-from find-argopt (values opt-index opt-element)))\n (when (funcall predicate\n (funcall key x pos)\n (funcall key opt-element pos))\n (setq opt-element x\n opt-index pos))\n (incf pos))\n (values opt-index opt-element))))\n (vector\n (let ((start (or start 0))\n (end (or end (length iterable))))\n (when (or (>= start end)\n (>= start (length iterable)))\n (invalid-range-error))\n (let ((opt-element (aref iterable start))\n (opt-index start))\n (loop for i from start below end\n for x = (aref iterable i)\n do (when (funcall predicate\n (funcall key x i)\n (funcall key opt-element i))\n (setq opt-element x\n opt-index i)))\n (values opt-index opt-element))))\n (hash-table\n (assert (and (null start) (null end)))\n (when (zerop (hash-table-count iterable))\n (invalid-range-error))\n (let* ((opt-value (gensym))\n (opt-key opt-value))\n (maphash\n (lambda (hash-key x)\n (when (or (eq opt-key opt-value)\n (funcall predicate\n (funcall key x hash-key)\n (funcall key opt-value hash-key)))\n (setq opt-value x\n opt-key hash-key)))\n iterable)\n (values opt-key opt-value))))))\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 (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 (inline sort sb-impl::stable-sort-list))\n (let* ((n (read))\n (d (read))\n (as (make-array n :element-type 'uint31))\n edges)\n (declare (uint31 n d))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (labels ((calc-cost (i j)\n (declare (uint31 i j)\n (values uint62 &optional))\n (+ (aref as i) (aref as j)\n (* d (abs (- i j))))))\n (sb-int:named-let recur ((l 0) (r n))\n (declare (uint31 l r))\n (when (>= (- r l) 2)\n (let ((mid (ash (+ l r) -1)))\n (recur l mid)\n (recur mid r)\n (let ((pivot1\n (find-argopt as #'< :start l :end mid :key (lambda (a i) (- a (* i d)))))\n (pivot2\n (find-argopt as #'< :start mid :end r :key (lambda (a i) (+ a (* i d))))))\n (loop for i from l below mid\n do (push (cons i pivot2) edges))\n (loop for i from mid below r\n do (push (cons i pivot1) edges))))))\n (setq edges (sort edges #'<\n :key (lambda (edge)\n (calc-cost (car edge) (cdr edge)))))\n (let ((dset (make-disjoint-set n))\n (res 0))\n (dolist (edge edges)\n (let ((i (car edge))\n (j (cdr edge)))\n (unless (ds-connected-p dset i j)\n (ds-unite! dset i j)\n (incf res (calc-cost i j)))))\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 1\n1 100 1\n\"\n \"106\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 1000\n1 100 1\n\"\n \"2202\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 14\n25 171 7 1 17 162\n\"\n \"497\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"12 5\n43 94 27 3 69 99 56 25 8 15 46 8\n\"\n \"658\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are N cities in Republic of AtCoder. The size of the i-th city is A_{i}.\nTakahashi would like to build N-1 bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads.\n\nAssume that the cost of building a road connecting the i-th city and the j-th city is |i-j| \\times D + A_{i} + A_{j}.\nFor Takahashi, find the minimum possible total cost to achieve the objective.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq D \\leq 10^9\n\n1 \\leq A_{i} \\leq 10^9\n\nA_{i} and D are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN D\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum possible total cost.\n\nSample Input 1\n\n3 1\n1 100 1\n\nSample Output 1\n\n106\n\nThis cost can be achieved by, for example, building roads connecting City 1, 2 and City 1, 3.\n\nSample Input 2\n\n3 1000\n1 100 1\n\nSample Output 2\n\n2202\n\nSample Input 3\n\n6 14\n25 171 7 1 17 162\n\nSample Output 3\n\n497\n\nSample Input 4\n\n12 5\n43 94 27 3 69 99 56 25 8 15 46 8\n\nSample Output 4\n\n658", "sample_input": "3 1\n1 100 1\n"}, "reference_outputs": ["106\n"], "source_document_id": "p03153", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are N cities in Republic of AtCoder. The size of the i-th city is A_{i}.\nTakahashi would like to build N-1 bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads.\n\nAssume that the cost of building a road connecting the i-th city and the j-th city is |i-j| \\times D + A_{i} + A_{j}.\nFor Takahashi, find the minimum possible total cost to achieve the objective.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^5\n\n1 \\leq D \\leq 10^9\n\n1 \\leq A_{i} \\leq 10^9\n\nA_{i} and D are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN D\nA_1 A_2 ... A_N\n\nOutput\n\nPrint the minimum possible total cost.\n\nSample Input 1\n\n3 1\n1 100 1\n\nSample Output 1\n\n106\n\nThis cost can be achieved by, for example, building roads connecting City 1, 2 and City 1, 3.\n\nSample Input 2\n\n3 1000\n1 100 1\n\nSample Output 2\n\n2202\n\nSample Input 3\n\n6 14\n25 171 7 1 17 162\n\nSample Output 3\n\n497\n\nSample Input 4\n\n12 5\n43 94 27 3 69 99 56 25 8 15 46 8\n\nSample Output 4\n\n658", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11066, "cpu_time_ms": 2106, "memory_kb": 137960}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s440034692", "group_id": "codeNet:p03155", "input_text": "\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;; BEGIN_USE_PACKAGE\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (h (read))\n (w (read)))\n (println (* (max 0 (+ 1 (- n h)))\n (max 0 (+ 1 (- n w)))))))\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 \"2\n\"\n (run \"3\n2\n3\n\" nil)))\n (5am:is\n (equal \"10000\n\"\n (run \"100\n1\n1\n\" nil)))\n (5am:is\n (equal \"8\n\"\n (run \"5\n4\n2\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600318578, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s440034692.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s440034692", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "\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;; BEGIN_USE_PACKAGE\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (h (read))\n (w (read)))\n (println (* (max 0 (+ 1 (- n h)))\n (max 0 (+ 1 (- n w)))))))\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 \"2\n\"\n (run \"3\n2\n3\n\" nil)))\n (5am:is\n (equal \"10000\n\"\n (run \"100\n1\n1\n\" nil)))\n (5am:is\n (equal \"8\n\"\n (run \"5\n4\n2\n\" nil))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3510, "cpu_time_ms": 21, "memory_kb": 24716}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s181786823", "group_id": "codeNet:p03156", "input_text": "(defun split (line)\n (with-input-from-string (stream line)\n (loop for obj = (read stream nil)\n while obj\n collect obj)))\n\n(let* ((n (read))\n (ab (split (read-line)))\n (a (car ab))\n (b (cadr ab))\n (p (split (read-line))))\n (princ (min (count-if (lambda (x) (<= x a)) p)\n (count-if (lambda (x) (and (> x a) (<= x b))) p)\n (count-if (lambda (x) (> x b)) p))))", "language": "Lisp", "metadata": {"date": 1547395756, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03156.html", "problem_id": "p03156", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03156/input.txt", "sample_output_relpath": "derived/input_output/data/p03156/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03156/Lisp/s181786823.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s181786823", "user_id": "u652695471"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun split (line)\n (with-input-from-string (stream line)\n (loop for obj = (read stream nil)\n while obj\n collect obj)))\n\n(let* ((n (read))\n (ab (split (read-line)))\n (a (car ab))\n (b (cadr ab))\n (p (split (read-line))))\n (princ (min (count-if (lambda (x) (<= x a)) p)\n (count-if (lambda (x) (and (> x a) (<= x b))) p)\n (count-if (lambda (x) (> x b)) p))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou have written N problems to hold programming contests.\nThe i-th problem will have a score of P_i points if used in a contest.\n\nWith these problems, you would like to hold as many contests as possible under the following condition:\n\nA contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.\n\nThe same problem should not be used in multiple contests.\nAt most how many contests can be held?\n\nConstraints\n\n3 \\leq N \\leq 100\n\n1 \\leq P_i \\leq 20 (1 \\leq i \\leq N)\n\n1 \\leq A < B < 20\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA B\nP_1 P_2 ... P_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n5 15\n1 10 16 2 7 20 12\n\nSample Output 1\n\n2\n\nTwo contests can be held by putting the first, second, third problems and the fourth, fifth, sixth problems together.\n\nSample Input 2\n\n8\n3 8\n5 5 5 10 10 10 15 20\n\nSample Output 2\n\n0\n\nNo contest can be held, because there is no problem with a score of A = 3 or less.\n\nSample Input 3\n\n3\n5 6\n5 6 10\n\nSample Output 3\n\n1", "sample_input": "7\n5 15\n1 10 16 2 7 20 12\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03156", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou have written N problems to hold programming contests.\nThe i-th problem will have a score of P_i points if used in a contest.\n\nWith these problems, you would like to hold as many contests as possible under the following condition:\n\nA contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points.\n\nThe same problem should not be used in multiple contests.\nAt most how many contests can be held?\n\nConstraints\n\n3 \\leq N \\leq 100\n\n1 \\leq P_i \\leq 20 (1 \\leq i \\leq N)\n\n1 \\leq A < B < 20\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA B\nP_1 P_2 ... P_N\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n7\n5 15\n1 10 16 2 7 20 12\n\nSample Output 1\n\n2\n\nTwo contests can be held by putting the first, second, third problems and the fourth, fifth, sixth problems together.\n\nSample Input 2\n\n8\n3 8\n5 5 5 10 10 10 15 20\n\nSample Output 2\n\n0\n\nNo contest can be held, because there is no problem with a score of A = 3 or less.\n\nSample Input 3\n\n3\n5 6\n5 6 10\n\nSample Output 3\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 430, "cpu_time_ms": 162, "memory_kb": 14820}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s121587249", "group_id": "codeNet:p03158", "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(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)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 calc-aoki-minwidth))\n(defun calc-aoki-minwidth (x as takahashi-l)\n (declare (uint32 x takahashi-l)\n ((simple-array uint32 (*)) as))\n (let* ((aoki-max (aref as (- takahashi-l 1)))\n (delta (- aoki-max x))\n (aoki-min (- x delta)))\n ;; (assert (<= x aoki-max))\n (let ((aoki-l (bisect-left as aoki-min)))\n (- takahashi-l aoki-l))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (q (read))\n (as (make-array n :element-type 'uint32))\n ;; cumulative sum\n (cumuls (make-array (+ 1 n) :element-type 'uint62 :initial-element 0))\n ;; cumulative sum of every other element\n (cumuls2 (make-array (+ 2 n) :element-type 'uint62 :initial-element 0)))\n (declare (uint31 n q))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref cumuls (+ i 1)) (+ (aref cumuls i) (aref as i))\n (aref cumuls2 (+ i 1)) (+ (aref cumuls2 (max 0 (- i 1))) (aref as i))))\n (with-buffered-stdout\n (dotimes (_ q)\n (let* ((x (read-fixnum))\n (l (sb-int:named-let bisect ((ok 1) (ng n))\n (declare (uint32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (aoki-minwidth (calc-aoki-minwidth x as mid)))\n (if (<= aoki-minwidth (- n mid))\n (bisect mid ng)\n (bisect ok mid))))))\n ;; Takahashi takes [L, N) and Aoki takes [L-(N-L), L)\n (t-score (+ (- (aref cumuls n) (aref cumuls l))\n (aref cumuls2 (max 0 (- l (- n l)))))))\n (println (the uint62 t-score)))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567602766, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03158.html", "problem_id": "p03158", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03158/input.txt", "sample_output_relpath": "derived/input_output/data/p03158/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03158/Lisp/s121587249.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s121587249", "user_id": "u352600849"}, "prompt_components": {"gold_output": "31\n31\n27\n23\n23\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(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)))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 calc-aoki-minwidth))\n(defun calc-aoki-minwidth (x as takahashi-l)\n (declare (uint32 x takahashi-l)\n ((simple-array uint32 (*)) as))\n (let* ((aoki-max (aref as (- takahashi-l 1)))\n (delta (- aoki-max x))\n (aoki-min (- x delta)))\n ;; (assert (<= x aoki-max))\n (let ((aoki-l (bisect-left as aoki-min)))\n (- takahashi-l aoki-l))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (q (read))\n (as (make-array n :element-type 'uint32))\n ;; cumulative sum\n (cumuls (make-array (+ 1 n) :element-type 'uint62 :initial-element 0))\n ;; cumulative sum of every other element\n (cumuls2 (make-array (+ 2 n) :element-type 'uint62 :initial-element 0)))\n (declare (uint31 n q))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref cumuls (+ i 1)) (+ (aref cumuls i) (aref as i))\n (aref cumuls2 (+ i 1)) (+ (aref cumuls2 (max 0 (- i 1))) (aref as i))))\n (with-buffered-stdout\n (dotimes (_ q)\n (let* ((x (read-fixnum))\n (l (sb-int:named-let bisect ((ok 1) (ng n))\n (declare (uint32 ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (aoki-minwidth (calc-aoki-minwidth x as mid)))\n (if (<= aoki-minwidth (- n mid))\n (bisect mid ng)\n (bisect ok mid))))))\n ;; Takahashi takes [L, N) and Aoki takes [L-(N-L), L)\n (t-score (+ (- (aref cumuls n) (aref cumuls l))\n (aref cumuls2 (max 0 (- l (- n l)))))))\n (println (the uint62 t-score)))))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N cards. The i-th card has an integer A_i written on it.\nFor any two cards, the integers on those cards are different.\n\nUsing these cards, Takahashi and Aoki will play the following game:\n\nAoki chooses an integer x.\n\nStarting from Takahashi, the two players alternately take a card. The card should be chosen in the following manner:\n\nTakahashi should take the card with the largest integer among the remaining card.\n\nAoki should take the card with the integer closest to x among the remaining card. If there are multiple such cards, he should take the card with the smallest integer among those cards.\n\nThe game ends when there is no card remaining.\n\nYou are given Q candidates for the value of x: X_1, X_2, ..., X_Q.\nFor each i (1 \\leq i \\leq Q), find the sum of the integers written on the cards that Takahashi will take if Aoki chooses x = X_i.\n\nConstraints\n\n2 \\leq N \\leq 100 000\n\n1 \\leq Q \\leq 100 000\n\n1 \\leq A_1 < A_2 < ... < A_N \\leq 10^9\n\n1 \\leq X_i \\leq 10^9 (1 \\leq i \\leq Q)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nA_1 A_2 ... A_N\nX_1\nX_2\n:\nX_Q\n\nOutput\n\nPrint Q lines. The i-th line (1 \\leq i \\leq Q) should contain the answer for x = X_i.\n\nSample Input 1\n\n5 5\n3 5 7 11 13\n1\n4\n9\n10\n13\n\nSample Output 1\n\n31\n31\n27\n23\n23\n\nFor example, when x = X_3(= 9), the game proceeds as follows:\n\nTakahashi takes the card with 13.\n\nAoki takes the card with 7.\n\nTakahashi takes the card with 11.\n\nAoki takes the card with 5.\n\nTakahashi takes the card with 3.\n\nThus, 13 + 11 + 3 = 27 should be printed on the third line.\n\nSample Input 2\n\n4 3\n10 20 30 40\n2\n34\n34\n\nSample Output 2\n\n70\n60\n60", "sample_input": "5 5\n3 5 7 11 13\n1\n4\n9\n10\n13\n"}, "reference_outputs": ["31\n31\n27\n23\n23\n"], "source_document_id": "p03158", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N cards. The i-th card has an integer A_i written on it.\nFor any two cards, the integers on those cards are different.\n\nUsing these cards, Takahashi and Aoki will play the following game:\n\nAoki chooses an integer x.\n\nStarting from Takahashi, the two players alternately take a card. The card should be chosen in the following manner:\n\nTakahashi should take the card with the largest integer among the remaining card.\n\nAoki should take the card with the integer closest to x among the remaining card. If there are multiple such cards, he should take the card with the smallest integer among those cards.\n\nThe game ends when there is no card remaining.\n\nYou are given Q candidates for the value of x: X_1, X_2, ..., X_Q.\nFor each i (1 \\leq i \\leq Q), find the sum of the integers written on the cards that Takahashi will take if Aoki chooses x = X_i.\n\nConstraints\n\n2 \\leq N \\leq 100 000\n\n1 \\leq Q \\leq 100 000\n\n1 \\leq A_1 < A_2 < ... < A_N \\leq 10^9\n\n1 \\leq X_i \\leq 10^9 (1 \\leq i \\leq Q)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nA_1 A_2 ... A_N\nX_1\nX_2\n:\nX_Q\n\nOutput\n\nPrint Q lines. The i-th line (1 \\leq i \\leq Q) should contain the answer for x = X_i.\n\nSample Input 1\n\n5 5\n3 5 7 11 13\n1\n4\n9\n10\n13\n\nSample Output 1\n\n31\n31\n27\n23\n23\n\nFor example, when x = X_3(= 9), the game proceeds as follows:\n\nTakahashi takes the card with 13.\n\nAoki takes the card with 7.\n\nTakahashi takes the card with 11.\n\nAoki takes the card with 5.\n\nTakahashi takes the card with 3.\n\nThus, 13 + 11 + 3 = 27 should be printed on the third line.\n\nSample Input 2\n\n4 3\n10 20 30 40\n2\n34\n34\n\nSample Output 2\n\n70\n60\n60", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6742, "cpu_time_ms": 404, "memory_kb": 32616}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s783914680", "group_id": "codeNet:p03158", "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(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)))))\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. 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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-aoki-minwidth (x as takahashi-l)\n (declare (uint32 x takahashi-l)\n ((simple-array uint32 (*)) as))\n (assert (>= takahashi-l 1))\n (let* ((aoki-max (aref as (- takahashi-l 1)))\n (delta (- aoki-max x))\n (aoki-min (- x delta)))\n ;; (assert (<= x aoki-max))\n (let ((aoki-l (bisect-left as aoki-min)))\n (- takahashi-l aoki-l))))\n\n(defun main ()\n (let* ((n (read))\n (q (read))\n (as (make-array n :element-type 'uint32))\n (cumuls (make-array (+ 1 n) :element-type 'uint62 :initial-element 0))\n (cumuls2 (make-array (+ 2 n) :element-type 'uint62 :initial-element 0)))\n (declare (uint31 n q))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref cumuls (+ i 1)) (+ (aref cumuls i) (aref as i))\n (aref cumuls2 (+ i 1)) (+ (aref cumuls2 (max 0 (- i 1))) (aref as i))))\n #>cumuls2\n (with-buffered-stdout\n (dotimes (_ q)\n (let* ((x (read-fixnum))\n (l (sb-int:named-let bisect ((ok 1) (ng n))\n (declare (uint32 ok ng))\n ;; (dbg ng ok)\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (aoki-minwidth (calc-aoki-minwidth x as mid)))\n ;; (dbg mid aoki-minwidth)\n (if (<= aoki-minwidth (- n mid))\n (bisect mid ng)\n (bisect ok mid))))))\n ;; Takahashi takes [L, N) and Aoki takes [L-(N-L), L)\n (t-score (+ (- (aref cumuls n) (aref cumuls l))\n (aref cumuls2 (max 0 (- l (- n l)))))))\n (println t-score))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567602535, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03158.html", "problem_id": "p03158", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03158/input.txt", "sample_output_relpath": "derived/input_output/data/p03158/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03158/Lisp/s783914680.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s783914680", "user_id": "u352600849"}, "prompt_components": {"gold_output": "31\n31\n27\n23\n23\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(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)))))\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. 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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-aoki-minwidth (x as takahashi-l)\n (declare (uint32 x takahashi-l)\n ((simple-array uint32 (*)) as))\n (assert (>= takahashi-l 1))\n (let* ((aoki-max (aref as (- takahashi-l 1)))\n (delta (- aoki-max x))\n (aoki-min (- x delta)))\n ;; (assert (<= x aoki-max))\n (let ((aoki-l (bisect-left as aoki-min)))\n (- takahashi-l aoki-l))))\n\n(defun main ()\n (let* ((n (read))\n (q (read))\n (as (make-array n :element-type 'uint32))\n (cumuls (make-array (+ 1 n) :element-type 'uint62 :initial-element 0))\n (cumuls2 (make-array (+ 2 n) :element-type 'uint62 :initial-element 0)))\n (declare (uint31 n q))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref cumuls (+ i 1)) (+ (aref cumuls i) (aref as i))\n (aref cumuls2 (+ i 1)) (+ (aref cumuls2 (max 0 (- i 1))) (aref as i))))\n #>cumuls2\n (with-buffered-stdout\n (dotimes (_ q)\n (let* ((x (read-fixnum))\n (l (sb-int:named-let bisect ((ok 1) (ng n))\n (declare (uint32 ok ng))\n ;; (dbg ng ok)\n (if (<= (- ng ok) 1)\n ok\n (let* ((mid (ash (+ ok ng) -1))\n (aoki-minwidth (calc-aoki-minwidth x as mid)))\n ;; (dbg mid aoki-minwidth)\n (if (<= aoki-minwidth (- n mid))\n (bisect mid ng)\n (bisect ok mid))))))\n ;; Takahashi takes [L, N) and Aoki takes [L-(N-L), L)\n (t-score (+ (- (aref cumuls n) (aref cumuls l))\n (aref cumuls2 (max 0 (- l (- n l)))))))\n (println t-score))))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nThere are N cards. The i-th card has an integer A_i written on it.\nFor any two cards, the integers on those cards are different.\n\nUsing these cards, Takahashi and Aoki will play the following game:\n\nAoki chooses an integer x.\n\nStarting from Takahashi, the two players alternately take a card. The card should be chosen in the following manner:\n\nTakahashi should take the card with the largest integer among the remaining card.\n\nAoki should take the card with the integer closest to x among the remaining card. If there are multiple such cards, he should take the card with the smallest integer among those cards.\n\nThe game ends when there is no card remaining.\n\nYou are given Q candidates for the value of x: X_1, X_2, ..., X_Q.\nFor each i (1 \\leq i \\leq Q), find the sum of the integers written on the cards that Takahashi will take if Aoki chooses x = X_i.\n\nConstraints\n\n2 \\leq N \\leq 100 000\n\n1 \\leq Q \\leq 100 000\n\n1 \\leq A_1 < A_2 < ... < A_N \\leq 10^9\n\n1 \\leq X_i \\leq 10^9 (1 \\leq i \\leq Q)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nA_1 A_2 ... A_N\nX_1\nX_2\n:\nX_Q\n\nOutput\n\nPrint Q lines. The i-th line (1 \\leq i \\leq Q) should contain the answer for x = X_i.\n\nSample Input 1\n\n5 5\n3 5 7 11 13\n1\n4\n9\n10\n13\n\nSample Output 1\n\n31\n31\n27\n23\n23\n\nFor example, when x = X_3(= 9), the game proceeds as follows:\n\nTakahashi takes the card with 13.\n\nAoki takes the card with 7.\n\nTakahashi takes the card with 11.\n\nAoki takes the card with 5.\n\nTakahashi takes the card with 3.\n\nThus, 13 + 11 + 3 = 27 should be printed on the third line.\n\nSample Input 2\n\n4 3\n10 20 30 40\n2\n34\n34\n\nSample Output 2\n\n70\n60\n60", "sample_input": "5 5\n3 5 7 11 13\n1\n4\n9\n10\n13\n"}, "reference_outputs": ["31\n31\n27\n23\n23\n"], "source_document_id": "p03158", "source_text": "Score : 500 points\n\nProblem Statement\n\nThere are N cards. The i-th card has an integer A_i written on it.\nFor any two cards, the integers on those cards are different.\n\nUsing these cards, Takahashi and Aoki will play the following game:\n\nAoki chooses an integer x.\n\nStarting from Takahashi, the two players alternately take a card. The card should be chosen in the following manner:\n\nTakahashi should take the card with the largest integer among the remaining card.\n\nAoki should take the card with the integer closest to x among the remaining card. If there are multiple such cards, he should take the card with the smallest integer among those cards.\n\nThe game ends when there is no card remaining.\n\nYou are given Q candidates for the value of x: X_1, X_2, ..., X_Q.\nFor each i (1 \\leq i \\leq Q), find the sum of the integers written on the cards that Takahashi will take if Aoki chooses x = X_i.\n\nConstraints\n\n2 \\leq N \\leq 100 000\n\n1 \\leq Q \\leq 100 000\n\n1 \\leq A_1 < A_2 < ... < A_N \\leq 10^9\n\n1 \\leq X_i \\leq 10^9 (1 \\leq i \\leq Q)\n\nAll values in input are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN Q\nA_1 A_2 ... A_N\nX_1\nX_2\n:\nX_Q\n\nOutput\n\nPrint Q lines. The i-th line (1 \\leq i \\leq Q) should contain the answer for x = X_i.\n\nSample Input 1\n\n5 5\n3 5 7 11 13\n1\n4\n9\n10\n13\n\nSample Output 1\n\n31\n31\n27\n23\n23\n\nFor example, when x = X_3(= 9), the game proceeds as follows:\n\nTakahashi takes the card with 13.\n\nAoki takes the card with 7.\n\nTakahashi takes the card with 11.\n\nAoki takes the card with 5.\n\nTakahashi takes the card with 3.\n\nThus, 13 + 11 + 3 = 27 should be printed on the third line.\n\nSample Input 2\n\n4 3\n10 20 30 40\n2\n34\n34\n\nSample Output 2\n\n70\n60\n60", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8788, "cpu_time_ms": 405, "memory_kb": 34664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s520851449", "group_id": "codeNet:p03162", "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 \"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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (val-a 0)\n (val-b 0)\n (val-c 0))\n (declare (uint31 n val-a val-b val-c))\n (dotimes (_ n)\n (let ((a (read-fixnum))\n (b (read-fixnum))\n (c (read-fixnum)))\n (psetq val-a (+ a (max val-b val-c))\n val-b (+ b (max val-c val-a))\n val-c (+ c (max val-a val-b)))))\n (println (max val-a val-b val-c))))\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\n10 40 70\n20 50 80\n30 60 90\n\"\n \"210\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n100 10 1\n\"\n \"100\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n6 7 8\n8 8 3\n2 5 2\n7 8 6\n4 6 8\n2 3 4\n7 5 1\n\"\n \"46\n\")))\n", "language": "Lisp", "metadata": {"date": 1579659483, "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/s520851449.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s520851449", "user_id": "u352600849"}, "prompt_components": {"gold_output": "210\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 \"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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (val-a 0)\n (val-b 0)\n (val-c 0))\n (declare (uint31 n val-a val-b val-c))\n (dotimes (_ n)\n (let ((a (read-fixnum))\n (b (read-fixnum))\n (c (read-fixnum)))\n (psetq val-a (+ a (max val-b val-c))\n val-b (+ b (max val-c val-a))\n val-c (+ c (max val-a val-b)))))\n (println (max val-a val-b val-c))))\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\n10 40 70\n20 50 80\n30 60 90\n\"\n \"210\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n100 10 1\n\"\n \"100\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n6 7 8\n8 8 3\n2 5 2\n7 8 6\n4 6 8\n2 3 4\n7 5 1\n\"\n \"46\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5429, "cpu_time_ms": 170, "memory_kb": 19172}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s705638078", "group_id": "codeNet:p03162", "input_text": "(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(defvar *n* (read))\n(defvar *in* (make-array (list *n* 3) :initial-element nil))\n \n(dotimes (i *n*)\n (dotimes (j 3)\n (setf (aref *in* i j) (read))\n ))\n \n;dp[i][j]→i日目に行動jを行うときの最大幸福度\n(defvar *dp* (make-array (list *n* 3) :initial-element -1))\n \n(defun ans (i j)\n (cond\n ((< i 0) 0)\n ((<= 0 (aref *dp* i j)) (aref *dp* i j))\n (t (setf (aref *dp* i j) (max\n (if (equal j 0) 0 (+ (ans (1- i) 0) (aref *in* i j)))\n (if (equal j 1) 0 (+ (ans (1- i) 1) (aref *in* i j)))\n (if (equal j 2) 0 (+ (ans (1- i) 2) (aref *in* i j)))\n )))\n ))\n \n(print (max (ans (1- *n*) 0) (ans (1- *n*) 1) (ans (1- *n*) 2)))", "language": "Lisp", "metadata": {"date": 1572370082, "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/s705638078.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s705638078", "user_id": "u358554431"}, "prompt_components": {"gold_output": "210\n", "input_to_evaluate": "(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(defvar *n* (read))\n(defvar *in* (make-array (list *n* 3) :initial-element nil))\n \n(dotimes (i *n*)\n (dotimes (j 3)\n (setf (aref *in* i j) (read))\n ))\n \n;dp[i][j]→i日目に行動jを行うときの最大幸福度\n(defvar *dp* (make-array (list *n* 3) :initial-element -1))\n \n(defun ans (i j)\n (cond\n ((< i 0) 0)\n ((<= 0 (aref *dp* i j)) (aref *dp* i j))\n (t (setf (aref *dp* i j) (max\n (if (equal j 0) 0 (+ (ans (1- i) 0) (aref *in* i j)))\n (if (equal j 1) 0 (+ (ans (1- i) 1) (aref *in* i j)))\n (if (equal j 2) 0 (+ (ans (1- i) 2) (aref *in* i j)))\n )))\n ))\n \n(print (max (ans (1- *n*) 0) (ans (1- *n*) 1) (ans (1- *n*) 2)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1204, "cpu_time_ms": 638, "memory_kb": 70648}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s772373689", "group_id": "codeNet:p03162", "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 ((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 split-ints-and-bind (arg-lst string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (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 :start ,pos1 :test #'char=))\n\t\t\t (,(car arg-lst) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr arg-lst) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand arg-lst)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" 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(defun solve (n table)\n (with-memoizing (:array (100001 3) :element-type 'uint32\n :initial-element #.(- (expt 2 32) 1))\n (labels ((%solve (i x)\n (cond ((= i 1) (aref table 1 x))\n ((= x 0) (+ (aref table i 0)\n (max (%solve (- i 1) 1)\n (%solve (- i 1) 2))))\n ((= x 1) (+ (aref table i 1)\n (max (%solve (- i 1) 0)\n (%solve (- i 1) 2))))\n ((= x 2) (+ (aref table i 2)\n (max (%solve (- i 1) 0)\n (%solve (- i 1) 1))))\n (t (error \"Huh?\")))))\n (max (%solve n 0)\n (%solve n 1)\n (%solve n 2)))))\n\n(defun main ()\n (let* ((n (read))\n (table (make-array (list (+ n 1) 3) :element-type 'uint16)))\n (loop for idx from 1 to n\n do (split-ints-and-bind (a b c) (read-line)\n (setf (aref table idx 0) a\n (aref table idx 1) b\n (aref table idx 2) c)))\n (println (solve n table))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1546804097, "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/s772373689.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s772373689", "user_id": "u352600849"}, "prompt_components": {"gold_output": "210\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 ((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 split-ints-and-bind (arg-lst string &body body)\n (let ((pos1 (gensym \"POS\"))\n\t(pos2 (gensym \"POS\"))\n\t(str (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 :start ,pos1 :test #'char=))\n\t\t\t (,(car arg-lst) (parse-integer ,str :start ,pos1 :end ,pos2)))\n\t\t ,@(expand (cdr arg-lst) nil))))))\n `(let ((,str ,string))\n (declare (string ,str))\n\t ,@(expand arg-lst)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" 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(defun solve (n table)\n (with-memoizing (:array (100001 3) :element-type 'uint32\n :initial-element #.(- (expt 2 32) 1))\n (labels ((%solve (i x)\n (cond ((= i 1) (aref table 1 x))\n ((= x 0) (+ (aref table i 0)\n (max (%solve (- i 1) 1)\n (%solve (- i 1) 2))))\n ((= x 1) (+ (aref table i 1)\n (max (%solve (- i 1) 0)\n (%solve (- i 1) 2))))\n ((= x 2) (+ (aref table i 2)\n (max (%solve (- i 1) 0)\n (%solve (- i 1) 1))))\n (t (error \"Huh?\")))))\n (max (%solve n 0)\n (%solve n 1)\n (%solve n 2)))))\n\n(defun main ()\n (let* ((n (read))\n (table (make-array (list (+ n 1) 3) :element-type 'uint16)))\n (loop for idx from 1 to n\n do (split-ints-and-bind (a b c) (read-line)\n (setf (aref table idx 0) a\n (aref table idx 1) b\n (aref table idx 2) c)))\n (println (solve n table))))\n\n#-swank(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9361, "cpu_time_ms": 378, "memory_kb": 66620}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s348482674", "group_id": "codeNet:p03164", "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(define-modify-macro minf (new-value) min)\n(defconstant +inf+ #x7fffffff)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (limit (read))\n (dp (make-array 100001 :element-type 'uint31 :initial-element +inf+)))\n (declare (uint31 n limit))\n (setf (aref dp 0) 0)\n (dotimes (_ n)\n (loop with w of-type uint31 = (read)\n with v of-type uint31 = (read)\n for y from 100000 downto v\n do (minf (aref dp y)\n (+ (aref dp (- y v)) w))))\n (println\n (position-if (lambda (w) (<= (the uint31 w) limit))\n dp :from-end t))))\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 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": 1579724058, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s348482674.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s348482674", "user_id": "u352600849"}, "prompt_components": {"gold_output": "90\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(define-modify-macro minf (new-value) min)\n(defconstant +inf+ #x7fffffff)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (limit (read))\n (dp (make-array 100001 :element-type 'uint31 :initial-element +inf+)))\n (declare (uint31 n limit))\n (setf (aref dp 0) 0)\n (dotimes (_ n)\n (loop with w of-type uint31 = (read)\n with v of-type uint31 = (read)\n for y from 100000 downto v\n do (minf (aref dp y)\n (+ (aref dp (- y v)) w))))\n (println\n (position-if (lambda (w) (<= (the uint31 w) limit))\n dp :from-end t))))\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 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4405, "cpu_time_ms": 59, "memory_kb": 10728}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s449111235", "group_id": "codeNet:p03166", "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 ;; 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;;; Topological sort\n;;;\n\n(define-condition cycle-detected-error (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 vertices 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(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-modify-macro maxf (new-value) max)\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 ((x (- (read-fixnum) 1))\n (y (- (read-fixnum) 1)))\n (push y (aref graph x))))\n (let ((sorted (topological-sort graph))\n (dp (make-array n :element-type 'uint31 :initial-element 0)))\n (sb-int:dovector (v sorted)\n (let ((dist (aref dp v)))\n (dolist (neighbor (aref graph v))\n (maxf (aref dp neighbor) (+ 1 dist)))))\n (println (reduce #'max 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:/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 \"4 5\n1 2\n1 3\n3 2\n2 4\n3 4\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 3\n2 3\n4 5\n5 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 8\n5 3\n2 3\n2 4\n5 2\n5 1\n1 4\n4 3\n1 3\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1579749694, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03166.html", "problem_id": "p03166", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03166/input.txt", "sample_output_relpath": "derived/input_output/data/p03166/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03166/Lisp/s449111235.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s449111235", "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\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;;; Topological sort\n;;;\n\n(define-condition cycle-detected-error (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 vertices 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(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-modify-macro maxf (new-value) max)\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 ((x (- (read-fixnum) 1))\n (y (- (read-fixnum) 1)))\n (push y (aref graph x))))\n (let ((sorted (topological-sort graph))\n (dp (make-array n :element-type 'uint31 :initial-element 0)))\n (sb-int:dovector (v sorted)\n (let ((dist (aref dp v)))\n (dolist (neighbor (aref graph v))\n (maxf (aref dp neighbor) (+ 1 dist)))))\n (println (reduce #'max 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:/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 \"4 5\n1 2\n1 3\n3 2\n2 4\n3 4\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 3\n2 3\n4 5\n5 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 8\n5 3\n2 3\n2 4\n5 2\n5 1\n1 4\n4 3\n1 3\n\"\n \"3\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a directed graph G with N vertices and M edges.\nThe vertices are numbered 1, 2, \\ldots, N, and for each i (1 \\leq i \\leq M), the i-th directed edge goes from Vertex x_i to y_i.\nG does not contain directed cycles.\n\nFind the length of the longest directed path in G.\nHere, the length of a directed path is the number of edges in it.\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\nAll pairs (x_i, y_i) are distinct.\n\nG does not contain directed cycles.\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_M y_M\n\nOutput\n\nPrint the length of the longest directed path in G.\n\nSample Input 1\n\n4 5\n1 2\n1 3\n3 2\n2 4\n3 4\n\nSample Output 1\n\n3\n\nThe red directed path in the following figure is the longest:\n\nSample Input 2\n\n6 3\n2 3\n4 5\n5 6\n\nSample Output 2\n\n2\n\nThe red directed path in the following figure is the longest:\n\nSample Input 3\n\n5 8\n5 3\n2 3\n2 4\n5 2\n5 1\n1 4\n4 3\n1 3\n\nSample Output 3\n\n3\n\nThe red directed path in the following figure is one of the longest:", "sample_input": "4 5\n1 2\n1 3\n3 2\n2 4\n3 4\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03166", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a directed graph G with N vertices and M edges.\nThe vertices are numbered 1, 2, \\ldots, N, and for each i (1 \\leq i \\leq M), the i-th directed edge goes from Vertex x_i to y_i.\nG does not contain directed cycles.\n\nFind the length of the longest directed path in G.\nHere, the length of a directed path is the number of edges in it.\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\nAll pairs (x_i, y_i) are distinct.\n\nG does not contain directed cycles.\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_M y_M\n\nOutput\n\nPrint the length of the longest directed path in G.\n\nSample Input 1\n\n4 5\n1 2\n1 3\n3 2\n2 4\n3 4\n\nSample Output 1\n\n3\n\nThe red directed path in the following figure is the longest:\n\nSample Input 2\n\n6 3\n2 3\n4 5\n5 6\n\nSample Output 2\n\n2\n\nThe red directed path in the following figure is the longest:\n\nSample Input 3\n\n5 8\n5 3\n2 3\n2 4\n5 2\n5 1\n1 4\n4 3\n1 3\n\nSample Output 3\n\n3\n\nThe red directed path in the following figure is one of the longest:", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7698, "cpu_time_ms": 119, "memory_kb": 29876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s436735848", "group_id": "codeNet:p03166", "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 ((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 #\\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;; Hauptteil\n(defun solve (graph)\n (declare #.OPT\n ((simple-array list (*)) graph))\n (let ((n (length graph)))\n (with-memoizing (:array (100001) :element-type 'fixnum :initial-element -1)\n (labels ((dp (src)\n (let ((dests (aref graph src)))\n (if (null dests)\n 0\n (loop for dest in dests\n maximize (1+ (dp dest)))))))\n (loop for src from 0 below n\n maximize (dp src))))))\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 (declare (uint32 m))\n (dotimes (i m)\n (split-ints-and-bind (x y) (buffered-read-line 15)\n (declare (uint32 x y))\n (push (- y 1) (aref graph (- x 1)))))\n (println (solve graph))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547372309, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03166.html", "problem_id": "p03166", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03166/input.txt", "sample_output_relpath": "derived/input_output/data/p03166/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03166/Lisp/s436735848.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s436735848", "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;; (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 #\\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;; Hauptteil\n(defun solve (graph)\n (declare #.OPT\n ((simple-array list (*)) graph))\n (let ((n (length graph)))\n (with-memoizing (:array (100001) :element-type 'fixnum :initial-element -1)\n (labels ((dp (src)\n (let ((dests (aref graph src)))\n (if (null dests)\n 0\n (loop for dest in dests\n maximize (1+ (dp dest)))))))\n (loop for src from 0 below n\n maximize (dp src))))))\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 (declare (uint32 m))\n (dotimes (i m)\n (split-ints-and-bind (x y) (buffered-read-line 15)\n (declare (uint32 x y))\n (push (- y 1) (aref graph (- x 1)))))\n (println (solve graph))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a directed graph G with N vertices and M edges.\nThe vertices are numbered 1, 2, \\ldots, N, and for each i (1 \\leq i \\leq M), the i-th directed edge goes from Vertex x_i to y_i.\nG does not contain directed cycles.\n\nFind the length of the longest directed path in G.\nHere, the length of a directed path is the number of edges in it.\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\nAll pairs (x_i, y_i) are distinct.\n\nG does not contain directed cycles.\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_M y_M\n\nOutput\n\nPrint the length of the longest directed path in G.\n\nSample Input 1\n\n4 5\n1 2\n1 3\n3 2\n2 4\n3 4\n\nSample Output 1\n\n3\n\nThe red directed path in the following figure is the longest:\n\nSample Input 2\n\n6 3\n2 3\n4 5\n5 6\n\nSample Output 2\n\n2\n\nThe red directed path in the following figure is the longest:\n\nSample Input 3\n\n5 8\n5 3\n2 3\n2 4\n5 2\n5 1\n1 4\n4 3\n1 3\n\nSample Output 3\n\n3\n\nThe red directed path in the following figure is one of the longest:", "sample_input": "4 5\n1 2\n1 3\n3 2\n2 4\n3 4\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03166", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a directed graph G with N vertices and M edges.\nThe vertices are numbered 1, 2, \\ldots, N, and for each i (1 \\leq i \\leq M), the i-th directed edge goes from Vertex x_i to y_i.\nG does not contain directed cycles.\n\nFind the length of the longest directed path in G.\nHere, the length of a directed path is the number of edges in it.\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\nAll pairs (x_i, y_i) are distinct.\n\nG does not contain directed cycles.\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_M y_M\n\nOutput\n\nPrint the length of the longest directed path in G.\n\nSample Input 1\n\n4 5\n1 2\n1 3\n3 2\n2 4\n3 4\n\nSample Output 1\n\n3\n\nThe red directed path in the following figure is the longest:\n\nSample Input 2\n\n6 3\n2 3\n4 5\n5 6\n\nSample Output 2\n\n2\n\nThe red directed path in the following figure is the longest:\n\nSample Input 3\n\n5 8\n5 3\n2 3\n2 4\n5 2\n5 1\n1 4\n4 3\n1 3\n\nSample Output 3\n\n3\n\nThe red directed path in the following figure is one of the longest:", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9461, "cpu_time_ms": 386, "memory_kb": 45668}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s715407383", "group_id": "codeNet:p03167", "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 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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* ((h (read))\n (w (read))\n (dp (make-array 1001 :element-type 'uint31 :initial-element 0)))\n (declare (uint16 h w))\n (setf (aref dp 1) 1)\n (dotimes (_ h)\n (loop for x from 1 to w\n do (setf (aref dp x)\n (if (char= #\\. (read-schar))\n (let ((sum (+ (aref dp x) (aref dp (- x 1)))))\n (if (>= sum +mod+)\n (- sum +mod+)\n sum))\n 0)))\n (read-schar))\n (println (aref dp w))))\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 4\n...#\n.#..\n....\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2\n..\n#.\n..\n.#\n..\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5\n..#..\n.....\n#...#\n.....\n..#..\n\"\n \"24\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20 20\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n\"\n \"345263555\n\")))\n", "language": "Lisp", "metadata": {"date": 1579752195, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03167.html", "problem_id": "p03167", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03167/input.txt", "sample_output_relpath": "derived/input_output/data/p03167/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03167/Lisp/s715407383.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s715407383", "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(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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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* ((h (read))\n (w (read))\n (dp (make-array 1001 :element-type 'uint31 :initial-element 0)))\n (declare (uint16 h w))\n (setf (aref dp 1) 1)\n (dotimes (_ h)\n (loop for x from 1 to w\n do (setf (aref dp x)\n (if (char= #\\. (read-schar))\n (let ((sum (+ (aref dp x) (aref dp (- x 1)))))\n (if (>= sum +mod+)\n (- sum +mod+)\n sum))\n 0)))\n (read-schar))\n (println (aref dp w))))\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 4\n...#\n.#..\n....\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2\n..\n#.\n..\n.#\n..\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5\n..#..\n.....\n#...#\n.....\n..#..\n\"\n \"24\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20 20\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n\"\n \"345263555\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a grid with H horizontal rows and W vertical columns.\nLet (i, j) denote the square at the i-th row from the top and the j-th column from the left.\n\nFor each i and j (1 \\leq i \\leq H, 1 \\leq j \\leq W), Square (i, j) is described by a character a_{i, j}.\nIf a_{i, j} is ., Square (i, j) is an empty square; if a_{i, j} is #, Square (i, j) is a wall square.\nIt is guaranteed that Squares (1, 1) and (H, W) are empty squares.\n\nTaro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.\n\nFind the number of Taro's paths from Square (1, 1) to (H, W).\nAs the answer can be extremely large, find the count modulo 10^9 + 7.\n\nConstraints\n\nH and W are integers.\n\n2 \\leq H, W \\leq 1000\n\na_{i, j} is . or #.\n\nSquares (1, 1) and (H, W) are empty squares.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{1, 1}\\ldotsa_{1, W}\n:\na_{H, 1}\\ldotsa_{H, W}\n\nOutput\n\nPrint the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.\n\nSample Input 1\n\n3 4\n...#\n.#..\n....\n\nSample Output 1\n\n3\n\nThere are three paths as follows:\n\nSample Input 2\n\n5 2\n..\n#.\n..\n.#\n..\n\nSample Output 2\n\n0\n\nThere may be no paths.\n\nSample Input 3\n\n5 5\n..#..\n.....\n#...#\n.....\n..#..\n\nSample Output 3\n\n24\n\nSample Input 4\n\n20 20\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n\nSample Output 4\n\n345263555\n\nBe sure to print the count modulo 10^9 + 7.", "sample_input": "3 4\n...#\n.#..\n....\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03167", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a grid with H horizontal rows and W vertical columns.\nLet (i, j) denote the square at the i-th row from the top and the j-th column from the left.\n\nFor each i and j (1 \\leq i \\leq H, 1 \\leq j \\leq W), Square (i, j) is described by a character a_{i, j}.\nIf a_{i, j} is ., Square (i, j) is an empty square; if a_{i, j} is #, Square (i, j) is a wall square.\nIt is guaranteed that Squares (1, 1) and (H, W) are empty squares.\n\nTaro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.\n\nFind the number of Taro's paths from Square (1, 1) to (H, W).\nAs the answer can be extremely large, find the count modulo 10^9 + 7.\n\nConstraints\n\nH and W are integers.\n\n2 \\leq H, W \\leq 1000\n\na_{i, j} is . or #.\n\nSquares (1, 1) and (H, W) are empty squares.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{1, 1}\\ldotsa_{1, W}\n:\na_{H, 1}\\ldotsa_{H, W}\n\nOutput\n\nPrint the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.\n\nSample Input 1\n\n3 4\n...#\n.#..\n....\n\nSample Output 1\n\n3\n\nThere are three paths as follows:\n\nSample Input 2\n\n5 2\n..\n#.\n..\n.#\n..\n\nSample Output 2\n\n0\n\nThere may be no paths.\n\nSample Input 3\n\n5 5\n..#..\n.....\n#...#\n.....\n..#..\n\nSample Output 3\n\n24\n\nSample Input 4\n\n20 20\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n\nSample Output 4\n\n345263555\n\nBe sure to print the count modulo 10^9 + 7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5181, "cpu_time_ms": 230, "memory_kb": 25188}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s646751526", "group_id": "codeNet:p03167", "input_text": "(defun mapper (x y) ;mapper\n (let* ((map-y (1- x))\n (map-x (1- y))\n (mp (make-array (list (1+ map-y) (1+ map-x)) :initial-element #\\. :element-type 'standard-char))\n (map-out-char #\\.))\n (defun accessor (accessor-x accessor-y)\n (if (and (<= 0 accessor-x map-x) (<= 0 accessor-x map-x))\n (aref mp accessor-y accessor-x)\n map-out-char))\n (loop :for yy :from 0 :upto map-y\n :do(loop :for xx :from 0 :upto map-x\n :do(setf (aref mp yy xx) (read-char))) :do(if (not (= yy map-y))\n (read-char)))))\n\n\n\n(let* ((a (read))\n (b (read))\n (dp-table (make-array (list (1+ b) (1+ a)) :initial-element 0 :element-type 'fixnum)))\n (mapper a b)\n (setf (aref dp-table 0 0) 1)\n (loop :for k :from 0 :upto (1- a)\n :do(loop :for l :from 0 :upto (1- b)\n :do(if (char= (accessor l k) #\\.)\n (progn (setf (aref dp-table (1+ l) k) (+ (aref dp-table (1+ l) k)\n (aref dp-table l k)))\n (setf (aref dp-table l (1+ k)) (+ (aref dp-table l (1+ k))\n (aref dp-table l k))))\n (setf (aref dp-table l k) 0))))\n (princ (mod (aref dp-table (1- b) (1- a)) (+ 7 (expt 10 9)))))\n", "language": "Lisp", "metadata": {"date": 1578667964, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03167.html", "problem_id": "p03167", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03167/input.txt", "sample_output_relpath": "derived/input_output/data/p03167/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03167/Lisp/s646751526.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s646751526", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun mapper (x y) ;mapper\n (let* ((map-y (1- x))\n (map-x (1- y))\n (mp (make-array (list (1+ map-y) (1+ map-x)) :initial-element #\\. :element-type 'standard-char))\n (map-out-char #\\.))\n (defun accessor (accessor-x accessor-y)\n (if (and (<= 0 accessor-x map-x) (<= 0 accessor-x map-x))\n (aref mp accessor-y accessor-x)\n map-out-char))\n (loop :for yy :from 0 :upto map-y\n :do(loop :for xx :from 0 :upto map-x\n :do(setf (aref mp yy xx) (read-char))) :do(if (not (= yy map-y))\n (read-char)))))\n\n\n\n(let* ((a (read))\n (b (read))\n (dp-table (make-array (list (1+ b) (1+ a)) :initial-element 0 :element-type 'fixnum)))\n (mapper a b)\n (setf (aref dp-table 0 0) 1)\n (loop :for k :from 0 :upto (1- a)\n :do(loop :for l :from 0 :upto (1- b)\n :do(if (char= (accessor l k) #\\.)\n (progn (setf (aref dp-table (1+ l) k) (+ (aref dp-table (1+ l) k)\n (aref dp-table l k)))\n (setf (aref dp-table l (1+ k)) (+ (aref dp-table l (1+ k))\n (aref dp-table l k))))\n (setf (aref dp-table l k) 0))))\n (princ (mod (aref dp-table (1- b) (1- a)) (+ 7 (expt 10 9)))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a grid with H horizontal rows and W vertical columns.\nLet (i, j) denote the square at the i-th row from the top and the j-th column from the left.\n\nFor each i and j (1 \\leq i \\leq H, 1 \\leq j \\leq W), Square (i, j) is described by a character a_{i, j}.\nIf a_{i, j} is ., Square (i, j) is an empty square; if a_{i, j} is #, Square (i, j) is a wall square.\nIt is guaranteed that Squares (1, 1) and (H, W) are empty squares.\n\nTaro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.\n\nFind the number of Taro's paths from Square (1, 1) to (H, W).\nAs the answer can be extremely large, find the count modulo 10^9 + 7.\n\nConstraints\n\nH and W are integers.\n\n2 \\leq H, W \\leq 1000\n\na_{i, j} is . or #.\n\nSquares (1, 1) and (H, W) are empty squares.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{1, 1}\\ldotsa_{1, W}\n:\na_{H, 1}\\ldotsa_{H, W}\n\nOutput\n\nPrint the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.\n\nSample Input 1\n\n3 4\n...#\n.#..\n....\n\nSample Output 1\n\n3\n\nThere are three paths as follows:\n\nSample Input 2\n\n5 2\n..\n#.\n..\n.#\n..\n\nSample Output 2\n\n0\n\nThere may be no paths.\n\nSample Input 3\n\n5 5\n..#..\n.....\n#...#\n.....\n..#..\n\nSample Output 3\n\n24\n\nSample Input 4\n\n20 20\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n\nSample Output 4\n\n345263555\n\nBe sure to print the count modulo 10^9 + 7.", "sample_input": "3 4\n...#\n.#..\n....\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03167", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a grid with H horizontal rows and W vertical columns.\nLet (i, j) denote the square at the i-th row from the top and the j-th column from the left.\n\nFor each i and j (1 \\leq i \\leq H, 1 \\leq j \\leq W), Square (i, j) is described by a character a_{i, j}.\nIf a_{i, j} is ., Square (i, j) is an empty square; if a_{i, j} is #, Square (i, j) is a wall square.\nIt is guaranteed that Squares (1, 1) and (H, W) are empty squares.\n\nTaro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.\n\nFind the number of Taro's paths from Square (1, 1) to (H, W).\nAs the answer can be extremely large, find the count modulo 10^9 + 7.\n\nConstraints\n\nH and W are integers.\n\n2 \\leq H, W \\leq 1000\n\na_{i, j} is . or #.\n\nSquares (1, 1) and (H, W) are empty squares.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{1, 1}\\ldotsa_{1, W}\n:\na_{H, 1}\\ldotsa_{H, W}\n\nOutput\n\nPrint the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.\n\nSample Input 1\n\n3 4\n...#\n.#..\n....\n\nSample Output 1\n\n3\n\nThere are three paths as follows:\n\nSample Input 2\n\n5 2\n..\n#.\n..\n.#\n..\n\nSample Output 2\n\n0\n\nThere may be no paths.\n\nSample Input 3\n\n5 5\n..#..\n.....\n#...#\n.....\n..#..\n\nSample Output 3\n\n24\n\nSample Input 4\n\n20 20\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n\nSample Output 4\n\n345263555\n\nBe sure to print the count modulo 10^9 + 7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 247, "memory_kb": 23528}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s942834493", "group_id": "codeNet:p03167", "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 ((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(defun read-line-into (buf-str &key (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 (schar buf-str idx) ch)\n finally (when terminate-char (setf (schar buf-str idx) terminate-char))\n (return buf-str)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" 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 solve (plan)\n (let ((h (array-dimension plan 0))\n (w (array-dimension plan 1)))\n (with-memoizing (:array (1001 1001) :element-type 'uint32\n :initial-element #.(- (expt 2 32) 1))\n (labels ((recurse (y x)\n (cond ((= 1 (sbit plan y x)) 0)\n ((and (zerop y) (zerop x)) 1)\n ((zerop y)\n (if (= 0 (sbit plan y x))\n (recurse y (- x 1))\n 0))\n ((zerop x)\n (if (= 0 (sbit plan y x))\n (recurse (- y 1) x)\n 0))\n (t\n (mod\n (+ (loop for j from (- x 1) downto 0\n while (zerop (sbit plan y j))\n sum (recurse (- y 1) j))\n (loop for i from (- y 1) downto 0\n while (zerop (sbit plan i x))\n sum (recurse i (- x 1))))\n +magic+)))))\n (recurse (- h 1) (- w 1))))))\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 (buf (make-string w :element-type 'standard-char))\n (horizontal-src-table (make-array h :element-type 'uint32))\n (vertical-src-table (make-array w :element-type 'uint32)))\n (dotimes (y h)\n (let ((line (read-line-into buf :terminate-char nil)))\n (dotimes (x w)\n (when (char= (schar line x) #\\#)\n (setf (sbit plan y x) 1)))))\n (dotimes (y h)\n (loop for x from (- w 1) downto 0\n while (zerop (sbit plan y x))\n finally (setf (aref horizontal-src-table y) (+ x 1))))\n (dotimes (x w)\n (loop for y from (- h 1) downto 0\n while (zerop (sbit plan y x))\n finally (setf (aref vertical-src-table x) (+ y 1))))\n (println (solve plan))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1546813430, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03167.html", "problem_id": "p03167", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03167/input.txt", "sample_output_relpath": "derived/input_output/data/p03167/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03167/Lisp/s942834493.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s942834493", "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 ((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(defun read-line-into (buf-str &key (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 (schar buf-str idx) ch)\n finally (when terminate-char (setf (schar buf-str idx) terminate-char))\n (return buf-str)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" 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 solve (plan)\n (let ((h (array-dimension plan 0))\n (w (array-dimension plan 1)))\n (with-memoizing (:array (1001 1001) :element-type 'uint32\n :initial-element #.(- (expt 2 32) 1))\n (labels ((recurse (y x)\n (cond ((= 1 (sbit plan y x)) 0)\n ((and (zerop y) (zerop x)) 1)\n ((zerop y)\n (if (= 0 (sbit plan y x))\n (recurse y (- x 1))\n 0))\n ((zerop x)\n (if (= 0 (sbit plan y x))\n (recurse (- y 1) x)\n 0))\n (t\n (mod\n (+ (loop for j from (- x 1) downto 0\n while (zerop (sbit plan y j))\n sum (recurse (- y 1) j))\n (loop for i from (- y 1) downto 0\n while (zerop (sbit plan i x))\n sum (recurse i (- x 1))))\n +magic+)))))\n (recurse (- h 1) (- w 1))))))\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 (buf (make-string w :element-type 'standard-char))\n (horizontal-src-table (make-array h :element-type 'uint32))\n (vertical-src-table (make-array w :element-type 'uint32)))\n (dotimes (y h)\n (let ((line (read-line-into buf :terminate-char nil)))\n (dotimes (x w)\n (when (char= (schar line x) #\\#)\n (setf (sbit plan y x) 1)))))\n (dotimes (y h)\n (loop for x from (- w 1) downto 0\n while (zerop (sbit plan y x))\n finally (setf (aref horizontal-src-table y) (+ x 1))))\n (dotimes (x w)\n (loop for y from (- h 1) downto 0\n while (zerop (sbit plan y x))\n finally (setf (aref vertical-src-table x) (+ y 1))))\n (println (solve plan))))\n\n#-swank(main)\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a grid with H horizontal rows and W vertical columns.\nLet (i, j) denote the square at the i-th row from the top and the j-th column from the left.\n\nFor each i and j (1 \\leq i \\leq H, 1 \\leq j \\leq W), Square (i, j) is described by a character a_{i, j}.\nIf a_{i, j} is ., Square (i, j) is an empty square; if a_{i, j} is #, Square (i, j) is a wall square.\nIt is guaranteed that Squares (1, 1) and (H, W) are empty squares.\n\nTaro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.\n\nFind the number of Taro's paths from Square (1, 1) to (H, W).\nAs the answer can be extremely large, find the count modulo 10^9 + 7.\n\nConstraints\n\nH and W are integers.\n\n2 \\leq H, W \\leq 1000\n\na_{i, j} is . or #.\n\nSquares (1, 1) and (H, W) are empty squares.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{1, 1}\\ldotsa_{1, W}\n:\na_{H, 1}\\ldotsa_{H, W}\n\nOutput\n\nPrint the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.\n\nSample Input 1\n\n3 4\n...#\n.#..\n....\n\nSample Output 1\n\n3\n\nThere are three paths as follows:\n\nSample Input 2\n\n5 2\n..\n#.\n..\n.#\n..\n\nSample Output 2\n\n0\n\nThere may be no paths.\n\nSample Input 3\n\n5 5\n..#..\n.....\n#...#\n.....\n..#..\n\nSample Output 3\n\n24\n\nSample Input 4\n\n20 20\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n\nSample Output 4\n\n345263555\n\nBe sure to print the count modulo 10^9 + 7.", "sample_input": "3 4\n...#\n.#..\n....\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03167", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a grid with H horizontal rows and W vertical columns.\nLet (i, j) denote the square at the i-th row from the top and the j-th column from the left.\n\nFor each i and j (1 \\leq i \\leq H, 1 \\leq j \\leq W), Square (i, j) is described by a character a_{i, j}.\nIf a_{i, j} is ., Square (i, j) is an empty square; if a_{i, j} is #, Square (i, j) is a wall square.\nIt is guaranteed that Squares (1, 1) and (H, W) are empty squares.\n\nTaro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.\n\nFind the number of Taro's paths from Square (1, 1) to (H, W).\nAs the answer can be extremely large, find the count modulo 10^9 + 7.\n\nConstraints\n\nH and W are integers.\n\n2 \\leq H, W \\leq 1000\n\na_{i, j} is . or #.\n\nSquares (1, 1) and (H, W) are empty squares.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{1, 1}\\ldotsa_{1, W}\n:\na_{H, 1}\\ldotsa_{H, W}\n\nOutput\n\nPrint the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.\n\nSample Input 1\n\n3 4\n...#\n.#..\n....\n\nSample Output 1\n\n3\n\nThere are three paths as follows:\n\nSample Input 2\n\n5 2\n..\n#.\n..\n.#\n..\n\nSample Output 2\n\n0\n\nThere may be no paths.\n\nSample Input 3\n\n5 5\n..#..\n.....\n#...#\n.....\n..#..\n\nSample Output 3\n\n24\n\nSample Input 4\n\n20 20\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n....................\n\nSample Output 4\n\n345263555\n\nBe sure to print the count modulo 10^9 + 7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9548, "cpu_time_ms": 2104, "memory_kb": 39520}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s796617578", "group_id": "codeNet:p03168", "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 (declare #.OPT)\n (let* ((*read-default-float-format* 'double-float)\n (n (read))\n (dp (make-array (+ n 1) :element-type 'double-float :initial-element 0d0)))\n (declare (uint31 n))\n (setf (aref dp 0) 1d0)\n (dotimes (x n)\n (let ((p (read)))\n (declare (double-float p))\n (setf (aref dp n) 0d0)\n (loop for y from (- n 1) downto 0\n do (incf (aref dp (+ y 1)) (* p (aref dp y)))\n (setf (aref dp y) (* (- 1d0 p) (aref dp y))))))\n (println\n (loop for y from (+ 1 (floor n 2)) to n\n sum (aref dp 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\n0.30 0.60 0.80\n\"\n \"0.612\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n0.50\n\"\n \"0.5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n0.42 0.01 0.42 0.99 0.42\n\"\n \"0.3821815872\n\")))\n", "language": "Lisp", "metadata": {"date": 1593365544, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03168.html", "problem_id": "p03168", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03168/input.txt", "sample_output_relpath": "derived/input_output/data/p03168/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03168/Lisp/s796617578.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s796617578", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0.612\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 (declare #.OPT)\n (let* ((*read-default-float-format* 'double-float)\n (n (read))\n (dp (make-array (+ n 1) :element-type 'double-float :initial-element 0d0)))\n (declare (uint31 n))\n (setf (aref dp 0) 1d0)\n (dotimes (x n)\n (let ((p (read)))\n (declare (double-float p))\n (setf (aref dp n) 0d0)\n (loop for y from (- n 1) downto 0\n do (incf (aref dp (+ y 1)) (* p (aref dp y)))\n (setf (aref dp y) (* (- 1d0 p) (aref dp y))))))\n (println\n (loop for y from (+ 1 (floor n 2)) to n\n sum (aref dp 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\n0.30 0.60 0.80\n\"\n \"0.612\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n0.50\n\"\n \"0.5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n0.42 0.01 0.42 0.99 0.42\n\"\n \"0.3821815872\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nLet N be a positive odd number.\n\nThere are N coins, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i.\n\nTaro has tossed all the N coins.\nFind the probability of having more heads than tails.\n\nConstraints\n\nN is an odd number.\n\n1 \\leq N \\leq 2999\n\np_i is a real number and has two decimal places.\n\n0 < p_i < 1\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 the probability of having more heads than tails.\nThe output is considered correct when the absolute error is not greater than 10^{-9}.\n\nSample Input 1\n\n3\n0.30 0.60 0.80\n\nSample Output 1\n\n0.612\n\nThe probability of each case where we have more heads than tails is as follows:\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Head) is 0.3 × 0.6 × 0.8 = 0.144;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Tail, Head, Head) is 0.7 × 0.6 × 0.8 = 0.336;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Tail, Head) is 0.3 × 0.4 × 0.8 = 0.096;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Tail) is 0.3 × 0.6 × 0.2 = 0.036.\n\nThus, the probability of having more heads than tails is 0.144 + 0.336 + 0.096 + 0.036 = 0.612.\n\nSample Input 2\n\n1\n0.50\n\nSample Output 2\n\n0.5\n\nOutputs such as 0.500, 0.500000001 and 0.499999999 are also considered correct.\n\nSample Input 3\n\n5\n0.42 0.01 0.42 0.99 0.42\n\nSample Output 3\n\n0.3821815872", "sample_input": "3\n0.30 0.60 0.80\n"}, "reference_outputs": ["0.612\n"], "source_document_id": "p03168", "source_text": "Score : 100 points\n\nProblem Statement\n\nLet N be a positive odd number.\n\nThere are N coins, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i.\n\nTaro has tossed all the N coins.\nFind the probability of having more heads than tails.\n\nConstraints\n\nN is an odd number.\n\n1 \\leq N \\leq 2999\n\np_i is a real number and has two decimal places.\n\n0 < p_i < 1\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 the probability of having more heads than tails.\nThe output is considered correct when the absolute error is not greater than 10^{-9}.\n\nSample Input 1\n\n3\n0.30 0.60 0.80\n\nSample Output 1\n\n0.612\n\nThe probability of each case where we have more heads than tails is as follows:\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Head) is 0.3 × 0.6 × 0.8 = 0.144;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Tail, Head, Head) is 0.7 × 0.6 × 0.8 = 0.336;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Tail, Head) is 0.3 × 0.4 × 0.8 = 0.096;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Tail) is 0.3 × 0.6 × 0.2 = 0.036.\n\nThus, the probability of having more heads than tails is 0.144 + 0.336 + 0.096 + 0.036 = 0.612.\n\nSample Input 2\n\n1\n0.50\n\nSample Output 2\n\n0.5\n\nOutputs such as 0.500, 0.500000001 and 0.499999999 are also considered correct.\n\nSample Input 3\n\n5\n0.42 0.01 0.42 0.99 0.42\n\nSample Output 3\n\n0.3821815872", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4188, "cpu_time_ms": 44, "memory_kb": 26692}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s479019646", "group_id": "codeNet:p03168", "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* ((*read-default-float-format* 'double-float)\n (n (read))\n (dp (make-array (+ n 1) :element-type 'double-float)))\n (declare (uint16 n))\n (setf (aref dp 0) 1d0)\n (dotimes (_ n)\n (let ((p (the double-float (read))))\n (loop for x from n downto 0\n do (setf (aref dp x)\n (+ (if (zerop x) 0d0 (* p (aref dp (- x 1))))\n (* (- 1d0 p) (aref dp x)))))))\n (println\n (loop for x from (ceiling n 2) to n\n sum (aref dp 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\n0.30 0.60 0.80\n\"\n \"0.612\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n0.50\n\"\n \"0.5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n0.42 0.01 0.42 0.99 0.42\n\"\n \"0.3821815872\n\")))\n", "language": "Lisp", "metadata": {"date": 1580287926, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03168.html", "problem_id": "p03168", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03168/input.txt", "sample_output_relpath": "derived/input_output/data/p03168/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03168/Lisp/s479019646.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s479019646", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0.612\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* ((*read-default-float-format* 'double-float)\n (n (read))\n (dp (make-array (+ n 1) :element-type 'double-float)))\n (declare (uint16 n))\n (setf (aref dp 0) 1d0)\n (dotimes (_ n)\n (let ((p (the double-float (read))))\n (loop for x from n downto 0\n do (setf (aref dp x)\n (+ (if (zerop x) 0d0 (* p (aref dp (- x 1))))\n (* (- 1d0 p) (aref dp x)))))))\n (println\n (loop for x from (ceiling n 2) to n\n sum (aref dp 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\n0.30 0.60 0.80\n\"\n \"0.612\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n0.50\n\"\n \"0.5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n0.42 0.01 0.42 0.99 0.42\n\"\n \"0.3821815872\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nLet N be a positive odd number.\n\nThere are N coins, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i.\n\nTaro has tossed all the N coins.\nFind the probability of having more heads than tails.\n\nConstraints\n\nN is an odd number.\n\n1 \\leq N \\leq 2999\n\np_i is a real number and has two decimal places.\n\n0 < p_i < 1\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 the probability of having more heads than tails.\nThe output is considered correct when the absolute error is not greater than 10^{-9}.\n\nSample Input 1\n\n3\n0.30 0.60 0.80\n\nSample Output 1\n\n0.612\n\nThe probability of each case where we have more heads than tails is as follows:\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Head) is 0.3 × 0.6 × 0.8 = 0.144;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Tail, Head, Head) is 0.7 × 0.6 × 0.8 = 0.336;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Tail, Head) is 0.3 × 0.4 × 0.8 = 0.096;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Tail) is 0.3 × 0.6 × 0.2 = 0.036.\n\nThus, the probability of having more heads than tails is 0.144 + 0.336 + 0.096 + 0.036 = 0.612.\n\nSample Input 2\n\n1\n0.50\n\nSample Output 2\n\n0.5\n\nOutputs such as 0.500, 0.500000001 and 0.499999999 are also considered correct.\n\nSample Input 3\n\n5\n0.42 0.01 0.42 0.99 0.42\n\nSample Output 3\n\n0.3821815872", "sample_input": "3\n0.30 0.60 0.80\n"}, "reference_outputs": ["0.612\n"], "source_document_id": "p03168", "source_text": "Score : 100 points\n\nProblem Statement\n\nLet N be a positive odd number.\n\nThere are N coins, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i.\n\nTaro has tossed all the N coins.\nFind the probability of having more heads than tails.\n\nConstraints\n\nN is an odd number.\n\n1 \\leq N \\leq 2999\n\np_i is a real number and has two decimal places.\n\n0 < p_i < 1\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 the probability of having more heads than tails.\nThe output is considered correct when the absolute error is not greater than 10^{-9}.\n\nSample Input 1\n\n3\n0.30 0.60 0.80\n\nSample Output 1\n\n0.612\n\nThe probability of each case where we have more heads than tails is as follows:\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Head) is 0.3 × 0.6 × 0.8 = 0.144;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Tail, Head, Head) is 0.7 × 0.6 × 0.8 = 0.336;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Tail, Head) is 0.3 × 0.4 × 0.8 = 0.096;\n\nThe probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Tail) is 0.3 × 0.6 × 0.2 = 0.036.\n\nThus, the probability of having more heads than tails is 0.144 + 0.336 + 0.096 + 0.036 = 0.612.\n\nSample Input 2\n\n1\n0.50\n\nSample Output 2\n\n0.5\n\nOutputs such as 0.500, 0.500000001 and 0.499999999 are also considered correct.\n\nSample Input 3\n\n5\n0.42 0.01 0.42 0.99 0.42\n\nSample Output 3\n\n0.3821815872", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4186, "cpu_time_ms": 66, "memory_kb": 12776}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s041925749", "group_id": "codeNet:p03172", "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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (dp (make-array '(101 100001) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n k))\n (setf (aref dp 0 0) 1)\n (dotimes (x n)\n (let ((a (read)))\n (declare (uint31 a))\n (dotimes (y (+ k 1))\n (incfmod (aref dp (+ x 1) y) (aref dp x y))\n (when (<= (+ y a 1) k)\n (incfmod (aref dp (+ x 1) (+ y a 1))\n (the uint31 (- +mod+ (aref dp x y))))))\n (dotimes (y k)\n (incfmod (aref dp (+ x 1) (+ y 1))\n (aref dp (+ x 1) y)))))\n (println (aref dp 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 \"3 4\n1 2 3\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 10\n9\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 0\n0 0\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 100000\n100000 100000 100000 100000\n\"\n \"665683269\n\")))\n", "language": "Lisp", "metadata": {"date": 1593300026, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s041925749.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s041925749", "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(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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (dp (make-array '(101 100001) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n k))\n (setf (aref dp 0 0) 1)\n (dotimes (x n)\n (let ((a (read)))\n (declare (uint31 a))\n (dotimes (y (+ k 1))\n (incfmod (aref dp (+ x 1) y) (aref dp x y))\n (when (<= (+ y a 1) k)\n (incfmod (aref dp (+ x 1) (+ y a 1))\n (the uint31 (- +mod+ (aref dp x y))))))\n (dotimes (y k)\n (incfmod (aref dp (+ x 1) (+ y 1))\n (aref dp (+ x 1) y)))))\n (println (aref dp 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 \"3 4\n1 2 3\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 10\n9\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 0\n0 0\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 100000\n100000 100000 100000 100000\n\"\n \"665683269\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5463, "cpu_time_ms": 129, "memory_kb": 63940}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s896321189", "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 uint62\n (+ (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": 1547673802, "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/s896321189.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s896321189", "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 uint62\n (+ (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9070, "cpu_time_ms": 279, "memory_kb": 66620}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s278567987", "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) 1)))\n (with-memoizing (:array (100 100001) :element-type 'uint32 :initial-element #xffffffff)\n (nlet recurse ((x n) (y k))\n (cond ((zerop y) 1)\n ((zerop x) 0)\n (t (mod (the (integer 0 #.most-positive-fixnum)\n (+ (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 (1+ n) :element-type 'uint32)))\n (split-ints-into-vector (read-line) as :offset 1)\n (println (solve as k))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547673404, "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/s278567987.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s278567987", "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) 1)))\n (with-memoizing (:array (100 100001) :element-type 'uint32 :initial-element #xffffffff)\n (nlet recurse ((x n) (y k))\n (cond ((zerop y) 1)\n ((zerop x) 0)\n (t (mod (the (integer 0 #.most-positive-fixnum)\n (+ (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 (1+ n) :element-type 'uint32)))\n (split-ints-into-vector (read-line) as :offset 1)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9034, "cpu_time_ms": 329, "memory_kb": 72884}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s252195755", "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 (integer-length s)\n for mask of-type uint32 = 1 then (ash mask 1)\n when (and (logtest 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": 1548837637, "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/s252195755.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s252195755", "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 (integer-length s)\n for mask of-type uint32 = 1 then (ash mask 1)\n when (and (logtest 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9179, "cpu_time_ms": 894, "memory_kb": 213220}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s778796875", "group_id": "codeNet:p03177", "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;;\n;; Matrix multiplication over semiring\n;;\n\n;; NOTE: These funcions are 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(defun gemm! (a b c &key (op+ #'+) (op* #'*) (identity+ 0))\n \"Calculates C := A*B. This function destructively modifies C. (OP+, OP*) must\ncomprise a semiring. IDENTITY+ is the identity element w.r.t. OP+.\"\n (declare ((simple-array * (* *)) a b c))\n (dotimes (row (array-dimension a 0))\n (dotimes (col (array-dimension b 1))\n (let ((res identity+))\n (dotimes (k (array-dimension a 1))\n (setf res\n (funcall op+ (funcall op* (aref a row k) (aref b k col)))))\n (setf (aref c row col) res))))\n c)\n\n(declaim (inline gemm))\n(defun gemm (a b &key (op+ #'+) (op* #'*) (identity+ 0))\n \"Calculates A*B. (OP+, OP*) must comprise a semiring. IDENTITY+ is the\nidentity element w.r.t. OP+.\"\n (declare ((simple-array * (* *)) a b)\n (function op+ op*))\n (let ((c (make-array (list (array-dimension a 0) (array-dimension b 1))\n :element-type '(unsigned-byte 31))))\n (dotimes (row (array-dimension a 0))\n (dotimes (col (array-dimension b 1))\n (let ((res identity+))\n (dotimes (k (array-dimension a 1))\n (setf res\n (funcall op+ res (funcall op* (aref a row k) (aref b k col)))))\n (setf (aref c row col) res))))\n c))\n\n(declaim (inline matrix-power))\n(defun matrix-power (base power &key (op+ #'+) (op* #'*) (identity+ 0) (identity* 1))\n (declare ((simple-array * (* *)) base)\n (function op+ op*)\n ((integer 0 #.most-positive-fixnum) power))\n (let ((size (array-dimension base 0)))\n (assert (= size (array-dimension base 1)))\n (let ((iden (make-array (array-dimensions base)\n :element-type '(unsigned-byte 31)\n :initial-element identity+)))\n (dotimes (i size)\n (setf (aref iden i i) identity*))\n (labels ((recur (p)\n (declare ((integer 0 #.most-positive-fixnum) p))\n (cond ((zerop p) iden)\n ((evenp p)\n (let ((res (recur (ash p -1))))\n (gemm res res :op+ op+ :op* op* :identity+ identity+)))\n (t\n (gemm base (recur (- p 1))\n :op+ op+ :op* op* :identity+ identity+)))))\n (recur power)))))\n\n(declaim (inline gemv))\n(defun gemv (a x &key (op+ #'+) (op* #'*) (identity+ 0))\n \"Calculates A*x for a matrix A and a vector x. (OP+, OP*) must form a\nsemiring. IDENTITY+ is the identity element w.r.t. OP+.\"\n (declare ((simple-array * (* *)) a)\n ((simple-array * (*)) x)\n (function op+ op*))\n (let ((y (make-array (array-dimension a 0) :element-type (array-element-type x))))\n (dotimes (i (length y))\n (let ((res identity+))\n (dotimes (j (length x))\n (setf res\n (funcall op+ res (funcall op* (aref a i j) (aref x j)))))\n (setf (aref y i) res)))\n y))\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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (mat (make-array (list n n) :element-type 'uint31 :initial-element 0)))\n (declare ((simple-array uint31 (* *)) mat))\n (dotimes (i n)\n (dotimes (j n)\n (setf (aref mat i j) (read))))\n (let ((mat (matrix-power mat k :op+ #'mod+ :op* #'mod*))\n (res 0))\n (dotimes (i n)\n (dotimes (j n)\n (incfmod res (aref mat i j))))\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 2\n0 1 0 0\n0 0 1 1\n0 0 0 1\n1 0 0 0\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n0 1 0\n1 0 1\n0 0 0\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 2\n0 0 0 0 0 0\n0 0 1 0 0 0\n0 0 0 0 0 0\n0 0 0 0 1 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1\n0\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 1000000000000000000\n0 0 1 1 0 0 0 1 1 0\n0 0 0 0 0 1 1 1 0 0\n0 1 0 0 0 1 0 1 0 1\n1 1 1 0 1 1 0 1 1 0\n0 1 1 1 0 1 0 1 1 1\n0 0 0 1 0 0 1 0 1 0\n0 0 0 1 1 0 0 1 0 1\n1 0 0 0 1 0 1 0 0 0\n0 0 0 0 0 1 0 0 0 0\n1 0 1 1 1 0 1 1 1 0\n\"\n \"957538352\n\")))\n", "language": "Lisp", "metadata": {"date": 1593289551, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03177.html", "problem_id": "p03177", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03177/input.txt", "sample_output_relpath": "derived/input_output/data/p03177/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03177/Lisp/s778796875.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s778796875", "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;;\n;; Matrix multiplication over semiring\n;;\n\n;; NOTE: These funcions are 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(defun gemm! (a b c &key (op+ #'+) (op* #'*) (identity+ 0))\n \"Calculates C := A*B. This function destructively modifies C. (OP+, OP*) must\ncomprise a semiring. IDENTITY+ is the identity element w.r.t. OP+.\"\n (declare ((simple-array * (* *)) a b c))\n (dotimes (row (array-dimension a 0))\n (dotimes (col (array-dimension b 1))\n (let ((res identity+))\n (dotimes (k (array-dimension a 1))\n (setf res\n (funcall op+ (funcall op* (aref a row k) (aref b k col)))))\n (setf (aref c row col) res))))\n c)\n\n(declaim (inline gemm))\n(defun gemm (a b &key (op+ #'+) (op* #'*) (identity+ 0))\n \"Calculates A*B. (OP+, OP*) must comprise a semiring. IDENTITY+ is the\nidentity element w.r.t. OP+.\"\n (declare ((simple-array * (* *)) a b)\n (function op+ op*))\n (let ((c (make-array (list (array-dimension a 0) (array-dimension b 1))\n :element-type '(unsigned-byte 31))))\n (dotimes (row (array-dimension a 0))\n (dotimes (col (array-dimension b 1))\n (let ((res identity+))\n (dotimes (k (array-dimension a 1))\n (setf res\n (funcall op+ res (funcall op* (aref a row k) (aref b k col)))))\n (setf (aref c row col) res))))\n c))\n\n(declaim (inline matrix-power))\n(defun matrix-power (base power &key (op+ #'+) (op* #'*) (identity+ 0) (identity* 1))\n (declare ((simple-array * (* *)) base)\n (function op+ op*)\n ((integer 0 #.most-positive-fixnum) power))\n (let ((size (array-dimension base 0)))\n (assert (= size (array-dimension base 1)))\n (let ((iden (make-array (array-dimensions base)\n :element-type '(unsigned-byte 31)\n :initial-element identity+)))\n (dotimes (i size)\n (setf (aref iden i i) identity*))\n (labels ((recur (p)\n (declare ((integer 0 #.most-positive-fixnum) p))\n (cond ((zerop p) iden)\n ((evenp p)\n (let ((res (recur (ash p -1))))\n (gemm res res :op+ op+ :op* op* :identity+ identity+)))\n (t\n (gemm base (recur (- p 1))\n :op+ op+ :op* op* :identity+ identity+)))))\n (recur power)))))\n\n(declaim (inline gemv))\n(defun gemv (a x &key (op+ #'+) (op* #'*) (identity+ 0))\n \"Calculates A*x for a matrix A and a vector x. (OP+, OP*) must form a\nsemiring. IDENTITY+ is the identity element w.r.t. OP+.\"\n (declare ((simple-array * (* *)) a)\n ((simple-array * (*)) x)\n (function op+ op*))\n (let ((y (make-array (array-dimension a 0) :element-type (array-element-type x))))\n (dotimes (i (length y))\n (let ((res identity+))\n (dotimes (j (length x))\n (setf res\n (funcall op+ res (funcall op* (aref a i j) (aref x j)))))\n (setf (aref y i) res)))\n y))\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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (mat (make-array (list n n) :element-type 'uint31 :initial-element 0)))\n (declare ((simple-array uint31 (* *)) mat))\n (dotimes (i n)\n (dotimes (j n)\n (setf (aref mat i j) (read))))\n (let ((mat (matrix-power mat k :op+ #'mod+ :op* #'mod*))\n (res 0))\n (dotimes (i n)\n (dotimes (j n)\n (incfmod res (aref mat i j))))\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 2\n0 1 0 0\n0 0 1 1\n0 0 0 1\n1 0 0 0\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n0 1 0\n1 0 1\n0 0 0\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 2\n0 0 0 0 0 0\n0 0 1 0 0 0\n0 0 0 0 0 0\n0 0 0 0 1 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1\n0\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 1000000000000000000\n0 0 1 1 0 0 0 1 1 0\n0 0 0 0 0 1 1 1 0 0\n0 1 0 0 0 1 0 1 0 1\n1 1 1 0 1 1 0 1 1 0\n0 1 1 1 0 1 0 1 1 1\n0 0 0 1 0 0 1 0 1 0\n0 0 0 1 1 0 0 1 0 1\n1 0 0 0 1 0 1 0 0 0\n0 0 0 0 0 1 0 0 0 0\n1 0 1 1 1 0 1 1 1 0\n\"\n \"957538352\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a simple directed graph G with N vertices, numbered 1, 2, \\ldots, N.\n\nFor each i and j (1 \\leq i, j \\leq N), you are given an integer a_{i, j} that represents whether there is a directed edge from Vertex i to j.\nIf a_{i, j} = 1, there is a directed edge from Vertex i to j; if a_{i, j} = 0, there is not.\n\nFind the number of different directed paths of length K in G, modulo 10^9 + 7.\nWe will also count a path that traverses the same edge multiple times.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 50\n\n1 \\leq K \\leq 10^{18}\n\na_{i, j} is 0 or 1.\n\na_{i, i} = 0\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_{1, 1} \\ldots a_{1, N}\n:\na_{N, 1} \\ldots a_{N, N}\n\nOutput\n\nPrint the number of different directed paths of length K in G, modulo 10^9 + 7.\n\nSample Input 1\n\n4 2\n0 1 0 0\n0 0 1 1\n0 0 0 1\n1 0 0 0\n\nSample Output 1\n\n6\n\nG is drawn in the figure below:\n\nThere are six directed paths of length 2:\n\n1 → 2 → 3\n\n1 → 2 → 4\n\n2 → 3 → 4\n\n2 → 4 → 1\n\n3 → 4 → 1\n\n4 → 1 → 2\n\nSample Input 2\n\n3 3\n0 1 0\n1 0 1\n0 0 0\n\nSample Output 2\n\n3\n\nG is drawn in the figure below:\n\nThere are three directed paths of length 3:\n\n1 → 2 → 1 → 2\n\n2 → 1 → 2 → 1\n\n2 → 1 → 2 → 3\n\nSample Input 3\n\n6 2\n0 0 0 0 0 0\n0 0 1 0 0 0\n0 0 0 0 0 0\n0 0 0 0 1 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n\nSample Output 3\n\n1\n\nG is drawn in the figure below:\n\nThere is one directed path of length 2:\n\n4 → 5 → 6\n\nSample Input 4\n\n1 1\n0\n\nSample Output 4\n\n0\n\nSample Input 5\n\n10 1000000000000000000\n0 0 1 1 0 0 0 1 1 0\n0 0 0 0 0 1 1 1 0 0\n0 1 0 0 0 1 0 1 0 1\n1 1 1 0 1 1 0 1 1 0\n0 1 1 1 0 1 0 1 1 1\n0 0 0 1 0 0 1 0 1 0\n0 0 0 1 1 0 0 1 0 1\n1 0 0 0 1 0 1 0 0 0\n0 0 0 0 0 1 0 0 0 0\n1 0 1 1 1 0 1 1 1 0\n\nSample Output 5\n\n957538352\n\nBe sure to print the count modulo 10^9 + 7.", "sample_input": "4 2\n0 1 0 0\n0 0 1 1\n0 0 0 1\n1 0 0 0\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03177", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a simple directed graph G with N vertices, numbered 1, 2, \\ldots, N.\n\nFor each i and j (1 \\leq i, j \\leq N), you are given an integer a_{i, j} that represents whether there is a directed edge from Vertex i to j.\nIf a_{i, j} = 1, there is a directed edge from Vertex i to j; if a_{i, j} = 0, there is not.\n\nFind the number of different directed paths of length K in G, modulo 10^9 + 7.\nWe will also count a path that traverses the same edge multiple times.\n\nConstraints\n\nAll values in input are integers.\n\n1 \\leq N \\leq 50\n\n1 \\leq K \\leq 10^{18}\n\na_{i, j} is 0 or 1.\n\na_{i, i} = 0\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\na_{1, 1} \\ldots a_{1, N}\n:\na_{N, 1} \\ldots a_{N, N}\n\nOutput\n\nPrint the number of different directed paths of length K in G, modulo 10^9 + 7.\n\nSample Input 1\n\n4 2\n0 1 0 0\n0 0 1 1\n0 0 0 1\n1 0 0 0\n\nSample Output 1\n\n6\n\nG is drawn in the figure below:\n\nThere are six directed paths of length 2:\n\n1 → 2 → 3\n\n1 → 2 → 4\n\n2 → 3 → 4\n\n2 → 4 → 1\n\n3 → 4 → 1\n\n4 → 1 → 2\n\nSample Input 2\n\n3 3\n0 1 0\n1 0 1\n0 0 0\n\nSample Output 2\n\n3\n\nG is drawn in the figure below:\n\nThere are three directed paths of length 3:\n\n1 → 2 → 1 → 2\n\n2 → 1 → 2 → 1\n\n2 → 1 → 2 → 3\n\nSample Input 3\n\n6 2\n0 0 0 0 0 0\n0 0 1 0 0 0\n0 0 0 0 0 0\n0 0 0 0 1 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n\nSample Output 3\n\n1\n\nG is drawn in the figure below:\n\nThere is one directed path of length 2:\n\n4 → 5 → 6\n\nSample Input 4\n\n1 1\n0\n\nSample Output 4\n\n0\n\nSample Input 5\n\n10 1000000000000000000\n0 0 1 1 0 0 0 1 1 0\n0 0 0 0 0 1 1 1 0 0\n0 1 0 0 0 1 0 1 0 1\n1 1 1 0 1 1 0 1 1 0\n0 1 1 1 0 1 0 1 1 1\n0 0 0 1 0 0 1 0 1 0\n0 0 0 1 1 0 0 1 0 1\n1 0 0 0 1 0 1 0 0 0\n0 0 0 0 0 1 0 0 0 0\n1 0 1 1 1 0 1 1 1 0\n\nSample Output 5\n\n957538352\n\nBe sure to print the count modulo 10^9 + 7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8917, "cpu_time_ms": 1527, "memory_kb": 79168}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s746340790", "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;; -*- 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;;;\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(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\n(defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) *modulus*)) 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) *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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (*modulus* (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-array n :element-type 'uint31 :initial-element 0))\n (result (make-array n :element-type 'uint31 :initial-element 0)))\n (declare ((simple-array list (*)) graph))\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 (labels ((dfs (v parent)\n (declare (int32 v parent))\n (let ((value 1))\n (declare (uint31 value))\n (dolist (child (aref graph v))\n (declare (uint31 child))\n (unless (= child parent)\n (mulfmod value (+ 1 (dfs child v)))))\n (setf (aref dp v) value)))\n (dfs2 (v parent)\n (declare (int32 v parent))\n (let* ((childs (remove parent (aref graph v)))\n (len (length childs))\n (cumul+ (make-array (+ len 1)\n :element-type 'uint31\n :initial-element 1))\n (cumul- (make-array (+ len 1)\n :element-type 'uint31\n :initial-element 1)))\n (loop for child in childs\n for i below len\n do (setf (aref cumul+ (+ i 1))\n (mod* (aref cumul+ i)\n (+ 1 (aref dp child)))))\n (loop for child in (reverse childs)\n for i from len downto 1\n do (setf (aref cumul- (- i 1))\n (mod* (aref cumul- i)\n (+ 1 (aref dp child)))))\n (setf (aref result v)\n (mod* (+ 1 (if (= parent -1) 0 (aref dp parent)))\n (aref cumul+ len)))\n (loop for child of-type uint31 in childs\n for i below len\n do (setf (aref dp v)\n (mod* (+ 1 (if (= parent -1) 0 (aref dp parent)))\n (aref cumul+ i)\n (aref cumul- (+ i 1))))\n (dfs2 child v)))))\n (dfs 0 -1)\n (dfs2 0 -1))\n (with-buffered-stdout\n (map () #'println result))))\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 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": 1572334957, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s746340790.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s746340790", "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;; -*- 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;;;\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(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\n(defun mod+ (&rest args)\n (reduce (lambda (x y) (mod (+ x y) *modulus*)) 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) *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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (*modulus* (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-array n :element-type 'uint31 :initial-element 0))\n (result (make-array n :element-type 'uint31 :initial-element 0)))\n (declare ((simple-array list (*)) graph))\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 (labels ((dfs (v parent)\n (declare (int32 v parent))\n (let ((value 1))\n (declare (uint31 value))\n (dolist (child (aref graph v))\n (declare (uint31 child))\n (unless (= child parent)\n (mulfmod value (+ 1 (dfs child v)))))\n (setf (aref dp v) value)))\n (dfs2 (v parent)\n (declare (int32 v parent))\n (let* ((childs (remove parent (aref graph v)))\n (len (length childs))\n (cumul+ (make-array (+ len 1)\n :element-type 'uint31\n :initial-element 1))\n (cumul- (make-array (+ len 1)\n :element-type 'uint31\n :initial-element 1)))\n (loop for child in childs\n for i below len\n do (setf (aref cumul+ (+ i 1))\n (mod* (aref cumul+ i)\n (+ 1 (aref dp child)))))\n (loop for child in (reverse childs)\n for i from len downto 1\n do (setf (aref cumul- (- i 1))\n (mod* (aref cumul- i)\n (+ 1 (aref dp child)))))\n (setf (aref result v)\n (mod* (+ 1 (if (= parent -1) 0 (aref dp parent)))\n (aref cumul+ len)))\n (loop for child of-type uint31 in childs\n for i below len\n do (setf (aref dp v)\n (mod* (+ 1 (if (= parent -1) 0 (aref dp parent)))\n (aref cumul+ i)\n (aref cumul- (+ i 1))))\n (dfs2 child v)))))\n (dfs 0 -1)\n (dfs2 0 -1))\n (with-buffered-stdout\n (map () #'println result))))\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 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9190, "cpu_time_ms": 231, "memory_kb": 55352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s728080974", "group_id": "codeNet:p03183", "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(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(defconstant +inf+ 40001)\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (ws (make-array n :element-type 'uint31))\n (ss (make-array n :element-type 'uint31))\n (vs (make-array n :element-type 'uint31))\n (ords (make-array n :element-type 'uint31))\n (dp (make-array (list (+ n 1) (+ +inf+ 1))\n :element-type 'fixnum\n :initial-element -1)))\n (dotimes (i n)\n (setf (aref ws i) (read-fixnum)\n (aref ss i) (read-fixnum)\n (aref vs i) (read-fixnum)\n (aref ords i) i))\n (setq ords (sort ords #'> :key (lambda (i) (+ (aref ws i) (aref ss i)))))\n (setf (aref dp 0 +inf+) 0)\n (dotimes (x n)\n (let* ((ord (aref ords x))\n (w (aref ws ord))\n (s (aref ss ord))\n (v (aref vs ord)))\n (dotimes (y (+ +inf+ 1))\n (unless (= (aref dp x y) -1)\n (maxf (aref dp (+ x 1) y) (aref dp x y))\n (cond ((= (aref dp x y) +inf+)\n (maxf (aref dp (+ x 1) s)\n (+ (aref dp x y) v)))\n ((>= y w)\n (maxf (aref dp (+ x 1) (min (- y w) s))\n (+ (aref dp x y) v))))))))\n (println\n (loop for y to +inf+\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 \"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 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": 1579587535, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s728080974.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s728080974", "user_id": "u352600849"}, "prompt_components": {"gold_output": "50\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(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(defconstant +inf+ 40001)\n\n(defun main ()\n (declare #.OPT\n (inline sort))\n (let* ((n (read))\n (ws (make-array n :element-type 'uint31))\n (ss (make-array n :element-type 'uint31))\n (vs (make-array n :element-type 'uint31))\n (ords (make-array n :element-type 'uint31))\n (dp (make-array (list (+ n 1) (+ +inf+ 1))\n :element-type 'fixnum\n :initial-element -1)))\n (dotimes (i n)\n (setf (aref ws i) (read-fixnum)\n (aref ss i) (read-fixnum)\n (aref vs i) (read-fixnum)\n (aref ords i) i))\n (setq ords (sort ords #'> :key (lambda (i) (+ (aref ws i) (aref ss i)))))\n (setf (aref dp 0 +inf+) 0)\n (dotimes (x n)\n (let* ((ord (aref ords x))\n (w (aref ws ord))\n (s (aref ss ord))\n (v (aref vs ord)))\n (dotimes (y (+ +inf+ 1))\n (unless (= (aref dp x y) -1)\n (maxf (aref dp (+ x 1) y) (aref dp x y))\n (cond ((= (aref dp x y) +inf+)\n (maxf (aref dp (+ x 1) s)\n (+ (aref dp x y) v)))\n ((>= y w)\n (maxf (aref dp (+ x 1) (min (- y w) s))\n (+ (aref dp x y) v))))))))\n (println\n (loop for y to +inf+\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 \"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 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6746, "cpu_time_ms": 371, "memory_kb": 346856}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s341428722", "group_id": "codeNet:p03184", "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;;;\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 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(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 stirling2))\n(defun stirling2 (n k)\n \"Returns the stirling number of the second kind S2(n, k). Time complexity is\nO(klog(n)).\"\n (declare ((integer 0 #.most-positive-fixnum) n k))\n (labels ((mod-power (base exp)\n (declare ((integer 0 #.most-positive-fixnum) base exp))\n (loop with res of-type (integer 0 #.most-positive-fixnum) = 1\n while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) +binom-mod+))\n do (setq base (mod (* base base) +binom-mod+)\n exp (ash exp -1))\n finally (return res))))\n (loop with result of-type fixnum = 0\n for i from 0 to k\n for delta = (mod (* (binom k i) (mod-power i n)) +binom-mod+)\n when (evenp (- k i))\n do (incf result delta)\n (when (>= result +binom-mod+)\n (decf result +binom-mod+))\n else\n do (decf result delta)\n (when (< result 0)\n (incf result +binom-mod+))\n finally (return (mod (* result (aref *fact-inv* k)) +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;;;\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(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (n (read))\n (rs (make-array (+ n 1) :element-type 'uint31 :initial-element 0))\n (cs (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 h w n))\n (dotimes (i n)\n (setf (aref rs i) (- (read) 1)\n (aref cs i) (- (read) 1)))\n (setf (aref rs n) (- h 1)\n (aref cs n) (- w 1))\n (println\n (with-cache (:array ((+ n 2)) :initial-element #x7fffffff :element-type 'uint31)\n (sb-int:named-let dp ((i n))\n (let ((r1 (aref rs i))\n (c1 (aref cs i)))\n (let ((value (binom (+ r1 c1) r1)))\n (declare (fixnum value))\n (dotimes (j (+ n 1))\n (let ((r2 (aref rs j))\n (c2 (aref cs j)))\n (when (and (/= i j) (<= r2 r1) (<= c2 c1))\n (decf value\n (mod* (dp j) (binom (- (+ r1 c1) (+ r2 c2)) (- r1 r2)))))))\n (mod value +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 4 2\n2 2\n1 4\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 2\n2 1\n4 2\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5 4\n3 1\n3 5\n1 3\n5 3\n\"\n \"24\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100000 100000 1\n50000 50000\n\"\n \"123445622\n\")))\n", "language": "Lisp", "metadata": {"date": 1593299251, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03184.html", "problem_id": "p03184", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03184/input.txt", "sample_output_relpath": "derived/input_output/data/p03184/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03184/Lisp/s341428722.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s341428722", "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#-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;;;\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 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(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 stirling2))\n(defun stirling2 (n k)\n \"Returns the stirling number of the second kind S2(n, k). Time complexity is\nO(klog(n)).\"\n (declare ((integer 0 #.most-positive-fixnum) n k))\n (labels ((mod-power (base exp)\n (declare ((integer 0 #.most-positive-fixnum) base exp))\n (loop with res of-type (integer 0 #.most-positive-fixnum) = 1\n while (> exp 0)\n when (oddp exp)\n do (setq res (mod (* res base) +binom-mod+))\n do (setq base (mod (* base base) +binom-mod+)\n exp (ash exp -1))\n finally (return res))))\n (loop with result of-type fixnum = 0\n for i from 0 to k\n for delta = (mod (* (binom k i) (mod-power i n)) +binom-mod+)\n when (evenp (- k i))\n do (incf result delta)\n (when (>= result +binom-mod+)\n (decf result +binom-mod+))\n else\n do (decf result delta)\n (when (< result 0)\n (incf result +binom-mod+))\n finally (return (mod (* result (aref *fact-inv* k)) +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;;;\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(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (n (read))\n (rs (make-array (+ n 1) :element-type 'uint31 :initial-element 0))\n (cs (make-array (+ n 1) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 h w n))\n (dotimes (i n)\n (setf (aref rs i) (- (read) 1)\n (aref cs i) (- (read) 1)))\n (setf (aref rs n) (- h 1)\n (aref cs n) (- w 1))\n (println\n (with-cache (:array ((+ n 2)) :initial-element #x7fffffff :element-type 'uint31)\n (sb-int:named-let dp ((i n))\n (let ((r1 (aref rs i))\n (c1 (aref cs i)))\n (let ((value (binom (+ r1 c1) r1)))\n (declare (fixnum value))\n (dotimes (j (+ n 1))\n (let ((r2 (aref rs j))\n (c2 (aref cs j)))\n (when (and (/= i j) (<= r2 r1) (<= c2 c1))\n (decf value\n (mod* (dp j) (binom (- (+ r1 c1) (+ r2 c2)) (- r1 r2)))))))\n (mod value +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 4 2\n2 2\n1 4\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 2\n2 1\n4 2\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5 4\n3 1\n3 5\n1 3\n5 3\n\"\n \"24\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"100000 100000 1\n50000 50000\n\"\n \"123445622\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThere is a grid with H horizontal rows and W vertical columns.\nLet (i, j) denote the square at the i-th row from the top and the j-th column from the left.\n\nIn the grid, N Squares (r_1, c_1), (r_2, c_2), \\ldots, (r_N, c_N) are wall squares, and the others are all empty squares.\nIt is guaranteed that Squares (1, 1) and (H, W) are empty squares.\n\nTaro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.\n\nFind the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq H, W \\leq 10^5\n\n1 \\leq N \\leq 3000\n\n1 \\leq r_i \\leq H\n\n1 \\leq c_i \\leq W\n\nSquares (r_i, c_i) are all distinct.\n\nSquares (1, 1) and (H, W) are empty squares.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W N\nr_1 c_1\nr_2 c_2\n:\nr_N c_N\n\nOutput\n\nPrint the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.\n\nSample Input 1\n\n3 4 2\n2 2\n1 4\n\nSample Output 1\n\n3\n\nThere are three paths as follows:\n\nSample Input 2\n\n5 2 2\n2 1\n4 2\n\nSample Output 2\n\n0\n\nThere may be no paths.\n\nSample Input 3\n\n5 5 4\n3 1\n3 5\n1 3\n5 3\n\nSample Output 3\n\n24\n\nSample Input 4\n\n100000 100000 1\n50000 50000\n\nSample Output 4\n\n123445622\n\nBe sure to print the count modulo 10^9 + 7.", "sample_input": "3 4 2\n2 2\n1 4\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03184", "source_text": "Score : 100 points\n\nProblem Statement\n\nThere is a grid with H horizontal rows and W vertical columns.\nLet (i, j) denote the square at the i-th row from the top and the j-th column from the left.\n\nIn the grid, N Squares (r_1, c_1), (r_2, c_2), \\ldots, (r_N, c_N) are wall squares, and the others are all empty squares.\nIt is guaranteed that Squares (1, 1) and (H, W) are empty squares.\n\nTaro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.\n\nFind the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.\n\nConstraints\n\nAll values in input are integers.\n\n2 \\leq H, W \\leq 10^5\n\n1 \\leq N \\leq 3000\n\n1 \\leq r_i \\leq H\n\n1 \\leq c_i \\leq W\n\nSquares (r_i, c_i) are all distinct.\n\nSquares (1, 1) and (H, W) are empty squares.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W N\nr_1 c_1\nr_2 c_2\n:\nr_N c_N\n\nOutput\n\nPrint the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.\n\nSample Input 1\n\n3 4 2\n2 2\n1 4\n\nSample Output 1\n\n3\n\nThere are three paths as follows:\n\nSample Input 2\n\n5 2 2\n2 1\n4 2\n\nSample Output 2\n\n0\n\nThere may be no paths.\n\nSample Input 3\n\n5 5 4\n3 1\n3 5\n1 3\n5 3\n\nSample Output 3\n\n24\n\nSample Input 4\n\n100000 100000 1\n50000 50000\n\nSample Output 4\n\n123445622\n\nBe sure to print the count modulo 10^9 + 7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 21737, "cpu_time_ms": 132, "memory_kb": 34596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s606970420", "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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\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 (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-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": 1572749327, "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/s606970420.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s606970420", "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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\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 (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-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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13185, "cpu_time_ms": 290, "memory_kb": 37608}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s755093939", "group_id": "codeNet:p03186", "input_text": "(defun app ()\n (let ((a (read))\n (b (read))\n (c (read))\n (ans 0))\n (if (>= b c)\n (setq ans (+ b c))\n (if (>= a (- c b))\n (setq ans (+ b c))\n (setq ans (+ b (+ b a 1)))\n )\n )\n (princ ans)\n )\n)\n(app)\n", "language": "Lisp", "metadata": {"date": 1592844151, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s755093939.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s755093939", "user_id": "u136500538"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun app ()\n (let ((a (read))\n (b (read))\n (c (read))\n (ans 0))\n (if (>= b c)\n (setq ans (+ b c))\n (if (>= a (- c b))\n (setq ans (+ b c))\n (setq ans (+ b (+ b a 1)))\n )\n )\n (princ ans)\n )\n)\n(app)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 277, "cpu_time_ms": 27, "memory_kb": 24276}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s903003475", "group_id": "codeNet:p03186", "input_text": "(let ((mazui (read))\n (umai (read))\n (umai-poison (read)))\n (princ (min (+ 1 mazui (* umai 2)) \n (+ umai umai-poison))))", "language": "Lisp", "metadata": {"date": 1584190368, "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/s903003475.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s903003475", "user_id": "u606976120"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((mazui (read))\n (umai (read))\n (umai-poison (read)))\n (princ (min (+ 1 mazui (* umai 2)) \n (+ umai umai-poison))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 144, "cpu_time_ms": 126, "memory_kb": 11876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s654659493", "group_id": "codeNet:p03186", "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* ((a (read))\n (b (read))\n (c (read)))\n (println (+ b (min c (+ 1 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 \"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 1 4\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 9\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 8 1\n\"\n \"9\n\")))\n", "language": "Lisp", "metadata": {"date": 1577965511, "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/s654659493.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s654659493", "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 ;; 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 (println (+ b (min c (+ 1 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 \"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 1 4\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 2 9\n\"\n \"10\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 8 1\n\"\n \"9\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3842, "cpu_time_ms": 23, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s578247079", "group_id": "codeNet:p03192", "input_text": "(princ (count #\\2 (read-line) :test #'eq))\n", "language": "Lisp", "metadata": {"date": 1576902508, "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/s578247079.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s578247079", "user_id": "u493610446"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(princ (count #\\2 (read-line) :test #'eq))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 43, "cpu_time_ms": 6, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s877302855", "group_id": "codeNet:p03192", "input_text": "(princ (count #\\2 (read-line)))", "language": "Lisp", "metadata": {"date": 1547010409, "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/s877302855.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s877302855", "user_id": "u652695471"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(princ (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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:s181314837", "group_id": "codeNet:p03192", "input_text": "(princ (count #\\2 (read-line)))\n", "language": "Lisp", "metadata": {"date": 1546406525, "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/s181314837.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s181314837", "user_id": "u081445141"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(princ (count #\\2 (read-line)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 32, "cpu_time_ms": 6, "memory_kb": 2788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s834212292", "group_id": "codeNet:p03196", "input_text": "(defun prime-factorization (n)\n (let ((ans '()))\n (labels ((divide (m i c)\n\t\t (unless (zerop (rem m i))\n\t\t (return-from divide (values m (cons i c))))\n\t\t (divide (/ m i) i (1+ c)))\n\t (take-apart (m i)\n\t\t\t (when (= m 1)\n\t\t\t (return-from take-apart ans))\n\n\t\t\t (when (< (sqrt m) i)\n\t\t\t (return-from take-apart\n\t\t\t (setf ans (append ans (list (cons m 1))))))\n\n\t\t\t (if (zerop (rem m i))\n\t\t\t (multiple-value-bind (m2 part) (divide m i 0)\n\t\t\t (setf ans (append ans (list part)))\n\t\t\t (take-apart m2 (1+ i)))\n\t\t\t (take-apart m (1+ i)))))\n (take-apart n 2)\n ans)))\n\n(defun caddi2018c ()\n (let* ((n (read)) (p (read)))\n (reduce #'*\n\t (mapcar (lambda (x) (expt (car x) (floor (cdr x) n)))\n\t\t (prime-factorization p)))))\n\n(format t \"~a~%\" (caddi2018c))", "language": "Lisp", "metadata": {"date": 1586407136, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03196.html", "problem_id": "p03196", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03196/input.txt", "sample_output_relpath": "derived/input_output/data/p03196/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03196/Lisp/s834212292.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s834212292", "user_id": "u652695471"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun prime-factorization (n)\n (let ((ans '()))\n (labels ((divide (m i c)\n\t\t (unless (zerop (rem m i))\n\t\t (return-from divide (values m (cons i c))))\n\t\t (divide (/ m i) i (1+ c)))\n\t (take-apart (m i)\n\t\t\t (when (= m 1)\n\t\t\t (return-from take-apart ans))\n\n\t\t\t (when (< (sqrt m) i)\n\t\t\t (return-from take-apart\n\t\t\t (setf ans (append ans (list (cons m 1))))))\n\n\t\t\t (if (zerop (rem m i))\n\t\t\t (multiple-value-bind (m2 part) (divide m i 0)\n\t\t\t (setf ans (append ans (list part)))\n\t\t\t (take-apart m2 (1+ i)))\n\t\t\t (take-apart m (1+ i)))))\n (take-apart n 2)\n ans)))\n\n(defun caddi2018c ()\n (let* ((n (read)) (p (read)))\n (reduce #'*\n\t (mapcar (lambda (x) (expt (car x) (floor (cdr x) n)))\n\t\t (prime-factorization p)))))\n\n(format t \"~a~%\" (caddi2018c))", "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": "p03196", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 805, "cpu_time_ms": 159, "memory_kb": 16224}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s074154186", "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(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;; Body\n\n(defun main ()\n (dotimes (_ (the fixnum (read)) (write-line \"second\"))\n (when (oddp (read-fixnum))\n (write-line \"first\")\n (return-from main))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1556059174, "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/s074154186.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s074154186", "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(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;; Body\n\n(defun main ()\n (dotimes (_ (the fixnum (read)) (write-line \"second\"))\n (when (oddp (read-fixnum))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1725, "cpu_time_ms": 44, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s412696653", "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(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 (dotimes (_ (read) (write-line \"second\"))\n (when (oddp (read))\n (write-line \"first\")\n (return-from main))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1556059031, "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/s412696653.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s412696653", "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(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 (dotimes (_ (read) (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2465, "cpu_time_ms": 339, "memory_kb": 59880}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s493293807", "group_id": "codeNet:p03200", "input_text": "(defun solve (s)\n (let ((n (length s))\n\t(cnt 0)\n\t(ans 0))\n (dotimes (i n)\n (when (equal (aref s i) #\\W)\n\t(setq ans (+ ans (- i cnt)))\n\t(incf cnt)))\n ans))\n\n\n(defun main()\n (let ((s (coerce (concatenate 'list (read-line)) 'vector)))\n (princ (solve s))\n (fresh-line)))\n\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1593960436, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03200.html", "problem_id": "p03200", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03200/input.txt", "sample_output_relpath": "derived/input_output/data/p03200/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03200/Lisp/s493293807.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s493293807", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve (s)\n (let ((n (length s))\n\t(cnt 0)\n\t(ans 0))\n (dotimes (i n)\n (when (equal (aref s i) #\\W)\n\t(setq ans (+ ans (- i cnt)))\n\t(incf cnt)))\n ans))\n\n\n(defun main()\n (let ((s (coerce (concatenate 'list (read-line)) 'vector)))\n (princ (solve s))\n (fresh-line)))\n\n\n(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.)\nThe state of each piece is represented by a string S of length N.\nIf S_i=B, the i-th piece from the left is showing black;\nIf S_i=W, the i-th piece from the left is showing white.\n\nConsider performing the following operation:\n\nChoose i (1 \\leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.\n\nFind the maximum possible number of times this operation can be performed.\n\nConstraints\n\n1 \\leq |S| \\leq 2\\times 10^5\n\nS_i=B or W\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the maximum possible number of times the operation can be performed.\n\nSample Input 1\n\nBBW\n\nSample Output 1\n\n2\n\nThe operation can be performed twice, as follows:\n\nFlip the second and third pieces from the left.\n\nFlip the first and second pieces from the left.\n\nSample Input 2\n\nBWBWBW\n\nSample Output 2\n\n6", "sample_input": "BBW\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03200", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.)\nThe state of each piece is represented by a string S of length N.\nIf S_i=B, the i-th piece from the left is showing black;\nIf S_i=W, the i-th piece from the left is showing white.\n\nConsider performing the following operation:\n\nChoose i (1 \\leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.\n\nFind the maximum possible number of times this operation can be performed.\n\nConstraints\n\n1 \\leq |S| \\leq 2\\times 10^5\n\nS_i=B or W\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the maximum possible number of times the operation can be performed.\n\nSample Input 1\n\nBBW\n\nSample Output 1\n\n2\n\nThe operation can be performed twice, as follows:\n\nFlip the second and third pieces from the left.\n\nFlip the first and second pieces from the left.\n\nSample Input 2\n\nBWBWBW\n\nSample Output 2\n\n6", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 295, "cpu_time_ms": 40, "memory_kb": 31620}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s482272594", "group_id": "codeNet:p03201", "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;;; 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(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +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 (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\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 force-self))\n(defun force-self (itreap)\n (declare (itreap itreap))\n (update-count itreap))\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 (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-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 (optimize (speed 3))\n ((or null itreap) left right))\n (cond ((null left) (when right (force-self right)) right)\n ((null right) (when left (force-self 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-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 itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP and returns the resultant treap.\"\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 (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-self 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-self itreap)\n itreap))))\n (recur itreap index))))\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-self 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 itreap-delete (itreap index)\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 (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-self itreap)\n itreap)\n ((> ikey left-count)\n (setf (%itreap-right itreap)\n (recur (%itreap-right itreap) (- ikey left-count 1)))\n (force-self itreap)\n itreap)\n (t\n (itreap-merge (%itreap-left itreap) (%itreap-right itreap)))))))\n (recur itreap index)))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (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-self itreap))))\n (%ref itreap index)))\n\n(declaim (inline itreap-bisect-left))\n(defun itreap-bisect-left (itreap threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(log(n)).\"\n (declare (function order))\n (labels ((recur (count itreap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null itreap) nil)\n ((funcall order (%itreap-value itreap) threshold)\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-insort))\n(defun itreap-insort (itreap obj order)\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\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 itreap\n (res 0))\n (declare (uint32 n res))\n (dotimes (i n)\n (setf itreap (itreap-insort itreap (read-fixnum) #'>)))\n #>itreap\n (loop (when (null itreap)\n (println res)\n (return-from main))\n (let* ((max (itreap-ref itreap 0))\n (target (- (sb-int:power-of-two-ceiling (+ 1 max)) max)))\n (declare (uint32 max target))\n (setq itreap (itreap-delete itreap 0))\n (let ((cand (itreap-bisect-left itreap target #'>)))\n (declare (uint32 cand))\n (when (and (< cand (itreap-count itreap))\n (= (itreap-ref itreap cand) target))\n (incf res)\n (setq itreap (itreap-delete itreap cand))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563750314, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03201.html", "problem_id": "p03201", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03201/input.txt", "sample_output_relpath": "derived/input_output/data/p03201/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03201/Lisp/s482272594.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s482272594", "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;;;\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(defstruct (itreap (:constructor %make-itreap (value priority &key left right (count 1)))\n (:copier nil)\n (:conc-name %itreap-))\n (value +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 (declare ((or null itreap) itreap))\n (if itreap\n (%itreap-count itreap)\n 0))\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 force-self))\n(defun force-self (itreap)\n (declare (itreap itreap))\n (update-count itreap))\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 (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-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 (optimize (speed 3))\n ((or null itreap) left right))\n (cond ((null left) (when right (force-self right)) right)\n ((null right) (when left (force-self 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-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 itreap-insert (itreap index obj)\n \"Destructively inserts OBJ into ITREAP and returns the resultant treap.\"\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 (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-self 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-self itreap)\n itreap))))\n (recur itreap index))))\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-self 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 itreap-delete (itreap index)\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 (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-self itreap)\n itreap)\n ((> ikey left-count)\n (setf (%itreap-right itreap)\n (recur (%itreap-right itreap) (- ikey left-count 1)))\n (force-self itreap)\n itreap)\n (t\n (itreap-merge (%itreap-left itreap) (%itreap-right itreap)))))))\n (recur itreap index)))\n\n(declaim (inline itreap-ref))\n(defun itreap-ref (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-self itreap))))\n (%ref itreap index)))\n\n(declaim (inline itreap-bisect-left))\n(defun itreap-bisect-left (itreap threshold order)\n \"Takes a **sorted** treap and returns the smallest index that satisfies\nITREAP[index] >= THRESHOLD, where >= is the complement of ORDER. Returns the\nsize of ITREAP if ITREAP[length-1] < THRESHOLD. The time complexity is\nO(log(n)).\"\n (declare (function order))\n (labels ((recur (count itreap)\n (declare ((integer 0 #.most-positive-fixnum) count))\n (cond ((null itreap) nil)\n ((funcall order (%itreap-value itreap) threshold)\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-insort))\n(defun itreap-insort (itreap obj order)\n (let ((pos (itreap-bisect-left itreap obj order)))\n (itreap-insert itreap pos obj)))\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 itreap\n (res 0))\n (declare (uint32 n res))\n (dotimes (i n)\n (setf itreap (itreap-insort itreap (read-fixnum) #'>)))\n #>itreap\n (loop (when (null itreap)\n (println res)\n (return-from main))\n (let* ((max (itreap-ref itreap 0))\n (target (- (sb-int:power-of-two-ceiling (+ 1 max)) max)))\n (declare (uint32 max target))\n (setq itreap (itreap-delete itreap 0))\n (let ((cand (itreap-bisect-left itreap target #'>)))\n (declare (uint32 cand))\n (when (and (< cand (itreap-count itreap))\n (= (itreap-ref itreap cand) target))\n (incf res)\n (setq itreap (itreap-delete itreap cand))))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nTakahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i.\nHe would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2.\nNote that a ball cannot belong to multiple pairs.\nFind the maximum possible number of pairs that can be formed.\n\nHere, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 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 number of pairs such that the sum of the integers written on each pair of balls is a power of 2.\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n1\n\nWe can form one pair whose sum of the written numbers is 4 by pairing the first and third balls.\nNote that we cannot pair the second ball with itself.\n\nSample Input 2\n\n5\n3 11 14 5 13\n\nSample Output 2\n\n2", "sample_input": "3\n1 2 3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03201", "source_text": "Score : 600 points\n\nProblem Statement\n\nTakahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i.\nHe would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2.\nNote that a ball cannot belong to multiple pairs.\nFind the maximum possible number of pairs that can be formed.\n\nHere, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.\n\nConstraints\n\n1 \\leq N \\leq 2\\times 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 number of pairs such that the sum of the integers written on each pair of balls is a power of 2.\n\nSample Input 1\n\n3\n1 2 3\n\nSample Output 1\n\n1\n\nWe can form one pair whose sum of the written numbers is 4 by pairing the first and third balls.\nNote that we cannot pair the second ball with itself.\n\nSample Input 2\n\n5\n3 11 14 5 13\n\nSample Output 2\n\n2", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11873, "cpu_time_ms": 490, "memory_kb": 47848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s157271368", "group_id": "codeNet:p03202", "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;;;\n;;; Treap with explicit key\n;;; Virtually it works like std::map, std::multiset, or java.util.TreeMap.\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\n;;\n;; (treap-ensure-key 1 :if-exists #'1+)\n;;\n;; instead of TREAP-INSERT.\n\n;; TODO & NOTE: insufficient tests\n;; TODO: introduce abstraction by macro\n\n(defstruct (treap (:constructor %make-treap (key priority value &key left right))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value 0 :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-key))\n(defun treap-key (treap)\n \"Returns the key of the (nullable) TREAP.\"\n (and treap (%treap-key treap)))\n\n(declaim (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (treap key &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 (if (null treap)\n (values nil nil)\n (progn\n (if (funcall order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split (%treap-right treap) key :order order)\n (setf (%treap-right treap) left)\n (values treap right))\n (multiple-value-bind (left right)\n (treap-split (%treap-left treap) key :order order)\n (setf (%treap-left treap) right)\n (values left treap))))))\n\n(declaim (inline treap-insert))\n(defun treap-insert (treap key value &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 (node treap)\n (declare (treap node))\n (unless treap (return-from recur node))\n (if (> (%treap-priority node) (%treap-priority treap))\n (progn\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split treap (%treap-key node) :order order))\n node)\n (progn\n (if (funcall 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 treap))))\n (recur (%make-treap key (random most-positive-fixnum) value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (treap key value &key (order #'<) 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 already contains KEY, TREAP-ENSURE-KEY\nupdates the value by the function instead of overwriting it with VALUE.\"\n (declare (function order)\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 (cond ((funcall order key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n t))\n ((funcall order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert treap key value :order order))))\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.\"\n (declare (optimize (speed 3))\n ((or null treap) left right))\n (cond ((null left) right)\n ((null right) left)\n (t\n (if (> (%treap-priority left) (%treap-priority right))\n (progn\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n right)))))\n\n(defun treap-delete (treap key &key (order #'<))\n \"Destructively deletes the KEY in TREAP and returns the resultant\ntreap. Returns the unmodified TREAP If KEY doesn't exist. You cannot rely on the\nside effect. Use the returned value.\n\n (Note that this function deletes at most one node even if duplicated keys\nexist.)\"\n (declare ((or null treap) treap)\n (function order))\n (when treap\n (cond ((funcall order key (%treap-key treap))\n (setf (%treap-left treap)\n (treap-delete (%treap-left treap) key :order order))\n treap)\n ((funcall order (%treap-key treap) key)\n (setf (%treap-right treap)\n (treap-delete (%treap-right treap) key :order order))\n treap)\n (t\n (treap-merge (%treap-left treap) (%treap-right 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 two arguments: KEY and VALUE.\"\n (labels ((recur (treap)\n (when treap\n (recur (%treap-left treap))\n (funcall function (%treap-key treap) (%treap-value 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 value)\n (if init\n (setf init nil)\n (write-char #\\ stream))\n (format stream \"<~A . ~A>\" key value))\n object))))\n\n(defmacro do-treap ((key-var value-var treap &optional result) &body body)\n \"Successively binds the key and value of INODE[0], ..., INODE[SIZE-1] to\nKEY-VAR and VALUE-VAR and executes BODY.\"\n `(block nil\n (treap-map (lambda (,key-var ,value-var) ,@body) ,treap)\n ,result))\n\n(declaim (inline treap-ref))\n(defun treap-ref (treap key &key (order #'<))\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (when treap\n (prog1 (cond ((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 (%treap-value 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 feasible-p (n as size)\n (declare #.OPT\n ((simple-array uint32 (*)) as)\n (uint31 n size))\n (let (dp)\n (dotimes (i n t)\n (let ((a (aref as i)))\n (declare (uint31 a))\n (if (null (treap-bisect-left dp a))\n (setq dp (treap-insert dp a 0))\n (progn\n (setq dp (treap-split dp (+ a 1)))\n (loop\n (setq dp (treap-ensure-key dp a 0 :if-exists #'identity))\n (let ((current (treap-ref dp a)))\n (declare (uint31 current))\n (cond ((zerop a)\n (return-from feasible-p nil))\n ((null current)\n (setq dp (treap-insert dp a 0))\n (return))\n ((= (- size 1) current)\n (setq dp (treap-ensure-key dp a 0))\n (decf a))\n (t\n (assert (< current (- size 1)))\n (setq dp (treap-ensure-key dp a (+ current 1)))\n (return))))))))\n (dbg 'end dp))))\n\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 (feasible-p n as 2)\n (sb-int:named-let bisect ((ng 0) (ok 200000))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (ash (+ ng ok) -1)))\n (if (feasible-p n as mid)\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 (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\n3 2 1\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n2 3 2 1 2\n\"\n \"2\n\")))\n", "language": "Lisp", "metadata": {"date": 1584676596, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03202.html", "problem_id": "p03202", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03202/input.txt", "sample_output_relpath": "derived/input_output/data/p03202/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03202/Lisp/s157271368.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s157271368", "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(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;;; Treap with explicit key\n;;; Virtually it works like std::map, std::multiset, or java.util.TreeMap.\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\n;;\n;; (treap-ensure-key 1 :if-exists #'1+)\n;;\n;; instead of TREAP-INSERT.\n\n;; TODO & NOTE: insufficient tests\n;; TODO: introduce abstraction by macro\n\n(defstruct (treap (:constructor %make-treap (key priority value &key left right))\n (:copier nil)\n (:conc-name %treap-))\n (key 0 :type fixnum)\n (value 0 :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-key))\n(defun treap-key (treap)\n \"Returns the key of the (nullable) TREAP.\"\n (and treap (%treap-key treap)))\n\n(declaim (ftype (function * (values (or null treap) (or null treap) &optional)) treap-split))\n(defun treap-split (treap key &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 (if (null treap)\n (values nil nil)\n (progn\n (if (funcall order (%treap-key treap) key)\n (multiple-value-bind (left right)\n (treap-split (%treap-right treap) key :order order)\n (setf (%treap-right treap) left)\n (values treap right))\n (multiple-value-bind (left right)\n (treap-split (%treap-left treap) key :order order)\n (setf (%treap-left treap) right)\n (values left treap))))))\n\n(declaim (inline treap-insert))\n(defun treap-insert (treap key value &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 (node treap)\n (declare (treap node))\n (unless treap (return-from recur node))\n (if (> (%treap-priority node) (%treap-priority treap))\n (progn\n (setf (values (%treap-left node) (%treap-right node))\n (treap-split treap (%treap-key node) :order order))\n node)\n (progn\n (if (funcall 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 treap))))\n (recur (%make-treap key (random most-positive-fixnum) value) treap)))\n\n(declaim (inline treap-ensure-key))\n(defun treap-ensure-key (treap key value &key (order #'<) 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 already contains KEY, TREAP-ENSURE-KEY\nupdates the value by the function instead of overwriting it with VALUE.\"\n (declare (function order)\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 (cond ((funcall order key (%treap-key treap))\n (when (find-and-update (%treap-left treap))\n t))\n ((funcall order (%treap-key treap) key)\n (when (find-and-update (%treap-right treap))\n t))\n (t (setf (%treap-value treap)\n (if if-exists\n (funcall if-exists (%treap-value treap))\n value))\n t))))\n (if (find-and-update treap)\n treap\n (treap-insert treap key value :order order))))\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.\"\n (declare (optimize (speed 3))\n ((or null treap) left right))\n (cond ((null left) right)\n ((null right) left)\n (t\n (if (> (%treap-priority left) (%treap-priority right))\n (progn\n (setf (%treap-right left)\n (treap-merge (%treap-right left) right))\n left)\n (progn\n (setf (%treap-left right)\n (treap-merge left (%treap-left right)))\n right)))))\n\n(defun treap-delete (treap key &key (order #'<))\n \"Destructively deletes the KEY in TREAP and returns the resultant\ntreap. Returns the unmodified TREAP If KEY doesn't exist. You cannot rely on the\nside effect. Use the returned value.\n\n (Note that this function deletes at most one node even if duplicated keys\nexist.)\"\n (declare ((or null treap) treap)\n (function order))\n (when treap\n (cond ((funcall order key (%treap-key treap))\n (setf (%treap-left treap)\n (treap-delete (%treap-left treap) key :order order))\n treap)\n ((funcall order (%treap-key treap) key)\n (setf (%treap-right treap)\n (treap-delete (%treap-right treap) key :order order))\n treap)\n (t\n (treap-merge (%treap-left treap) (%treap-right 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 two arguments: KEY and VALUE.\"\n (labels ((recur (treap)\n (when treap\n (recur (%treap-left treap))\n (funcall function (%treap-key treap) (%treap-value 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 value)\n (if init\n (setf init nil)\n (write-char #\\ stream))\n (format stream \"<~A . ~A>\" key value))\n object))))\n\n(defmacro do-treap ((key-var value-var treap &optional result) &body body)\n \"Successively binds the key and value of INODE[0], ..., INODE[SIZE-1] to\nKEY-VAR and VALUE-VAR and executes BODY.\"\n `(block nil\n (treap-map (lambda (,key-var ,value-var) ,@body) ,treap)\n ,result))\n\n(declaim (inline treap-ref))\n(defun treap-ref (treap key &key (order #'<))\n (declare ((or null treap) treap))\n (labels ((recur (treap)\n (when treap\n (prog1 (cond ((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 (%treap-value 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 feasible-p (n as size)\n (declare #.OPT\n ((simple-array uint32 (*)) as)\n (uint31 n size))\n (let (dp)\n (dotimes (i n t)\n (let ((a (aref as i)))\n (declare (uint31 a))\n (if (null (treap-bisect-left dp a))\n (setq dp (treap-insert dp a 0))\n (progn\n (setq dp (treap-split dp (+ a 1)))\n (loop\n (setq dp (treap-ensure-key dp a 0 :if-exists #'identity))\n (let ((current (treap-ref dp a)))\n (declare (uint31 current))\n (cond ((zerop a)\n (return-from feasible-p nil))\n ((null current)\n (setq dp (treap-insert dp a 0))\n (return))\n ((= (- size 1) current)\n (setq dp (treap-ensure-key dp a 0))\n (decf a))\n (t\n (assert (< current (- size 1)))\n (setq dp (treap-ensure-key dp a (+ current 1)))\n (return))))))))\n (dbg 'end dp))))\n\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 (feasible-p n as 2)\n (sb-int:named-let bisect ((ng 0) (ok 200000))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (ash (+ ng ok) -1)))\n (if (feasible-p n as mid)\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 (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\n3 2 1\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n2 3 2 1 2\n\"\n \"2\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nThere are N strings arranged in a row.\nIt is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right.\nThat is, S_1 (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* ((x (read)))\n (write-line (if (member x '(3 5 7))\n \"YES\"\n \"NO\"))))\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\n\" nil)))\n (5am:is\n (equal \"NO\n\"\n (run \"6\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600762605, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s629567045.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s629567045", "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;; BEGIN_USE_PACKAGE\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((x (read)))\n (write-line (if (member x '(3 5 7))\n \"YES\"\n \"NO\"))))\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\n\" nil)))\n (5am:is\n (equal \"NO\n\"\n (run \"6\n\" nil))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3417, "cpu_time_ms": 16, "memory_kb": 23820}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s298392874", "group_id": "codeNet:p03210", "input_text": "(if (find (read-char) \"753\") (princ \"YES\") (princ \"NO\"))", "language": "Lisp", "metadata": {"date": 1584718042, "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/s298392874.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s298392874", "user_id": "u334552723"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(if (find (read-char) \"753\") (princ \"YES\") (princ \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 56, "cpu_time_ms": 17, "memory_kb": 3688}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s554706169", "group_id": "codeNet:p03210", "input_text": "(format t \"~a~%\" ((lambda (x) (if (= x 5) (= x \"YES\" \"NO\")) (read)))", "language": "Lisp", "metadata": {"date": 1544133860, "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/s554706169.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s554706169", "user_id": "u477651929"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(format t \"~a~%\" ((lambda (x) (if (= x 5) (= x \"YES\" \"NO\")) (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 40, "memory_kb": 5224}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s490968301", "group_id": "codeNet:p03211", "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 (str)\n (loop for i from 0 to (- (length str) 3)\n minimize (abs (- 753 (read-from-string (subseq str i (+ i 3)))))))\n\n(princ (main (read-line)))\n", "language": "Lisp", "metadata": {"date": 1589140046, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03211.html", "problem_id": "p03211", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03211/input.txt", "sample_output_relpath": "derived/input_output/data/p03211/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03211/Lisp/s490968301.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s490968301", "user_id": "u493610446"}, "prompt_components": {"gold_output": "34\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 (str)\n (loop for i from 0 to (- (length str) 3)\n minimize (abs (- 753 (read-from-string (subseq str i (+ i 3)))))))\n\n(princ (main (read-line)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere is a string S consisting of digits 1, 2, ..., 9.\nLunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)\n\nThe master's favorite number is 753. The closer to this number, the better.\nWhat is the minimum possible (absolute) difference between X and 753?\n\nConstraints\n\nS is a string of length between 4 and 10 (inclusive).\n\nEach character in S is 1, 2, ..., or 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum possible difference between X and 753.\n\nSample Input 1\n\n1234567876\n\nSample Output 1\n\n34\n\nTaking out the seventh to ninth characters results in X = 787, and the difference between this and 753 is 787 - 753 = 34. The difference cannot be made smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out 567 and rearranging it to 765 is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For example, taking out the seventh digit 7, the ninth digit 7 and the tenth digit 6 to obtain 776 is not allowed.\n\nSample Input 2\n\n35753\n\nSample Output 2\n\n0\n\nIf 753 itself can be taken out, the answer is 0.\n\nSample Input 3\n\n1111111111\n\nSample Output 3\n\n642\n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642.", "sample_input": "1234567876\n"}, "reference_outputs": ["34\n"], "source_document_id": "p03211", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere is a string S consisting of digits 1, 2, ..., 9.\nLunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)\n\nThe master's favorite number is 753. The closer to this number, the better.\nWhat is the minimum possible (absolute) difference between X and 753?\n\nConstraints\n\nS is a string of length between 4 and 10 (inclusive).\n\nEach character in S is 1, 2, ..., or 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum possible difference between X and 753.\n\nSample Input 1\n\n1234567876\n\nSample Output 1\n\n34\n\nTaking out the seventh to ninth characters results in X = 787, and the difference between this and 753 is 787 - 753 = 34. The difference cannot be made smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out 567 and rearranging it to 765 is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For example, taking out the seventh digit 7, the ninth digit 7 and the tenth digit 6 to obtain 776 is not allowed.\n\nSample Input 2\n\n35753\n\nSample Output 2\n\n0\n\nIf 753 itself can be taken out, the answer is 0.\n\nSample Input 3\n\n1111111111\n\nSample Output 3\n\n642\n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2198, "cpu_time_ms": 175, "memory_kb": 21172}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s028267262", "group_id": "codeNet:p03211", "input_text": "(defun substAbs (s)\n (abs (- (parse-integer (subseq s 0 3)) 753)))\n\n(defun minSubst (s &optional (mins 10000))\n (if (< 2 (length s))\n (minSubst (subseq s 1 (length s))\n (min mins (substAbs s)))\n mins))\n\n(format t \"~a~%\" (minsubst (read-line)))\n", "language": "Lisp", "metadata": {"date": 1544124495, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03211.html", "problem_id": "p03211", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03211/input.txt", "sample_output_relpath": "derived/input_output/data/p03211/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03211/Lisp/s028267262.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s028267262", "user_id": "u477651929"}, "prompt_components": {"gold_output": "34\n", "input_to_evaluate": "(defun substAbs (s)\n (abs (- (parse-integer (subseq s 0 3)) 753)))\n\n(defun minSubst (s &optional (mins 10000))\n (if (< 2 (length s))\n (minSubst (subseq s 1 (length s))\n (min mins (substAbs s)))\n mins))\n\n(format t \"~a~%\" (minsubst (read-line)))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere is a string S consisting of digits 1, 2, ..., 9.\nLunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)\n\nThe master's favorite number is 753. The closer to this number, the better.\nWhat is the minimum possible (absolute) difference between X and 753?\n\nConstraints\n\nS is a string of length between 4 and 10 (inclusive).\n\nEach character in S is 1, 2, ..., or 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum possible difference between X and 753.\n\nSample Input 1\n\n1234567876\n\nSample Output 1\n\n34\n\nTaking out the seventh to ninth characters results in X = 787, and the difference between this and 753 is 787 - 753 = 34. The difference cannot be made smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out 567 and rearranging it to 765 is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For example, taking out the seventh digit 7, the ninth digit 7 and the tenth digit 6 to obtain 776 is not allowed.\n\nSample Input 2\n\n35753\n\nSample Output 2\n\n0\n\nIf 753 itself can be taken out, the answer is 0.\n\nSample Input 3\n\n1111111111\n\nSample Output 3\n\n642\n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642.", "sample_input": "1234567876\n"}, "reference_outputs": ["34\n"], "source_document_id": "p03211", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere is a string S consisting of digits 1, 2, ..., 9.\nLunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)\n\nThe master's favorite number is 753. The closer to this number, the better.\nWhat is the minimum possible (absolute) difference between X and 753?\n\nConstraints\n\nS is a string of length between 4 and 10 (inclusive).\n\nEach character in S is 1, 2, ..., or 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum possible difference between X and 753.\n\nSample Input 1\n\n1234567876\n\nSample Output 1\n\n34\n\nTaking out the seventh to ninth characters results in X = 787, and the difference between this and 753 is 787 - 753 = 34. The difference cannot be made smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out 567 and rearranging it to 765 is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For example, taking out the seventh digit 7, the ninth digit 7 and the tenth digit 6 to obtain 776 is not allowed.\n\nSample Input 2\n\n35753\n\nSample Output 2\n\n0\n\nIf 753 itself can be taken out, the answer is 0.\n\nSample Input 3\n\n1111111111\n\nSample Output 3\n\n642\n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 13, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s601183575", "group_id": "codeNet:p03211", "input_text": "(defun substAbs (s)\n (abs (- (parse-integer (subseq s 0 3)) 753)))\n\n(defun minSubst (s &optional (mins 10000000))\n (if (< 2 (length s))\n (if (> mins (substAbs s))\n (minSubst (subseq s 1 (length s))\n (substAbs s))\n mins)\n mins))\n", "language": "Lisp", "metadata": {"date": 1544123011, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03211.html", "problem_id": "p03211", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03211/input.txt", "sample_output_relpath": "derived/input_output/data/p03211/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03211/Lisp/s601183575.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s601183575", "user_id": "u477651929"}, "prompt_components": {"gold_output": "34\n", "input_to_evaluate": "(defun substAbs (s)\n (abs (- (parse-integer (subseq s 0 3)) 753)))\n\n(defun minSubst (s &optional (mins 10000000))\n (if (< 2 (length s))\n (if (> mins (substAbs s))\n (minSubst (subseq s 1 (length s))\n (substAbs s))\n mins)\n mins))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere is a string S consisting of digits 1, 2, ..., 9.\nLunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)\n\nThe master's favorite number is 753. The closer to this number, the better.\nWhat is the minimum possible (absolute) difference between X and 753?\n\nConstraints\n\nS is a string of length between 4 and 10 (inclusive).\n\nEach character in S is 1, 2, ..., or 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum possible difference between X and 753.\n\nSample Input 1\n\n1234567876\n\nSample Output 1\n\n34\n\nTaking out the seventh to ninth characters results in X = 787, and the difference between this and 753 is 787 - 753 = 34. The difference cannot be made smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out 567 and rearranging it to 765 is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For example, taking out the seventh digit 7, the ninth digit 7 and the tenth digit 6 to obtain 776 is not allowed.\n\nSample Input 2\n\n35753\n\nSample Output 2\n\n0\n\nIf 753 itself can be taken out, the answer is 0.\n\nSample Input 3\n\n1111111111\n\nSample Output 3\n\n642\n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642.", "sample_input": "1234567876\n"}, "reference_outputs": ["34\n"], "source_document_id": "p03211", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere is a string S consisting of digits 1, 2, ..., 9.\nLunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)\n\nThe master's favorite number is 753. The closer to this number, the better.\nWhat is the minimum possible (absolute) difference between X and 753?\n\nConstraints\n\nS is a string of length between 4 and 10 (inclusive).\n\nEach character in S is 1, 2, ..., or 9.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\n\nOutput\n\nPrint the minimum possible difference between X and 753.\n\nSample Input 1\n\n1234567876\n\nSample Output 1\n\n34\n\nTaking out the seventh to ninth characters results in X = 787, and the difference between this and 753 is 787 - 753 = 34. The difference cannot be made smaller, no matter where X is taken from.\n\nNote that the digits cannot be rearranged. For example, taking out 567 and rearranging it to 765 is not allowed.\n\nWe cannot take out three digits that are not consecutive from S, either. For example, taking out the seventh digit 7, the ninth digit 7 and the tenth digit 6 to obtain 776 is not allowed.\n\nSample Input 2\n\n35753\n\nSample Output 2\n\n0\n\nIf 753 itself can be taken out, the answer is 0.\n\nSample Input 3\n\n1111111111\n\nSample Output 3\n\n642\n\nNo matter where X is taken from, X = 111, with the difference 753 - 111 = 642.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 280, "cpu_time_ms": 121, "memory_kb": 12008}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s089783491", "group_id": "codeNet:p03213", "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 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 decompose (n prime-table)\n (map 'vector\n (lambda (p)\n (loop for i from 0\n do (multiple-value-bind (quot rem) (floor n p)\n (if (zerop rem)\n (setf n quot)\n (return i)))))\n prime-table))\n\n(defun count-4-4-2 (table)\n (let ((num2~3 (loop for i across table count (<= 2 i 3)))\n (num4~ (loop for i across table count (<= 4 i))))\n (+ (floor (* num2~3 num4~ (- num4~ 1)) 2)\n (floor (* num4~ (- num4~ 1) (- num4~ 2)) 2))))\n\n(defun count-14-4 (table)\n (let ((num4~13 (loop for i across table count (<= 4 i 13)))\n (num14~ (loop for i across table count (<= 14 i))))\n (+ (* num14~ (- num14~ 1))\n (* num14~ num4~13))))\n\n(defun count-24-2 (table)\n (let ((num2~23 (loop for i across table count (<= 2 i 23)))\n (num24~ (loop for i across table count (<= 24 i))))\n (+ (* num24~ (- num24~ 1))\n (* num24~ num2~23))))\n\n(defun count-74 (table)\n (loop for i across table count (<= 74 i)))\n\n(defun main ()\n (let* ((n (read))\n (prime-table (coerce (loop for x from 2 to n\n when (sb-impl::positive-primep x)\n collect x)\n 'vector))\n (factor-table (make-array (length prime-table) :element-type 'uint16)))\n (loop for k from 1 to n\n do (map-into factor-table #'+ factor-table (decompose k prime-table)))\n (println (+ (count-4-4-2 factor-table)\n (count-14-4 factor-table)\n (count-24-2 factor-table)\n (count-74 factor-table)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1546482703, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03213.html", "problem_id": "p03213", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03213/input.txt", "sample_output_relpath": "derived/input_output/data/p03213/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03213/Lisp/s089783491.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s089783491", "user_id": "u352600849"}, "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;; 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 decompose (n prime-table)\n (map 'vector\n (lambda (p)\n (loop for i from 0\n do (multiple-value-bind (quot rem) (floor n p)\n (if (zerop rem)\n (setf n quot)\n (return i)))))\n prime-table))\n\n(defun count-4-4-2 (table)\n (let ((num2~3 (loop for i across table count (<= 2 i 3)))\n (num4~ (loop for i across table count (<= 4 i))))\n (+ (floor (* num2~3 num4~ (- num4~ 1)) 2)\n (floor (* num4~ (- num4~ 1) (- num4~ 2)) 2))))\n\n(defun count-14-4 (table)\n (let ((num4~13 (loop for i across table count (<= 4 i 13)))\n (num14~ (loop for i across table count (<= 14 i))))\n (+ (* num14~ (- num14~ 1))\n (* num14~ num4~13))))\n\n(defun count-24-2 (table)\n (let ((num2~23 (loop for i across table count (<= 2 i 23)))\n (num24~ (loop for i across table count (<= 24 i))))\n (+ (* num24~ (- num24~ 1))\n (* num24~ num2~23))))\n\n(defun count-74 (table)\n (loop for i across table count (<= 74 i)))\n\n(defun main ()\n (let* ((n (read))\n (prime-table (coerce (loop for x from 2 to n\n when (sb-impl::positive-primep x)\n collect x)\n 'vector))\n (factor-table (make-array (length prime-table) :element-type 'uint16)))\n (loop for k from 1 to n\n do (map-into factor-table #'+ factor-table (decompose k prime-table)))\n (println (+ (count-4-4-2 factor-table)\n (count-14-4 factor-table)\n (count-24-2 factor-table)\n (count-74 factor-table)))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are given an integer N. Among the divisors of N! (= 1 \\times 2 \\times ... \\times N), how many Shichi-Go numbers (literally \"Seven-Five numbers\") are there?\n\nHere, a Shichi-Go number is a positive integer that has exactly 75 divisors.\n\nNote\n\nWhen a positive integer A divides a positive integer B, A is said to a divisor of B.\nFor example, 6 has four divisors: 1, 2, 3 and 6.\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\nPrint the number of the Shichi-Go numbers that are divisors of N!.\n\nSample Input 1\n\n9\n\nSample Output 1\n\n0\n\nThere are no Shichi-Go numbers among the divisors of 9! = 1 \\times 2 \\times ... \\times 9 = 362880.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n1\n\nThere is one Shichi-Go number among the divisors of 10! = 3628800: 32400.\n\nSample Input 3\n\n100\n\nSample Output 3\n\n543", "sample_input": "9\n"}, "reference_outputs": ["0\n"], "source_document_id": "p03213", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou are given an integer N. Among the divisors of N! (= 1 \\times 2 \\times ... \\times N), how many Shichi-Go numbers (literally \"Seven-Five numbers\") are there?\n\nHere, a Shichi-Go number is a positive integer that has exactly 75 divisors.\n\nNote\n\nWhen a positive integer A divides a positive integer B, A is said to a divisor of B.\nFor example, 6 has four divisors: 1, 2, 3 and 6.\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\nPrint the number of the Shichi-Go numbers that are divisors of N!.\n\nSample Input 1\n\n9\n\nSample Output 1\n\n0\n\nThere are no Shichi-Go numbers among the divisors of 9! = 1 \\times 2 \\times ... \\times 9 = 362880.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n1\n\nThere is one Shichi-Go number among the divisors of 10! = 3628800: 32400.\n\nSample Input 3\n\n100\n\nSample Output 3\n\n543", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2532, "cpu_time_ms": 217, "memory_kb": 23652}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s973909218", "group_id": "codeNet:p03213", "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 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 decompose (n prime-table)\n (map 'vector\n (lambda (p)\n (loop for i from 0\n do (multiple-value-bind (quot rem) (floor n p)\n (if (zerop rem)\n (setf n quot)\n (return i)))))\n prime-table))\n\n(defun count-4-4-2 (table)\n (let ((num2~3 (loop for i across table count (<= 2 i 3)))\n (num4~ (loop for i across table count (<= 4 i))))\n (+ (floor (* num2~3 num4~ (- num4~ 1)) 2)\n (floor (* num4~ (- num4~ 1) (- num4~ 2)) 2))))\n\n(defun count-14-4 (table)\n (let ((num4~13 (loop for i across table count (<= 4 i 13)))\n (num14~ (loop for i across table count (<= 14 i))))\n (+ (* num14~ (- num14~ 1))\n (* num14~ num4~13))))\n\n(defun count-24-2 (table)\n (let ((num2~23 (loop for i across table count (<= 2 i 23)))\n (num24~ (loop for i across table count (<= 24 i))))\n (+ (* num24~ (- num24~ 1))\n (* num24~ num2~23))))\n\n(defun count-74 (table)\n (loop for i across table count (<= 74 i)))\n\n(defun main ()\n (let* ((n (read))\n (prime-table (coerce (loop for x from 2 to n\n when (sb-impl::positive-primep x)\n collect x)\n 'vector))\n (factor-table (make-array (length prime-table) :element-type 'uint16)))\n (loop for k from 1 to n\n do (map-into factor-table #'+ factor-table (decompose k prime-table)))\n (println (+ (count-4-4-2 factor-table)\n (count-14-4 factor-table)\n (count-24-2 factor-table)\n (count-74 factor-table)))))\n", "language": "Lisp", "metadata": {"date": 1546482056, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03213.html", "problem_id": "p03213", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03213/input.txt", "sample_output_relpath": "derived/input_output/data/p03213/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03213/Lisp/s973909218.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s973909218", "user_id": "u352600849"}, "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;; 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 decompose (n prime-table)\n (map 'vector\n (lambda (p)\n (loop for i from 0\n do (multiple-value-bind (quot rem) (floor n p)\n (if (zerop rem)\n (setf n quot)\n (return i)))))\n prime-table))\n\n(defun count-4-4-2 (table)\n (let ((num2~3 (loop for i across table count (<= 2 i 3)))\n (num4~ (loop for i across table count (<= 4 i))))\n (+ (floor (* num2~3 num4~ (- num4~ 1)) 2)\n (floor (* num4~ (- num4~ 1) (- num4~ 2)) 2))))\n\n(defun count-14-4 (table)\n (let ((num4~13 (loop for i across table count (<= 4 i 13)))\n (num14~ (loop for i across table count (<= 14 i))))\n (+ (* num14~ (- num14~ 1))\n (* num14~ num4~13))))\n\n(defun count-24-2 (table)\n (let ((num2~23 (loop for i across table count (<= 2 i 23)))\n (num24~ (loop for i across table count (<= 24 i))))\n (+ (* num24~ (- num24~ 1))\n (* num24~ num2~23))))\n\n(defun count-74 (table)\n (loop for i across table count (<= 74 i)))\n\n(defun main ()\n (let* ((n (read))\n (prime-table (coerce (loop for x from 2 to n\n when (sb-impl::positive-primep x)\n collect x)\n 'vector))\n (factor-table (make-array (length prime-table) :element-type 'uint16)))\n (loop for k from 1 to n\n do (map-into factor-table #'+ factor-table (decompose k prime-table)))\n (println (+ (count-4-4-2 factor-table)\n (count-14-4 factor-table)\n (count-24-2 factor-table)\n (count-74 factor-table)))))\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are given an integer N. Among the divisors of N! (= 1 \\times 2 \\times ... \\times N), how many Shichi-Go numbers (literally \"Seven-Five numbers\") are there?\n\nHere, a Shichi-Go number is a positive integer that has exactly 75 divisors.\n\nNote\n\nWhen a positive integer A divides a positive integer B, A is said to a divisor of B.\nFor example, 6 has four divisors: 1, 2, 3 and 6.\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\nPrint the number of the Shichi-Go numbers that are divisors of N!.\n\nSample Input 1\n\n9\n\nSample Output 1\n\n0\n\nThere are no Shichi-Go numbers among the divisors of 9! = 1 \\times 2 \\times ... \\times 9 = 362880.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n1\n\nThere is one Shichi-Go number among the divisors of 10! = 3628800: 32400.\n\nSample Input 3\n\n100\n\nSample Output 3\n\n543", "sample_input": "9\n"}, "reference_outputs": ["0\n"], "source_document_id": "p03213", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou are given an integer N. Among the divisors of N! (= 1 \\times 2 \\times ... \\times N), how many Shichi-Go numbers (literally \"Seven-Five numbers\") are there?\n\nHere, a Shichi-Go number is a positive integer that has exactly 75 divisors.\n\nNote\n\nWhen a positive integer A divides a positive integer B, A is said to a divisor of B.\nFor example, 6 has four divisors: 1, 2, 3 and 6.\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\nPrint the number of the Shichi-Go numbers that are divisors of N!.\n\nSample Input 1\n\n9\n\nSample Output 1\n\n0\n\nThere are no Shichi-Go numbers among the divisors of 9! = 1 \\times 2 \\times ... \\times 9 = 362880.\n\nSample Input 2\n\n10\n\nSample Output 2\n\n1\n\nThere is one Shichi-Go number among the divisors of 10! = 3628800: 32400.\n\nSample Input 3\n\n100\n\nSample Output 3\n\n543", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2517, "cpu_time_ms": 221, "memory_kb": 23656}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s353757807", "group_id": "codeNet:p03216", "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 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)\n #-swank (sb-kernel:ansi-stream in))\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;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (s (let ((s (make-string n :element-type 'base-char)))\n (read-line-into s)))\n (q (read))\n (ks (make-array q :element-type 'uint32))\n (cumul-d (make-array (+ n 1) :element-type 'uint31))\n (cumul-m (make-array (+ n 1) :element-type 'uint31))\n (cumul-c (make-array (+ n 1) :element-type 'uint31))\n (cumul-dm (make-array (+ n 1) :element-type 'uint62))\n (total-dmc 0))\n (declare (uint31 n q)\n (uint62 total-dmc)\n (simple-base-string s))\n (dotimes (i q)\n (setf (aref ks i) (read)))\n (dotimes (i n)\n (setf (aref cumul-d (+ i 1))\n (+ (aref cumul-d i)\n (if (char= #\\D (aref s i)) 1 0)))\n (setf (aref cumul-m (+ i 1))\n (+ (aref cumul-m i)\n (if (char= #\\M (aref s i)) 1 0)))\n (setf (aref cumul-c (+ i 1))\n (+ (aref cumul-c i)\n (if (char= #\\C (aref s i)) 1 0)))\n (setf (aref cumul-dm (+ i 1))\n (if (char= #\\M (aref s i))\n (+ (aref cumul-dm i) (aref cumul-d i))\n (aref cumul-dm i))))\n (dotimes (i n)\n (when (char= #\\M (aref s i))\n (incf total-dmc (* (aref cumul-d i)\n (- (aref cumul-c n) (aref cumul-c i))))))\n (labels ((calc (k)\n (let ((res 0))\n (declare (uint62 res))\n (dotimes (z n)\n (when (char= #\\C (aref s z))\n (incf res (aref cumul-dm (max 0 (+ 1 (- z k)))))\n (incf res (* (aref cumul-d (max 0 (+ 1 (- z k))))\n (- (aref cumul-m z)\n (aref cumul-m (max 0 (+ 1 (- z k)))))))))\n res)))\n (sb-int:dovector (k ks)\n (println (- total-dmc (calc k)))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1570077670, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03216.html", "problem_id": "p03216", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03216/input.txt", "sample_output_relpath": "derived/input_output/data/p03216/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03216/Lisp/s353757807.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s353757807", "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(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)\n #-swank (sb-kernel:ansi-stream in))\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;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (s (let ((s (make-string n :element-type 'base-char)))\n (read-line-into s)))\n (q (read))\n (ks (make-array q :element-type 'uint32))\n (cumul-d (make-array (+ n 1) :element-type 'uint31))\n (cumul-m (make-array (+ n 1) :element-type 'uint31))\n (cumul-c (make-array (+ n 1) :element-type 'uint31))\n (cumul-dm (make-array (+ n 1) :element-type 'uint62))\n (total-dmc 0))\n (declare (uint31 n q)\n (uint62 total-dmc)\n (simple-base-string s))\n (dotimes (i q)\n (setf (aref ks i) (read)))\n (dotimes (i n)\n (setf (aref cumul-d (+ i 1))\n (+ (aref cumul-d i)\n (if (char= #\\D (aref s i)) 1 0)))\n (setf (aref cumul-m (+ i 1))\n (+ (aref cumul-m i)\n (if (char= #\\M (aref s i)) 1 0)))\n (setf (aref cumul-c (+ i 1))\n (+ (aref cumul-c i)\n (if (char= #\\C (aref s i)) 1 0)))\n (setf (aref cumul-dm (+ i 1))\n (if (char= #\\M (aref s i))\n (+ (aref cumul-dm i) (aref cumul-d i))\n (aref cumul-dm i))))\n (dotimes (i n)\n (when (char= #\\M (aref s i))\n (incf total-dmc (* (aref cumul-d i)\n (- (aref cumul-c n) (aref cumul-c i))))))\n (labels ((calc (k)\n (let ((res 0))\n (declare (uint62 res))\n (dotimes (z n)\n (when (char= #\\C (aref s z))\n (incf res (aref cumul-dm (max 0 (+ 1 (- z k)))))\n (incf res (* (aref cumul-d (max 0 (+ 1 (- z k))))\n (- (aref cumul-m z)\n (aref cumul-m (max 0 (+ 1 (- z k)))))))))\n res)))\n (sb-int:dovector (k ks)\n (println (- total-dmc (calc k)))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nIn Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short.\n\nThe name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string.\n\nGiven a string S of length N and an integer k (k \\geq 3),\nhe defines the k-DMC number of S as the number of triples (a, b, c) of integers that satisfy the following conditions:\n\n0 \\leq a < b < c \\leq N - 1\n\nS[a] = D\n\nS[b] = M\n\nS[c] = C\n\nc-a < k\n\nHere S[a] is the a-th character of the string S. Indexing is zero-based, that is, 0 \\leq a \\leq N - 1 holds.\n\nFor a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC number of S for each i (0 \\leq i \\leq Q-1).\n\nConstraints\n\n3 \\leq N \\leq 10^6\n\nS consists of uppercase English letters\n\n1 \\leq Q \\leq 75\n\n3 \\leq k_i \\leq N\n\nAll numbers given in input are integers\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\nQ\nk_{0} k_{1} ... k_{Q-1}\n\nOutput\n\nPrint Q lines.\nThe i-th line should contain the k_i-DMC number of the string S.\n\nSample Input 1\n\n18\nDWANGOMEDIACLUSTER\n1\n18\n\nSample Output 1\n\n1\n\n(a,b,c) = (0, 6, 11) satisfies the conditions.\n\nStrangely, Dwango Media Cluster does not have so much DMC-ness by his definition.\n\nSample Input 2\n\n18\nDDDDDDMMMMMCCCCCCC\n1\n18\n\nSample Output 2\n\n210\n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\nSample Input 3\n\n54\nDIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n3\n20 30 40\n\nSample Output 3\n\n0\n1\n2\n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last one, namely, c-a < k_i.\n\nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming Operation\".\n\nSample Output 4\n\n30\nDMCDMCDMCDMCDMCDMCDMCDMCDMCDMC\n4\n5 10 15 20\n\nSample Output 4\n\n10\n52\n110\n140", "sample_input": "18\nDWANGOMEDIACLUSTER\n1\n18\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03216", "source_text": "Score : 600 points\n\nProblem Statement\n\nIn Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short.\n\nThe name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string.\n\nGiven a string S of length N and an integer k (k \\geq 3),\nhe defines the k-DMC number of S as the number of triples (a, b, c) of integers that satisfy the following conditions:\n\n0 \\leq a < b < c \\leq N - 1\n\nS[a] = D\n\nS[b] = M\n\nS[c] = C\n\nc-a < k\n\nHere S[a] is the a-th character of the string S. Indexing is zero-based, that is, 0 \\leq a \\leq N - 1 holds.\n\nFor a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC number of S for each i (0 \\leq i \\leq Q-1).\n\nConstraints\n\n3 \\leq N \\leq 10^6\n\nS consists of uppercase English letters\n\n1 \\leq Q \\leq 75\n\n3 \\leq k_i \\leq N\n\nAll numbers given in input are integers\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\nQ\nk_{0} k_{1} ... k_{Q-1}\n\nOutput\n\nPrint Q lines.\nThe i-th line should contain the k_i-DMC number of the string S.\n\nSample Input 1\n\n18\nDWANGOMEDIACLUSTER\n1\n18\n\nSample Output 1\n\n1\n\n(a,b,c) = (0, 6, 11) satisfies the conditions.\n\nStrangely, Dwango Media Cluster does not have so much DMC-ness by his definition.\n\nSample Input 2\n\n18\nDDDDDDMMMMMCCCCCCC\n1\n18\n\nSample Output 2\n\n210\n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\nSample Input 3\n\n54\nDIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n3\n20 30 40\n\nSample Output 3\n\n0\n1\n2\n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last one, namely, c-a < k_i.\n\nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming Operation\".\n\nSample Output 4\n\n30\nDMCDMCDMCDMCDMCDMCDMCDMCDMCDMC\n4\n5 10 15 20\n\nSample Output 4\n\n10\n52\n110\n140", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4066, "cpu_time_ms": 536, "memory_kb": 39904}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s814585209", "group_id": "codeNet:p03216", "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 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)\n #-swank (sb-kernel:ansi-stream in))\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;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (s (let ((s (make-string n :element-type 'base-char)))\n (read-line-into s)))\n (q (read))\n (ks (make-array q :element-type 'uint32))\n (cumul-d (make-array (+ n 1) :element-type 'uint31))\n (cumul-m (make-array (+ n 1) :element-type 'uint31))\n (cumul-c (make-array (+ n 1) :element-type 'uint31))\n (cumul-dm (make-array (+ n 1) :element-type 'uint31)))\n (declare (uint31 n q)\n (simple-base-string s))\n (dotimes (i q)\n (setf (aref ks i) (read)))\n (dotimes (i n)\n (setf (aref cumul-d (+ i 1))\n (+ (aref cumul-d i)\n (if (char= #\\D (aref s i)) 1 0)))\n (setf (aref cumul-m (+ i 1))\n (+ (aref cumul-m i)\n (if (char= #\\M (aref s i)) 1 0)))\n (setf (aref cumul-c (+ i 1))\n (+ (aref cumul-c i)\n (if (char= #\\C (aref s i)) 1 0))))\n (dotimes (i n)\n (setf (aref cumul-dm (+ i 1))\n (if (char= #\\M (aref s i))\n (+ (aref cumul-dm i) (aref cumul-d i))\n (aref cumul-dm i))))\n (let ((total-dmc 0))\n (declare (uint62 total-dmc))\n (dotimes (i n)\n (when (char= #\\M (aref s i))\n (incf total-dmc (* (aref cumul-d i)\n (- (aref cumul-c n) (aref cumul-c i))))))\n (labels ((calc (k)\n (let ((res 0))\n (declare (uint62 res))\n (dotimes (z n)\n (when (char= #\\C (aref s z))\n (incf res (aref cumul-dm (max 0 (+ 1 (- z k)))))\n (incf res (* (aref cumul-d (max 0 (+ 1 (- z k))))\n (- (aref cumul-m z)\n (aref cumul-m (max 0 (+ 1 (- z k)))))))))\n res)))\n (sb-int:dovector (k ks)\n (println (- total-dmc (calc k))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1570077374, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03216.html", "problem_id": "p03216", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03216/input.txt", "sample_output_relpath": "derived/input_output/data/p03216/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03216/Lisp/s814585209.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s814585209", "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(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)\n #-swank (sb-kernel:ansi-stream in))\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;;;\n;;; Body\n;;;\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (s (let ((s (make-string n :element-type 'base-char)))\n (read-line-into s)))\n (q (read))\n (ks (make-array q :element-type 'uint32))\n (cumul-d (make-array (+ n 1) :element-type 'uint31))\n (cumul-m (make-array (+ n 1) :element-type 'uint31))\n (cumul-c (make-array (+ n 1) :element-type 'uint31))\n (cumul-dm (make-array (+ n 1) :element-type 'uint31)))\n (declare (uint31 n q)\n (simple-base-string s))\n (dotimes (i q)\n (setf (aref ks i) (read)))\n (dotimes (i n)\n (setf (aref cumul-d (+ i 1))\n (+ (aref cumul-d i)\n (if (char= #\\D (aref s i)) 1 0)))\n (setf (aref cumul-m (+ i 1))\n (+ (aref cumul-m i)\n (if (char= #\\M (aref s i)) 1 0)))\n (setf (aref cumul-c (+ i 1))\n (+ (aref cumul-c i)\n (if (char= #\\C (aref s i)) 1 0))))\n (dotimes (i n)\n (setf (aref cumul-dm (+ i 1))\n (if (char= #\\M (aref s i))\n (+ (aref cumul-dm i) (aref cumul-d i))\n (aref cumul-dm i))))\n (let ((total-dmc 0))\n (declare (uint62 total-dmc))\n (dotimes (i n)\n (when (char= #\\M (aref s i))\n (incf total-dmc (* (aref cumul-d i)\n (- (aref cumul-c n) (aref cumul-c i))))))\n (labels ((calc (k)\n (let ((res 0))\n (declare (uint62 res))\n (dotimes (z n)\n (when (char= #\\C (aref s z))\n (incf res (aref cumul-dm (max 0 (+ 1 (- z k)))))\n (incf res (* (aref cumul-d (max 0 (+ 1 (- z k))))\n (- (aref cumul-m z)\n (aref cumul-m (max 0 (+ 1 (- z k)))))))))\n res)))\n (sb-int:dovector (k ks)\n (println (- total-dmc (calc k))))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nIn Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short.\n\nThe name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string.\n\nGiven a string S of length N and an integer k (k \\geq 3),\nhe defines the k-DMC number of S as the number of triples (a, b, c) of integers that satisfy the following conditions:\n\n0 \\leq a < b < c \\leq N - 1\n\nS[a] = D\n\nS[b] = M\n\nS[c] = C\n\nc-a < k\n\nHere S[a] is the a-th character of the string S. Indexing is zero-based, that is, 0 \\leq a \\leq N - 1 holds.\n\nFor a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC number of S for each i (0 \\leq i \\leq Q-1).\n\nConstraints\n\n3 \\leq N \\leq 10^6\n\nS consists of uppercase English letters\n\n1 \\leq Q \\leq 75\n\n3 \\leq k_i \\leq N\n\nAll numbers given in input are integers\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\nQ\nk_{0} k_{1} ... k_{Q-1}\n\nOutput\n\nPrint Q lines.\nThe i-th line should contain the k_i-DMC number of the string S.\n\nSample Input 1\n\n18\nDWANGOMEDIACLUSTER\n1\n18\n\nSample Output 1\n\n1\n\n(a,b,c) = (0, 6, 11) satisfies the conditions.\n\nStrangely, Dwango Media Cluster does not have so much DMC-ness by his definition.\n\nSample Input 2\n\n18\nDDDDDDMMMMMCCCCCCC\n1\n18\n\nSample Output 2\n\n210\n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\nSample Input 3\n\n54\nDIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n3\n20 30 40\n\nSample Output 3\n\n0\n1\n2\n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last one, namely, c-a < k_i.\n\nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming Operation\".\n\nSample Output 4\n\n30\nDMCDMCDMCDMCDMCDMCDMCDMCDMCDMC\n4\n5 10 15 20\n\nSample Output 4\n\n10\n52\n110\n140", "sample_input": "18\nDWANGOMEDIACLUSTER\n1\n18\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03216", "source_text": "Score : 600 points\n\nProblem Statement\n\nIn Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short.\n\nThe name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string.\n\nGiven a string S of length N and an integer k (k \\geq 3),\nhe defines the k-DMC number of S as the number of triples (a, b, c) of integers that satisfy the following conditions:\n\n0 \\leq a < b < c \\leq N - 1\n\nS[a] = D\n\nS[b] = M\n\nS[c] = C\n\nc-a < k\n\nHere S[a] is the a-th character of the string S. Indexing is zero-based, that is, 0 \\leq a \\leq N - 1 holds.\n\nFor a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC number of S for each i (0 \\leq i \\leq Q-1).\n\nConstraints\n\n3 \\leq N \\leq 10^6\n\nS consists of uppercase English letters\n\n1 \\leq Q \\leq 75\n\n3 \\leq k_i \\leq N\n\nAll numbers given in input are integers\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\nQ\nk_{0} k_{1} ... k_{Q-1}\n\nOutput\n\nPrint Q lines.\nThe i-th line should contain the k_i-DMC number of the string S.\n\nSample Input 1\n\n18\nDWANGOMEDIACLUSTER\n1\n18\n\nSample Output 1\n\n1\n\n(a,b,c) = (0, 6, 11) satisfies the conditions.\n\nStrangely, Dwango Media Cluster does not have so much DMC-ness by his definition.\n\nSample Input 2\n\n18\nDDDDDDMMMMMCCCCCCC\n1\n18\n\nSample Output 2\n\n210\n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\nSample Input 3\n\n54\nDIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n3\n20 30 40\n\nSample Output 3\n\n0\n1\n2\n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last one, namely, c-a < k_i.\n\nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming Operation\".\n\nSample Output 4\n\n30\nDMCDMCDMCDMCDMCDMCDMCDMCDMCDMC\n4\n5 10 15 20\n\nSample Output 4\n\n10\n52\n110\n140", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4124, "cpu_time_ms": 707, "memory_kb": 47720}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s042736893", "group_id": "codeNet:p03219", "input_text": "(princ(+(read)(/(read)2)))", "language": "Lisp", "metadata": {"date": 1541393106, "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/s042736893.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s042736893", "user_id": "u994767958"}, "prompt_components": {"gold_output": "110\n", "input_to_evaluate": "(princ(+(read)(/(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 20, "memory_kb": 3816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s919470881", "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 (push (cons (read) (read)) lst))\n (setq lst (cdr (reverse lst)))\n (dotimes (x *N*)\n (setq lst (shape-ans (1+ x) lst)))\n (dolist (v lst)\n (when (= 0 (car v))\n (format t \"~A~%\" (cdr v))))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1541793388, "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/s919470881.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s919470881", "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 (push (cons (read) (read)) lst))\n (setq lst (cdr (reverse lst)))\n (dotimes (x *N*)\n (setq lst (shape-ans (1+ x) lst)))\n (dolist (v lst)\n (when (= 0 (car v))\n (format t \"~A~%\" (cdr v))))))\n\n(main)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 98704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s986131816", "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 (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 (princ (cdr result))))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1541788626, "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/s986131816.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s986131816", "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 (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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1062, "cpu_time_ms": 2106, "memory_kb": 98656}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s015426587", "group_id": "codeNet:p03238", "input_text": "(defparameter *n* (read))\n(when (= *n* 2)\n (defparameter *a* (read))\n (defparameter *b* (read)))\n(when (= *n* 1)\n (defparameter *a* nil)\n (defparameter *b* nil))\n\n(defun f (n a b)\n (if (= n 1)\n \"Hello World\"\n (+ a b)))\n\n(princ (f *n* *a* *b*))", "language": "Lisp", "metadata": {"date": 1538874527, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03238.html", "problem_id": "p03238", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03238/input.txt", "sample_output_relpath": "derived/input_output/data/p03238/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03238/Lisp/s015426587.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s015426587", "user_id": "u956039157"}, "prompt_components": {"gold_output": "Hello World\n", "input_to_evaluate": "(defparameter *n* (read))\n(when (= *n* 2)\n (defparameter *a* (read))\n (defparameter *b* (read)))\n(when (= *n* 1)\n (defparameter *a* nil)\n (defparameter *b* nil))\n\n(defun f (n a b)\n (if (= n 1)\n \"Hello World\"\n (+ a b)))\n\n(princ (f *n* *a* *b*))", "problem_context": "Score: 100 points\n\nProblem Statement\n\nIn 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.\n\nOne day, there was an exam where a one-year-old child must write a program that prints Hello World, and a two-year-old child must write a program that receives integers A, B and prints A+B.\n\nTakahashi, who is taking this exam, suddenly forgets his age.\n\nHe decides to write a program that first receives his age N (1 or 2) as input, then prints Hello World if N=1, and additionally receives integers A, B and prints A+B if N=2.\n\nWrite this program for him.\n\nConstraints\n\nN is 1 or 2.\n\nA is an integer between 1 and 9 (inclusive).\n\nB is an integer between 1 and 9 (inclusive).\n\nInput\n\nInput is given from Standard Input in one of the following formats:\n\n1\n\n2\nA\nB\n\nOutput\n\nIf N=1, print Hello World; if N=2, print A+B.\n\nSample Input 1\n\n1\n\nSample Output 1\n\nHello World\n\nAs N=1, Takahashi is one year old. Thus, we should print Hello World.\n\nSample Input 2\n\n2\n3\n5\n\nSample Output 2\n\n8\n\nAs N=2, Takahashi is two years old. Thus, we should print A+B, which is 8 since A=3 and B=5.", "sample_input": "1\n"}, "reference_outputs": ["Hello World\n"], "source_document_id": "p03238", "source_text": "Score: 100 points\n\nProblem Statement\n\nIn 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.\n\nOne day, there was an exam where a one-year-old child must write a program that prints Hello World, and a two-year-old child must write a program that receives integers A, B and prints A+B.\n\nTakahashi, who is taking this exam, suddenly forgets his age.\n\nHe decides to write a program that first receives his age N (1 or 2) as input, then prints Hello World if N=1, and additionally receives integers A, B and prints A+B if N=2.\n\nWrite this program for him.\n\nConstraints\n\nN is 1 or 2.\n\nA is an integer between 1 and 9 (inclusive).\n\nB is an integer between 1 and 9 (inclusive).\n\nInput\n\nInput is given from Standard Input in one of the following formats:\n\n1\n\n2\nA\nB\n\nOutput\n\nIf N=1, print Hello World; if N=2, print A+B.\n\nSample Input 1\n\n1\n\nSample Output 1\n\nHello World\n\nAs N=1, Takahashi is one year old. Thus, we should print Hello World.\n\nSample Input 2\n\n2\n3\n5\n\nSample Output 2\n\n8\n\nAs N=2, Takahashi is two years old. Thus, we should print A+B, which is 8 since A=3 and B=5.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 93, "memory_kb": 9952}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s975372229", "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 (print n)\n (print ans)\n (print tmax)\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": 1573585281, "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/s975372229.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s975372229", "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 (print n)\n (print ans)\n (print tmax)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 339, "cpu_time_ms": 12, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s490029527", "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 (print n)\n (print ans)\n (print tmax)\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": 1573585191, "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/s490029527.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s490029527", "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 (print n)\n (print ans)\n (print tmax)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 341, "cpu_time_ms": 191, "memory_kb": 19556}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s178324859", "group_id": "codeNet:p03239", "input_text": "(let ((n (read))\n (tmax (read))\n (ans 1000000000))\n (loop repeat n do\n (let ((cost (read))\n\t (time (read)))\n\t (when (and\n\t\t(<= time tmax)\n\t\t(< cost ans))\n\t (setq ans cost))))\n (print (if (<= ans 1000) ans 'TLE)))", "language": "Lisp", "metadata": {"date": 1573584522, "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/s178324859.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s178324859", "user_id": "u691380397"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((n (read))\n (tmax (read))\n (ans 1000000000))\n (loop repeat n do\n (let ((cost (read))\n\t (time (read)))\n\t (when (and\n\t\t(<= time tmax)\n\t\t(< cost ans))\n\t (setq ans cost))))\n (print (if (<= ans 1000) ans 'TLE)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 236, "cpu_time_ms": 142, "memory_kb": 13024}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s033745755", "group_id": "codeNet:p03242", "input_text": "(princ (- 1110 (read)))", "language": "Lisp", "metadata": {"date": 1590795027, "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/s033745755.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s033745755", "user_id": "u425762225"}, "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 22, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s563642654", "group_id": "codeNet:p03242", "input_text": "(princ (concatenate 'string (mapcar (lambda (n) (if (equal n #\\1)\n #\\9 #\\1)) (concatenate 'list (read-line)))))", "language": "Lisp", "metadata": {"date": 1538269794, "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/s563642654.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s563642654", "user_id": "u610490393"}, "prompt_components": {"gold_output": "991\n", "input_to_evaluate": "(princ (concatenate 'string (mapcar (lambda (n) (if (equal n #\\1)\n #\\9 #\\1)) (concatenate 'list (read-line)))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 195, "memory_kb": 8036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s829393421", "group_id": "codeNet:p03244", "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 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 (inline alist-to-hash-table))\n(defun alist-to-hash-table (alist &key (test #'eql))\n (let ((table (make-hash-table :test test)))\n (dolist (pair alist table)\n (setf (gethash (car pair) table) (cdr pair)))))\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 (let* ((n (read))\n (odd-freq-table (make-hash-table))\n (even-freq-table (make-hash-table)))\n (labels ((ensure-hash (obj table)\n (multiple-value-bind (num presentp) (gethash obj table)\n (if presentp\n (setf (gethash obj table) (+ num 1))\n (setf (gethash obj table) 1)))))\n (dotimes (i n)\n (let ((v (read-fixnum)))\n (if (evenp i)\n (ensure-hash v even-freq-table)\n (ensure-hash v odd-freq-table))))\n (let ((odd-freqs (hash-table-to-alist odd-freq-table))\n (even-freqs (hash-table-to-alist even-freq-table)))\n (setq odd-freqs (sort odd-freqs #'> :key #'cdr)\n even-freqs (sort even-freqs #'> :key #'cdr))\n (println\n (if (= (car (first odd-freqs)) (car (first even-freqs)))\n (cond ((and (second odd-freqs) (second even-freqs))\n (min (- n (cdr (second even-freqs)) (cdr (first odd-freqs)))\n (- n (cdr (first even-freqs)) (cdr (second odd-freqs)))))\n ((second even-freqs)\n (- n (cdr (second even-freqs)) (cdr (first odd-freqs))))\n ((second odd-freqs)\n (- n (cdr (first even-freqs)) (cdr (second odd-freqs))))\n (t\n (min (- n (cdr (first even-freqs)))\n (- n (cdr (first odd-freqs))))))\n (- n (cdr (first even-freqs)) (cdr (first odd-freqs)))))))))\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 \"4\n3 1 3 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n105 119 105 119 105 119\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 1 1 1\n\"\n \"2\n\")))\n", "language": "Lisp", "metadata": {"date": 1578188294, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03244.html", "problem_id": "p03244", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03244/input.txt", "sample_output_relpath": "derived/input_output/data/p03244/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03244/Lisp/s829393421.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s829393421", "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 (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 (inline alist-to-hash-table))\n(defun alist-to-hash-table (alist &key (test #'eql))\n (let ((table (make-hash-table :test test)))\n (dolist (pair alist table)\n (setf (gethash (car pair) table) (cdr pair)))))\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 (let* ((n (read))\n (odd-freq-table (make-hash-table))\n (even-freq-table (make-hash-table)))\n (labels ((ensure-hash (obj table)\n (multiple-value-bind (num presentp) (gethash obj table)\n (if presentp\n (setf (gethash obj table) (+ num 1))\n (setf (gethash obj table) 1)))))\n (dotimes (i n)\n (let ((v (read-fixnum)))\n (if (evenp i)\n (ensure-hash v even-freq-table)\n (ensure-hash v odd-freq-table))))\n (let ((odd-freqs (hash-table-to-alist odd-freq-table))\n (even-freqs (hash-table-to-alist even-freq-table)))\n (setq odd-freqs (sort odd-freqs #'> :key #'cdr)\n even-freqs (sort even-freqs #'> :key #'cdr))\n (println\n (if (= (car (first odd-freqs)) (car (first even-freqs)))\n (cond ((and (second odd-freqs) (second even-freqs))\n (min (- n (cdr (second even-freqs)) (cdr (first odd-freqs)))\n (- n (cdr (first even-freqs)) (cdr (second odd-freqs)))))\n ((second even-freqs)\n (- n (cdr (second even-freqs)) (cdr (first odd-freqs))))\n ((second odd-freqs)\n (- n (cdr (first even-freqs)) (cdr (second odd-freqs))))\n (t\n (min (- n (cdr (first even-freqs)))\n (- n (cdr (first odd-freqs))))))\n (- n (cdr (first even-freqs)) (cdr (first odd-freqs)))))))))\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 \"4\n3 1 3 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n105 119 105 119 105 119\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 1 1 1\n\"\n \"2\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nA sequence a_1,a_2,... ,a_n is said to be /\\/\\/\\/ when the following conditions are satisfied:\n\nFor each i = 1,2,..., n-2, a_i = a_{i+2}.\n\nExactly two different numbers appear in the sequence.\n\nYou are given a sequence v_1,v_2,...,v_n whose length is even.\nWe would like to make this sequence /\\/\\/\\/ by replacing some of its elements.\nFind the minimum number of elements that needs to be replaced.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\nn is even.\n\n1 \\leq v_i \\leq 10^5\n\nv_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\nv_1 v_2 ... v_n\n\nOutput\n\nPrint the minimum number of elements that needs to be replaced.\n\nSample Input 1\n\n4\n3 1 3 2\n\nSample Output 1\n\n1\n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.\n\nSample Input 2\n\n6\n105 119 105 119 105 119\n\nSample Output 2\n\n0\n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\nSample Input 3\n\n4\n1 1 1 1\n\nSample Output 3\n\n2\n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/.", "sample_input": "4\n3 1 3 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03244", "source_text": "Score : 300 points\n\nProblem Statement\n\nA sequence a_1,a_2,... ,a_n is said to be /\\/\\/\\/ when the following conditions are satisfied:\n\nFor each i = 1,2,..., n-2, a_i = a_{i+2}.\n\nExactly two different numbers appear in the sequence.\n\nYou are given a sequence v_1,v_2,...,v_n whose length is even.\nWe would like to make this sequence /\\/\\/\\/ by replacing some of its elements.\nFind the minimum number of elements that needs to be replaced.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\nn is even.\n\n1 \\leq v_i \\leq 10^5\n\nv_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\nv_1 v_2 ... v_n\n\nOutput\n\nPrint the minimum number of elements that needs to be replaced.\n\nSample Input 1\n\n4\n3 1 3 2\n\nSample Output 1\n\n1\n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.\n\nSample Input 2\n\n6\n105 119 105 119 105 119\n\nSample Output 2\n\n0\n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\nSample Input 3\n\n4\n1 1 1 1\n\nSample Output 3\n\n2\n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7152, "cpu_time_ms": 117, "memory_kb": 41448}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s950448576", "group_id": "codeNet:p03244", "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 \"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 (odd-freq-table (make-hash-table))\n (even-freq-table (make-hash-table)))\n (labels ((ensure-hash (obj table)\n (multiple-value-bind (num presentp) (gethash obj table)\n (if presentp\n (setf (gethash obj table) (+ num 1))\n (setf (gethash obj table) 1)))))\n (dotimes (i n)\n (let ((v (read-fixnum)))\n (if (evenp i)\n (ensure-hash v even-freq-table)\n (ensure-hash v odd-freq-table))))\n (let ((odd-freqs (sb-int:%hash-table-alist odd-freq-table))\n (even-freqs (sb-int:%hash-table-alist even-freq-table)))\n (setq odd-freqs (sort odd-freqs #'> :key #'cdr)\n even-freqs (sort even-freqs #'> :key #'cdr))\n (println\n (if (= (car (first odd-freqs)) (car (first even-freqs)))\n (cond ((and (second odd-freqs) (second even-freqs))\n (min (- n (cdr (second even-freqs)) (cdr (first odd-freqs)))\n (- n (cdr (first even-freqs)) (cdr (second odd-freqs)))))\n ((second even-freqs)\n (- n (cdr (second even-freqs)) (cdr (first odd-freqs))))\n ((second odd-freqs)\n (- n (cdr (first even-freqs)) (cdr (second odd-freqs))))\n (t\n (min (- n (cdr (first even-freqs)))\n (- n (cdr (first odd-freqs))))))\n (- n (cdr (first even-freqs)) (cdr (first odd-freqs)))))))))\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 \"4\n3 1 3 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n105 119 105 119 105 119\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 1 1 1\n\"\n \"2\n\")))\n", "language": "Lisp", "metadata": {"date": 1578188215, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03244.html", "problem_id": "p03244", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03244/input.txt", "sample_output_relpath": "derived/input_output/data/p03244/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03244/Lisp/s950448576.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s950448576", "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 \"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 (odd-freq-table (make-hash-table))\n (even-freq-table (make-hash-table)))\n (labels ((ensure-hash (obj table)\n (multiple-value-bind (num presentp) (gethash obj table)\n (if presentp\n (setf (gethash obj table) (+ num 1))\n (setf (gethash obj table) 1)))))\n (dotimes (i n)\n (let ((v (read-fixnum)))\n (if (evenp i)\n (ensure-hash v even-freq-table)\n (ensure-hash v odd-freq-table))))\n (let ((odd-freqs (sb-int:%hash-table-alist odd-freq-table))\n (even-freqs (sb-int:%hash-table-alist even-freq-table)))\n (setq odd-freqs (sort odd-freqs #'> :key #'cdr)\n even-freqs (sort even-freqs #'> :key #'cdr))\n (println\n (if (= (car (first odd-freqs)) (car (first even-freqs)))\n (cond ((and (second odd-freqs) (second even-freqs))\n (min (- n (cdr (second even-freqs)) (cdr (first odd-freqs)))\n (- n (cdr (first even-freqs)) (cdr (second odd-freqs)))))\n ((second even-freqs)\n (- n (cdr (second even-freqs)) (cdr (first odd-freqs))))\n ((second odd-freqs)\n (- n (cdr (first even-freqs)) (cdr (second odd-freqs))))\n (t\n (min (- n (cdr (first even-freqs)))\n (- n (cdr (first odd-freqs))))))\n (- n (cdr (first even-freqs)) (cdr (first odd-freqs)))))))))\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 \"4\n3 1 3 2\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n105 119 105 119 105 119\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4\n1 1 1 1\n\"\n \"2\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nA sequence a_1,a_2,... ,a_n is said to be /\\/\\/\\/ when the following conditions are satisfied:\n\nFor each i = 1,2,..., n-2, a_i = a_{i+2}.\n\nExactly two different numbers appear in the sequence.\n\nYou are given a sequence v_1,v_2,...,v_n whose length is even.\nWe would like to make this sequence /\\/\\/\\/ by replacing some of its elements.\nFind the minimum number of elements that needs to be replaced.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\nn is even.\n\n1 \\leq v_i \\leq 10^5\n\nv_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\nv_1 v_2 ... v_n\n\nOutput\n\nPrint the minimum number of elements that needs to be replaced.\n\nSample Input 1\n\n4\n3 1 3 2\n\nSample Output 1\n\n1\n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.\n\nSample Input 2\n\n6\n105 119 105 119 105 119\n\nSample Output 2\n\n0\n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\nSample Input 3\n\n4\n1 1 1 1\n\nSample Output 3\n\n2\n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/.", "sample_input": "4\n3 1 3 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03244", "source_text": "Score : 300 points\n\nProblem Statement\n\nA sequence a_1,a_2,... ,a_n is said to be /\\/\\/\\/ when the following conditions are satisfied:\n\nFor each i = 1,2,..., n-2, a_i = a_{i+2}.\n\nExactly two different numbers appear in the sequence.\n\nYou are given a sequence v_1,v_2,...,v_n whose length is even.\nWe would like to make this sequence /\\/\\/\\/ by replacing some of its elements.\nFind the minimum number of elements that needs to be replaced.\n\nConstraints\n\n2 \\leq n \\leq 10^5\n\nn is even.\n\n1 \\leq v_i \\leq 10^5\n\nv_i is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nn\nv_1 v_2 ... v_n\n\nOutput\n\nPrint the minimum number of elements that needs to be replaced.\n\nSample Input 1\n\n4\n3 1 3 2\n\nSample Output 1\n\n1\n\nThe sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.\n\nSample Input 2\n\n6\n105 119 105 119 105 119\n\nSample Output 2\n\n0\n\nThe sequence 105,119,105,119,105,119 is /\\/\\/\\/.\n\nSample Input 3\n\n4\n1 1 1 1\n\nSample Output 3\n\n2\n\nThe elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6479, "cpu_time_ms": 202, "memory_kb": 23392}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s178277623", "group_id": "codeNet:p03252", "input_text": "(defparameter *char-list*\n (loop for i below 26 collect (code-char (+ (char-code #\\a)\n i))))\n(defun lst-equal-p (xs ys)\n (if (null xs)\n t\n (if (equal (first xs) (first ys))\n (lst-equal-p (rest xs)\n (rest ys))\n nil)))\n\n(defun make-pos-list (lst chr &optional (acc nil) (cnt 0))\n (if (null lst)\n (reverse acc)\n (progn\n (when (char-equal (first lst) chr)\n (push cnt acc))\n (make-pos-list (rest lst) chr acc (1+ cnt)))))\n\n(defun solve (s1 s2)\n (let ((p1 (sort (remove-if #'null\n (mapcar (lambda (c) (make-pos-list s1 c))\n *char-list*))\n (lambda (xs ys) (< (first xs) (first ys)))))\n (p2 (sort (remove-if #'null\n (mapcar (lambda (c) (make-pos-list s2 c))\n *char-list*))\n (lambda (xs ys) (< (first xs) (first ys))))))\n (if (/= (length p1) (length p2))\n \"No\")\n (if (lst-equal-p p1 p2)\n \"Yes\"\n \"No\")))\n\n(defun main ()\n (let ((str1 (concatenate 'list (read-line)))\n (str2 (concatenate 'list (read-line))))\n (format t \"~a~%\" (solve str1 str2))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1598585930, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s178277623.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s178277623", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defparameter *char-list*\n (loop for i below 26 collect (code-char (+ (char-code #\\a)\n i))))\n(defun lst-equal-p (xs ys)\n (if (null xs)\n t\n (if (equal (first xs) (first ys))\n (lst-equal-p (rest xs)\n (rest ys))\n nil)))\n\n(defun make-pos-list (lst chr &optional (acc nil) (cnt 0))\n (if (null lst)\n (reverse acc)\n (progn\n (when (char-equal (first lst) chr)\n (push cnt acc))\n (make-pos-list (rest lst) chr acc (1+ cnt)))))\n\n(defun solve (s1 s2)\n (let ((p1 (sort (remove-if #'null\n (mapcar (lambda (c) (make-pos-list s1 c))\n *char-list*))\n (lambda (xs ys) (< (first xs) (first ys)))))\n (p2 (sort (remove-if #'null\n (mapcar (lambda (c) (make-pos-list s2 c))\n *char-list*))\n (lambda (xs ys) (< (first xs) (first ys))))))\n (if (/= (length p1) (length p2))\n \"No\")\n (if (lst-equal-p p1 p2)\n \"Yes\"\n \"No\")))\n\n(defun main ()\n (let ((str1 (concatenate 'list (read-line)))\n (str2 (concatenate 'list (read-line))))\n (format t \"~a~%\" (solve str1 str2))))\n\n(main)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1282, "cpu_time_ms": 158, "memory_kb": 47628}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s457231903", "group_id": "codeNet:p03252", "input_text": "(defun collector (function lst)\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(if (equal (mapcar #'cdr (collector #'char= (sort (concatenate 'list (read-line)) #'char<)))\n (mapcar #'cdr (collector #'char= (sort (concatenate 'list (read-line)) #'char<))))\n (princ \"Yes\")\n (princ \"No\"))\n", "language": "Lisp", "metadata": {"date": 1575662115, "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/s457231903.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s457231903", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun collector (function lst)\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(if (equal (mapcar #'cdr (collector #'char= (sort (concatenate 'list (read-line)) #'char<)))\n (mapcar #'cdr (collector #'char= (sort (concatenate 'list (read-line)) #'char<))))\n (princ \"Yes\")\n (princ \"No\"))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 186, "memory_kb": 22760}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s276607569", "group_id": "codeNet:p03252", "input_text": "(defun solve (s1 s2)\n (let ((h1 (make-hash-table))\n (h2 (make-hash-table))\n (len (length s1)))\n (dotimes (i len)\n (let ((c1 (char s1 i))\n (c2 (char s2 i)))\n (when (or (and (gethash c1 h1) (not (eq c2 (gethash c1 h1))))\n (and (gethash c2 h2) (not (eq c1 (gethash c2 h2)))))\n (return-from solve \"No\"))\n (setf (gethash c1 h1) c2)\n (setf (gethash c2 h2) c1)))\n \"Yes\"))\n(format t \"~A~%\" (solve (read-line) (read-line)))", "language": "Lisp", "metadata": {"date": 1573708910, "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/s276607569.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s276607569", "user_id": "u672956630"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun solve (s1 s2)\n (let ((h1 (make-hash-table))\n (h2 (make-hash-table))\n (len (length s1)))\n (dotimes (i len)\n (let ((c1 (char s1 i))\n (c2 (char s2 i)))\n (when (or (and (gethash c1 h1) (not (eq c2 (gethash c1 h1))))\n (and (gethash c2 h2) (not (eq c1 (gethash c2 h2)))))\n (return-from solve \"No\"))\n (setf (gethash c1 h1) c2)\n (setf (gethash c2 h2) c1)))\n \"Yes\"))\n(format t \"~A~%\" (solve (read-line) (read-line)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 498, "cpu_time_ms": 255, "memory_kb": 19552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s196189232", "group_id": "codeNet:p03253", "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 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 #'first args) ,@body))\n (,name ,@(mapcar #'second 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 #.OPT)\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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" 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;; Based on alexandria\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(defun binomial-coefficient (n k)\n (declare ((integer 0 (#.most-positive-fixnum)) n k))\n (assert (>= n k))\n (mod (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 +magic+))\n\n(defun multiset-coefficient (n k)\n (binomial-coefficient (+ n k -1) k))\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": 1546591630, "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/s196189232.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s196189232", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\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 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 #'first args) ,@body))\n (,name ,@(mapcar #'second 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 #.OPT)\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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" 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;; Based on alexandria\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(defun binomial-coefficient (n k)\n (declare ((integer 0 (#.most-positive-fixnum)) n k))\n (assert (>= n k))\n (mod (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 +magic+))\n\n(defun multiset-coefficient (n k)\n (binomial-coefficient (+ n k -1) k))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4234, "cpu_time_ms": 247, "memory_kb": 26976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s845936708", "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 (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": 1546580755, "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/s845936708.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s845936708", "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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8407, "cpu_time_ms": 315, "memory_kb": 63032}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s848026703", "group_id": "codeNet:p03253", "input_text": "(defmacro defmemo (name args &body exprs)\n \"Define memoized function with referential transparency.\"\n (let ((fn (gensym))\n (memo (gensym)))\n `(labels ((,fn ,args ,@exprs))\n (let ((,memo (make-hash-table :test #'equal)))\n (defun ,name ,args\n (or (gethash (list ,@args) ,memo)\n (setf (gethash (list ,@args) ,memo) (apply (function ,fn) (list ,@args)))))))))\n\n(defparameter *n* (read))\n(defparameter *m* (read))\n\n(defun f (m)\n (labels ((f1 (m div lst)\n (let ((x (/ m div)))\n (cond ((= x 1) (cons div lst))\n ((integerp x) (f1 x div (cons div lst)))\n ((< m (* div div)) (cons m lst))\n ((oddp div) (f1 m (+ div 2) lst))\n (t (f1 m (1+ div) lst))))))\n (f1 m 2 nil)))\n\n(defun combination (n r)\n (if (zerop r)\n 1\n (* (/ n r)\n (combination (1- n) (1- r)))))\n\n(defun g (lst)\n (mapcar (lambda (n) (count n lst)) (remove-duplicates lst)))\n\n(defun h (n lst)\n (apply #'* (mapcar (lambda (x)\n (combination (+ x (1- n)) x))\n lst)))\n\n(defun i (n m)\n (rem (h n (g (f m))) (+ 1000000000 7)))\n\n(princ (i *n* *m*))", "language": "Lisp", "metadata": {"date": 1537959698, "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/s848026703.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s848026703", "user_id": "u956039157"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(defmacro defmemo (name args &body exprs)\n \"Define memoized function with referential transparency.\"\n (let ((fn (gensym))\n (memo (gensym)))\n `(labels ((,fn ,args ,@exprs))\n (let ((,memo (make-hash-table :test #'equal)))\n (defun ,name ,args\n (or (gethash (list ,@args) ,memo)\n (setf (gethash (list ,@args) ,memo) (apply (function ,fn) (list ,@args)))))))))\n\n(defparameter *n* (read))\n(defparameter *m* (read))\n\n(defun f (m)\n (labels ((f1 (m div lst)\n (let ((x (/ m div)))\n (cond ((= x 1) (cons div lst))\n ((integerp x) (f1 x div (cons div lst)))\n ((< m (* div div)) (cons m lst))\n ((oddp div) (f1 m (+ div 2) lst))\n (t (f1 m (1+ div) lst))))))\n (f1 m 2 nil)))\n\n(defun combination (n r)\n (if (zerop r)\n 1\n (* (/ n r)\n (combination (1- n) (1- r)))))\n\n(defun g (lst)\n (mapcar (lambda (n) (count n lst)) (remove-duplicates lst)))\n\n(defun h (n lst)\n (apply #'* (mapcar (lambda (x)\n (combination (+ x (1- n)) x))\n lst)))\n\n(defun i (n m)\n (rem (h n (g (f m))) (+ 1000000000 7)))\n\n(princ (i *n* *m*))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1215, "cpu_time_ms": 23, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s797625785", "group_id": "codeNet:p03255", "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(defstruct (stair-sum (:constructor %make-stair-sum))\n (cumul nil :type (simple-array (unsigned-byte 62) (*)))\n (stair nil :type (simple-array (unsigned-byte 62) (*))))\n\n(declaim (inline make-stair-sum))\n(defun make-stair-sum (vector)\n \"Makes a table from VECTOR that stores 0, VECTOR[0], VECTOR[0] + 2*VECTOR[1],\nVECTOR[0] + 2*VECTOR[1] + 3*VECTOR[2], ...\"\n (let* ((n (length vector))\n (cumul (make-array (+ n 1) :element-type '(unsigned-byte 62) :initial-element 0))\n (stair (make-array (+ n 1) :element-type '(unsigned-byte 62) :initial-element 0)))\n (dotimes (i n)\n (setf (aref stair (+ i 1))\n (+ (aref stair i) (* (+ i 1) (aref vector i)))\n (aref cumul (+ i 1))\n (+ (aref cumul i) (aref vector i))))\n (%make-stair-sum :cumul cumul :stair stair)))\n\n(declaim (inline stair-sum-query))\n(defun stair-sum-query (stair-sum l r)\n \"Returns VECTOR[L] + 2*VECTOR[L+1] + 3*VECTOR[L+2] + ... + (R-L)*VECTOR[R-1].\"\n (symbol-macrolet ((stair (stair-sum-stair stair-sum))\n (cumul (stair-sum-cumul stair-sum)))\n (the uint62 (- (- (aref stair r)\n (aref stair l))\n (the uint62 (* l (- (aref cumul r)\n (aref cumul l))))))))\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 calc-distribution))\n(defun calc-distribution (total num)\n (declare (uint31 total num))\n (multiple-value-bind (smaller rem) (floor total num)\n (if (zerop rem)\n `((,smaller . ,num))\n (let ((larger-num (- total (* smaller num))))\n `((,(+ 1 smaller) . ,larger-num) .\n (,smaller . ,(- num larger-num)))))))\n\n(declaim (inline get-next))\n(defun get-next (distribution)\n (assert (cdr distribution))\n (let* ((node1 (car distribution))\n (node2 (cdr distribution))\n (num1 (cdr node1))\n (num2 (cdr node2)))\n (declare (uint31 num1 num2))\n (if (= num1 1)\n (rplacd node2 (+ num2 1))\n (cons (rplacd node1 (- num1 1)) (rplacd node2 (+ num2 1))))))\n\n(declaim (inline calc-coefficient))\n(defun calc-coefficient (distribution)\n (if (cdr distribution)\n (destructuring-bind ((size1 . num1) . (size2 . num2)) distribution\n (declare (uint31 size1 num1 size2 num2))\n (+ (the uint62 (* num1 (expt (+ size1 1) 2)))\n (the uint62 (* num2 (expt (+ size2 1) 2)))\n num1\n num2))\n (destructuring-bind ((size . num)) distribution\n (declare (uint31 size num))\n (+ (* num (expt (+ size 1) 2))\n num))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (x (read))\n (xs (make-array n :element-type 'uint31))\n (dxs (make-array n :element-type 'uint31))\n (cumul (make-array (+ n 1) :element-type 'uint31 :initial-element 0))\n (res #xffffffffffffffffff))\n (declare (uint31 n x))\n (dotimes (i n)\n (setf (aref xs i) (read-fixnum)\n (aref dxs i) (- (aref xs i) (if (zerop i) 0 (aref xs (- i 1))))\n (aref cumul (+ i 1)) (+ (aref cumul i) (aref dxs i))))\n (let ((stair-sum (make-stair-sum dxs)))\n (loop for k from 1 to n\n for cost-sum of-type unsigned-byte = 0\n for n/k of-type uint31 = (floor n k)\n do (when (> n (* k n/k))\n (let* ((end (- n (* k n/k)))\n (base-coef (calc-coefficient (calc-distribution n k)))\n (delta-coef (+ 1 (* 2 (+ n/k 1))))\n (cost (- (* base-coef\n (- (aref cumul end) (aref cumul 0)))\n (* delta-coef\n (stair-sum-query stair-sum 1 end)))))\n (declare (uint31 end delta-coef)\n (uint62 base-coef))\n (incf cost-sum cost)))\n do (loop for m from n/k above 0\n for base-index of-type uint31 = (- n (* k m))\n for size of-type uint31 = (floor (* m k) k)\n for base-coef of-type uint62 = (+ (* k (expt (+ size 1) 2)) k)\n for delta-coef of-type uint31 = (if (= 1 m) 5 (+ 1 (* 2 m)))\n for cost = (- (* base-coef\n (- (aref cumul (+ base-index k))\n (aref cumul base-index)))\n (* delta-coef\n (stair-sum-query stair-sum\n (+ base-index 1)\n (+ base-index k))))\n do (incf cost-sum cost))\n (setq res (min res (+ (* k x) cost-sum)))))\n ;; 拾うコストNXは最後に足す\n (println (+ res (* x 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 \"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 \"200000 1000000000~%\")\n (let ((xs (loop repeat 200000 collect (+ 1 (random #.(expt 10 9))))))\n (setq xs (sort xs #'<))\n (dolist (x xs)\n (println x out)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; 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 100\n1 10\n\"\n \"355\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 1\n1 999999997 999999998 999999999 1000000000\n\"\n \"19999999983\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 8851025\n38 87 668 3175 22601 65499 90236 790604 4290609 4894746\n\"\n \"150710136\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"16 10\n1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408\n\"\n \"3256017715\n\")))\n", "language": "Lisp", "metadata": {"date": 1580280067, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03255.html", "problem_id": "p03255", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03255/input.txt", "sample_output_relpath": "derived/input_output/data/p03255/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03255/Lisp/s797625785.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s797625785", "user_id": "u352600849"}, "prompt_components": {"gold_output": "355\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(defstruct (stair-sum (:constructor %make-stair-sum))\n (cumul nil :type (simple-array (unsigned-byte 62) (*)))\n (stair nil :type (simple-array (unsigned-byte 62) (*))))\n\n(declaim (inline make-stair-sum))\n(defun make-stair-sum (vector)\n \"Makes a table from VECTOR that stores 0, VECTOR[0], VECTOR[0] + 2*VECTOR[1],\nVECTOR[0] + 2*VECTOR[1] + 3*VECTOR[2], ...\"\n (let* ((n (length vector))\n (cumul (make-array (+ n 1) :element-type '(unsigned-byte 62) :initial-element 0))\n (stair (make-array (+ n 1) :element-type '(unsigned-byte 62) :initial-element 0)))\n (dotimes (i n)\n (setf (aref stair (+ i 1))\n (+ (aref stair i) (* (+ i 1) (aref vector i)))\n (aref cumul (+ i 1))\n (+ (aref cumul i) (aref vector i))))\n (%make-stair-sum :cumul cumul :stair stair)))\n\n(declaim (inline stair-sum-query))\n(defun stair-sum-query (stair-sum l r)\n \"Returns VECTOR[L] + 2*VECTOR[L+1] + 3*VECTOR[L+2] + ... + (R-L)*VECTOR[R-1].\"\n (symbol-macrolet ((stair (stair-sum-stair stair-sum))\n (cumul (stair-sum-cumul stair-sum)))\n (the uint62 (- (- (aref stair r)\n (aref stair l))\n (the uint62 (* l (- (aref cumul r)\n (aref cumul l))))))))\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 calc-distribution))\n(defun calc-distribution (total num)\n (declare (uint31 total num))\n (multiple-value-bind (smaller rem) (floor total num)\n (if (zerop rem)\n `((,smaller . ,num))\n (let ((larger-num (- total (* smaller num))))\n `((,(+ 1 smaller) . ,larger-num) .\n (,smaller . ,(- num larger-num)))))))\n\n(declaim (inline get-next))\n(defun get-next (distribution)\n (assert (cdr distribution))\n (let* ((node1 (car distribution))\n (node2 (cdr distribution))\n (num1 (cdr node1))\n (num2 (cdr node2)))\n (declare (uint31 num1 num2))\n (if (= num1 1)\n (rplacd node2 (+ num2 1))\n (cons (rplacd node1 (- num1 1)) (rplacd node2 (+ num2 1))))))\n\n(declaim (inline calc-coefficient))\n(defun calc-coefficient (distribution)\n (if (cdr distribution)\n (destructuring-bind ((size1 . num1) . (size2 . num2)) distribution\n (declare (uint31 size1 num1 size2 num2))\n (+ (the uint62 (* num1 (expt (+ size1 1) 2)))\n (the uint62 (* num2 (expt (+ size2 1) 2)))\n num1\n num2))\n (destructuring-bind ((size . num)) distribution\n (declare (uint31 size num))\n (+ (* num (expt (+ size 1) 2))\n num))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (x (read))\n (xs (make-array n :element-type 'uint31))\n (dxs (make-array n :element-type 'uint31))\n (cumul (make-array (+ n 1) :element-type 'uint31 :initial-element 0))\n (res #xffffffffffffffffff))\n (declare (uint31 n x))\n (dotimes (i n)\n (setf (aref xs i) (read-fixnum)\n (aref dxs i) (- (aref xs i) (if (zerop i) 0 (aref xs (- i 1))))\n (aref cumul (+ i 1)) (+ (aref cumul i) (aref dxs i))))\n (let ((stair-sum (make-stair-sum dxs)))\n (loop for k from 1 to n\n for cost-sum of-type unsigned-byte = 0\n for n/k of-type uint31 = (floor n k)\n do (when (> n (* k n/k))\n (let* ((end (- n (* k n/k)))\n (base-coef (calc-coefficient (calc-distribution n k)))\n (delta-coef (+ 1 (* 2 (+ n/k 1))))\n (cost (- (* base-coef\n (- (aref cumul end) (aref cumul 0)))\n (* delta-coef\n (stair-sum-query stair-sum 1 end)))))\n (declare (uint31 end delta-coef)\n (uint62 base-coef))\n (incf cost-sum cost)))\n do (loop for m from n/k above 0\n for base-index of-type uint31 = (- n (* k m))\n for size of-type uint31 = (floor (* m k) k)\n for base-coef of-type uint62 = (+ (* k (expt (+ size 1) 2)) k)\n for delta-coef of-type uint31 = (if (= 1 m) 5 (+ 1 (* 2 m)))\n for cost = (- (* base-coef\n (- (aref cumul (+ base-index k))\n (aref cumul base-index)))\n (* delta-coef\n (stair-sum-query stair-sum\n (+ base-index 1)\n (+ base-index k))))\n do (incf cost-sum cost))\n (setq res (min res (+ (* k x) cost-sum)))))\n ;; 拾うコストNXは最後に足す\n (println (+ res (* x 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 \"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 \"200000 1000000000~%\")\n (let ((xs (loop repeat 200000 collect (+ 1 (random #.(expt 10 9))))))\n (setq xs (sort xs #'<))\n (dolist (x xs)\n (println x out)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; 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 100\n1 10\n\"\n \"355\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 1\n1 999999997 999999998 999999999 1000000000\n\"\n \"19999999983\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 8851025\n38 87 668 3175 22601 65499 90236 790604 4290609 4894746\n\"\n \"150710136\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"16 10\n1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408\n\"\n \"3256017715\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nSnuke has decided to use a robot to clean his room.\n\nThere are N pieces of trash on a number line.\nThe i-th piece from the left is at position x_i.\nWe would like to put all of them in a trash bin at position 0.\n\nFor the positions of the pieces of trash, 0 < x_1 < x_2 < ... < x_{N} \\leq 10^{9} holds.\n\nThe robot is initially at position 0.\nIt can freely move left and right along the number line, pick up a piece of trash when it comes to the position of that piece, carry any number of pieces of trash and put them in the trash bin when it comes to position 0. It is not allowed to put pieces of trash anywhere except in the trash bin.\n\nThe robot consumes X points of energy when the robot picks up a piece of trash, or put pieces of trash in the trash bin. (Putting any number of pieces of trash in the trash bin consumes X points of energy.)\nAlso, the robot consumes (k+1)^{2} points of energy to travel by a distance of 1 when the robot is carrying k pieces of trash.\n\nFind the minimum amount of energy required to put all the N pieces of trash in the trash bin.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^{5}\n\n0 < x_1 < ... < x_N \\leq 10^9\n\n1 \\leq X \\leq 10^9\n\nAll values in input are integers.\n\nPartial Scores\n\n400 points will be awarded for passing the test set satisfying N \\leq 2000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nx_1 x_2 ... x_{N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2 100\n1 10\n\nSample Output 1\n\n355\n\nTravel to position 10 by consuming 10 points of energy.\n\nPick up the piece of trash by consuming 100 points of energy.\n\nTravel to position 1 by consuming 36 points of energy.\n\nPick up the piece of trash by consuming 100 points of energy.\n\nTravel to position 0 by consuming 9 points of energy.\n\nPut the two pieces of trash in the trash bin by consuming 100 points of energy.\n\nThis strategy consumes a total of 10+100+36+100+9+100=355 points of energy.\n\nSample Input 2\n\n5 1\n1 999999997 999999998 999999999 1000000000\n\nSample Output 2\n\n19999999983\n\nSample Input 3\n\n10 8851025\n38 87 668 3175 22601 65499 90236 790604 4290609 4894746\n\nSample Output 3\n\n150710136\n\nSample Input 4\n\n16 10\n1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408\n\nSample Output 4\n\n3256017715", "sample_input": "2 100\n1 10\n"}, "reference_outputs": ["355\n"], "source_document_id": "p03255", "source_text": "Score : 700 points\n\nProblem Statement\n\nSnuke has decided to use a robot to clean his room.\n\nThere are N pieces of trash on a number line.\nThe i-th piece from the left is at position x_i.\nWe would like to put all of them in a trash bin at position 0.\n\nFor the positions of the pieces of trash, 0 < x_1 < x_2 < ... < x_{N} \\leq 10^{9} holds.\n\nThe robot is initially at position 0.\nIt can freely move left and right along the number line, pick up a piece of trash when it comes to the position of that piece, carry any number of pieces of trash and put them in the trash bin when it comes to position 0. It is not allowed to put pieces of trash anywhere except in the trash bin.\n\nThe robot consumes X points of energy when the robot picks up a piece of trash, or put pieces of trash in the trash bin. (Putting any number of pieces of trash in the trash bin consumes X points of energy.)\nAlso, the robot consumes (k+1)^{2} points of energy to travel by a distance of 1 when the robot is carrying k pieces of trash.\n\nFind the minimum amount of energy required to put all the N pieces of trash in the trash bin.\n\nConstraints\n\n1 \\leq N \\leq 2 \\times 10^{5}\n\n0 < x_1 < ... < x_N \\leq 10^9\n\n1 \\leq X \\leq 10^9\n\nAll values in input are integers.\n\nPartial Scores\n\n400 points will be awarded for passing the test set satisfying N \\leq 2000.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN X\nx_1 x_2 ... x_{N}\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\n2 100\n1 10\n\nSample Output 1\n\n355\n\nTravel to position 10 by consuming 10 points of energy.\n\nPick up the piece of trash by consuming 100 points of energy.\n\nTravel to position 1 by consuming 36 points of energy.\n\nPick up the piece of trash by consuming 100 points of energy.\n\nTravel to position 0 by consuming 9 points of energy.\n\nPut the two pieces of trash in the trash bin by consuming 100 points of energy.\n\nThis strategy consumes a total of 10+100+36+100+9+100=355 points of energy.\n\nSample Input 2\n\n5 1\n1 999999997 999999998 999999999 1000000000\n\nSample Output 2\n\n19999999983\n\nSample Input 3\n\n10 8851025\n38 87 668 3175 22601 65499 90236 790604 4290609 4894746\n\nSample Output 3\n\n150710136\n\nSample Input 4\n\n16 10\n1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408\n\nSample Output 4\n\n3256017715", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 10174, "cpu_time_ms": 264, "memory_kb": 60004}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s413914608", "group_id": "codeNet:p03265", "input_text": "(defun turn90 (x1 x2 y1 y2)\n (list (+ y1 (- x2 y2)) (+ y2 (* -1 (- x1 y1)))))\n(defparameter *x1* (read))\n(defparameter *y1* (read))\n(defparameter *x2* (read))\n(defparameter *y2* (read))\n(format t \"~A ~A ~A ~A\" (car (turn90 *x1* *x2* *y1* *y2*)) (cdar (turn90 *x1* *x2* *y1* *y2*)) (car (turn90 *y1* *y2* (car (turn90 *x1* *x2* *y1* *y2*)) (cdar (turn90 *x1* *x2* *y1* *y2*)))) (car (turn90 *y1* *y2* (car (turn90 *x1* *x2* *y1* *y2*)) (cdar (turn90 *x1* *x2* *y1* *y2*)))))", "language": "Lisp", "metadata": {"date": 1535852787, "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/s413914608.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s413914608", "user_id": "u610490393"}, "prompt_components": {"gold_output": "-1 1 -1 0\n", "input_to_evaluate": "(defun turn90 (x1 x2 y1 y2)\n (list (+ y1 (- x2 y2)) (+ y2 (* -1 (- x1 y1)))))\n(defparameter *x1* (read))\n(defparameter *y1* (read))\n(defparameter *x2* (read))\n(defparameter *y2* (read))\n(format t \"~A ~A ~A ~A\" (car (turn90 *x1* *x2* *y1* *y2*)) (cdar (turn90 *x1* *x2* *y1* *y2*)) (car (turn90 *y1* *y2* (car (turn90 *x1* *x2* *y1* *y2*)) (cdar (turn90 *x1* *x2* *y1* *y2*)))) (car (turn90 *y1* *y2* (car (turn90 *x1* *x2* *y1* *y2*)) (cdar (turn90 *x1* *x2* *y1* *y2*)))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 474, "cpu_time_ms": 275, "memory_kb": 13032}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s157304344", "group_id": "codeNet:p03267", "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* ((l (read))\n (k (- (integer-length l) 1))\n (out (make-string-output-stream :element-type 'base-char))\n (n (+ k 1))\n (m 0))\n (declare (uint32 m l))\n (dotimes (i k)\n (format out \"~D ~D ~D~%\" (+ i 1) (+ i 2) 0)\n (format out \"~D ~D ~D~%\" (+ i 1) (+ i 2) (ash 1 i))\n (incf m 2))\n (loop for v from (- k 1) downto 0\n when (>= (- l (ash 1 v)) (ash 1 k))\n do (format out \"~D ~D ~D~%\" (+ v 1) n (- l (ash 1 v)))\n (decf l (ash 1 v))\n (incf m))\n (format t \"~D ~D~%\" n m)\n (write-string (get-output-stream-string out))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1564872415, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03267.html", "problem_id": "p03267", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03267/input.txt", "sample_output_relpath": "derived/input_output/data/p03267/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03267/Lisp/s157304344.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s157304344", "user_id": "u352600849"}, "prompt_components": {"gold_output": "8 10\n1 2 0\n2 3 0\n3 4 0\n1 5 0\n2 6 0\n3 7 0\n4 8 0\n5 6 1\n6 7 1\n7 8 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* ((l (read))\n (k (- (integer-length l) 1))\n (out (make-string-output-stream :element-type 'base-char))\n (n (+ k 1))\n (m 0))\n (declare (uint32 m l))\n (dotimes (i k)\n (format out \"~D ~D ~D~%\" (+ i 1) (+ i 2) 0)\n (format out \"~D ~D ~D~%\" (+ i 1) (+ i 2) (ash 1 i))\n (incf m 2))\n (loop for v from (- k 1) downto 0\n when (>= (- l (ash 1 v)) (ash 1 k))\n do (format out \"~D ~D ~D~%\" (+ v 1) n (- l (ash 1 v)))\n (decf l (ash 1 v))\n (incf m))\n (format t \"~D ~D~%\" n m)\n (write-string (get-output-stream-string out))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nYou are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists.\n\nThe number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N.\n\nThe number of edges, M, is at most 60. Each edge has an integer length between 0 and 10^6 (inclusive).\n\nEvery edge is directed from the vertex with the smaller ID to the vertex with the larger ID. That is, 1,2,...,N is one possible topological order of the vertices.\n\nThere are exactly L different paths from Vertex 1 to Vertex N. The lengths of these paths are all different, and they are integers between 0 and L-1.\n\nHere, the length of a path is the sum of the lengths of the edges contained in that path, and two paths are considered different when the sets of the edges contained in those paths are different.\n\nConstraints\n\n2 \\leq L \\leq 10^6\n\nL is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\n\nOutput\n\nIn the first line, print N and M, the number of the vertices and edges in your graph.\nIn the i-th of the following M lines, print three integers u_i,v_i and w_i, representing the starting vertex, the ending vertex and the length of the i-th edge.\nIf there are multiple solutions, any of them will be accepted.\n\nSample Input 1\n\n4\n\nSample Output 1\n\n8 10\n1 2 0\n2 3 0\n3 4 0\n1 5 0\n2 6 0\n3 7 0\n4 8 0\n5 6 1\n6 7 1\n7 8 1\n\nIn the graph represented by the sample output, there are four paths from Vertex 1 to N=8:\n\n1 → 2 → 3 → 4 → 8 with length 0\n\n1 → 2 → 3 → 7 → 8 with length 1\n\n1 → 2 → 6 → 7 → 8 with length 2\n\n1 → 5 → 6 → 7 → 8 with length 3\n\nThere are other possible solutions.\n\nSample Input 2\n\n5\n\nSample Output 2\n\n5 7\n1 2 0\n2 3 1\n3 4 0\n4 5 0\n2 4 0\n1 3 3\n3 5 1", "sample_input": "4\n"}, "reference_outputs": ["8 10\n1 2 0\n2 3 0\n3 4 0\n1 5 0\n2 6 0\n3 7 0\n4 8 0\n5 6 1\n6 7 1\n7 8 1\n"], "source_document_id": "p03267", "source_text": "Score : 700 points\n\nProblem Statement\n\nYou are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists.\n\nThe number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N.\n\nThe number of edges, M, is at most 60. Each edge has an integer length between 0 and 10^6 (inclusive).\n\nEvery edge is directed from the vertex with the smaller ID to the vertex with the larger ID. That is, 1,2,...,N is one possible topological order of the vertices.\n\nThere are exactly L different paths from Vertex 1 to Vertex N. The lengths of these paths are all different, and they are integers between 0 and L-1.\n\nHere, the length of a path is the sum of the lengths of the edges contained in that path, and two paths are considered different when the sets of the edges contained in those paths are different.\n\nConstraints\n\n2 \\leq L \\leq 10^6\n\nL is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nL\n\nOutput\n\nIn the first line, print N and M, the number of the vertices and edges in your graph.\nIn the i-th of the following M lines, print three integers u_i,v_i and w_i, representing the starting vertex, the ending vertex and the length of the i-th edge.\nIf there are multiple solutions, any of them will be accepted.\n\nSample Input 1\n\n4\n\nSample Output 1\n\n8 10\n1 2 0\n2 3 0\n3 4 0\n1 5 0\n2 6 0\n3 7 0\n4 8 0\n5 6 1\n6 7 1\n7 8 1\n\nIn the graph represented by the sample output, there are four paths from Vertex 1 to N=8:\n\n1 → 2 → 3 → 4 → 8 with length 0\n\n1 → 2 → 3 → 7 → 8 with length 1\n\n1 → 2 → 6 → 7 → 8 with length 2\n\n1 → 5 → 6 → 7 → 8 with length 3\n\nThere are other possible solutions.\n\nSample Input 2\n\n5\n\nSample Output 2\n\n5 7\n1 2 0\n2 3 1\n3 4 0\n4 5 0\n2 4 0\n1 3 3\n3 5 1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1924, "cpu_time_ms": 171, "memory_kb": 17888}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s702613711", "group_id": "codeNet:p03273", "input_text": "(defun leader ()\n (setf *gridmap* (loop :for n :from 1 :upto *var* collect(concatenate 'list (read-line)))))\n\n\n(defun compresser ()\n (setf *gridmap* (remove (loop :for f :from 1 :upto *hol* collect(coerce \".\" 'character)) *gridmap* :test #'equal))\n (defparameter *nth-comp* 0)\n (loop :for a :from 0 :upto (1- *hol*) do(comp-loop a)))\n\n\n(defun comp-loop (n)\n (format t \"縦~A.横~A~%\" *nth-comp* n)\n (if (equal (nth n (nth *nth-comp* *gridmap*)) (coerce \".\" 'character))\n (if (= *nth-comp* (length *gridmap*))\n (setf *gridmap* (mapcar (lambda (g)\n (remove-if #'(lambda (q) t) g :start n :end (1+ n))) *gridmap*))\n (progn (setq *nth-comp* (1+ *nth-comp*))\n (comp-loop n)))\n (setq *nth-comp* 0)))\n\n\n(defun main ()\n (defparameter *gridmap* nil)\n (defparameter *var* (read))\n (defparameter *hol* (read))\n (leader)\n (compresser)\n ;(mapcar (lambda (n) (format t \"~A~%\" (concatenate 'string n))) *gridmap*)\n *gridmap*\n )\n\n\n(mapcar (lambda (n) (format t \"~A~%\" (concatenate 'string n))) (main))\n", "language": "Lisp", "metadata": {"date": 1535492301, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03273.html", "problem_id": "p03273", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03273/input.txt", "sample_output_relpath": "derived/input_output/data/p03273/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03273/Lisp/s702613711.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s702613711", "user_id": "u610490393"}, "prompt_components": {"gold_output": "###\n###\n.##\n", "input_to_evaluate": "(defun leader ()\n (setf *gridmap* (loop :for n :from 1 :upto *var* collect(concatenate 'list (read-line)))))\n\n\n(defun compresser ()\n (setf *gridmap* (remove (loop :for f :from 1 :upto *hol* collect(coerce \".\" 'character)) *gridmap* :test #'equal))\n (defparameter *nth-comp* 0)\n (loop :for a :from 0 :upto (1- *hol*) do(comp-loop a)))\n\n\n(defun comp-loop (n)\n (format t \"縦~A.横~A~%\" *nth-comp* n)\n (if (equal (nth n (nth *nth-comp* *gridmap*)) (coerce \".\" 'character))\n (if (= *nth-comp* (length *gridmap*))\n (setf *gridmap* (mapcar (lambda (g)\n (remove-if #'(lambda (q) t) g :start n :end (1+ n))) *gridmap*))\n (progn (setq *nth-comp* (1+ *nth-comp*))\n (comp-loop n)))\n (setq *nth-comp* 0)))\n\n\n(defun main ()\n (defparameter *gridmap* nil)\n (defparameter *var* (read))\n (defparameter *hol* (read))\n (leader)\n (compresser)\n ;(mapcar (lambda (n) (format t \"~A~%\" (concatenate 'string n))) *gridmap*)\n *gridmap*\n )\n\n\n(mapcar (lambda (n) (format t \"~A~%\" (concatenate 'string n))) (main))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere is a grid of squares with H horizontal rows and W vertical columns.\nThe square at the i-th row from the top and the j-th column from the left is represented as (i, j).\nEach square is black or white.\nThe color of the square is given as an H-by-W matrix (a_{i, j}).\nIf a_{i, j} is ., the square (i, j) is white; if a_{i, j} is #, the square (i, j) is black.\n\nSnuke is compressing this grid.\nHe will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:\n\nOperation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.\n\nIt can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.\nFind the final state of the grid.\n\nConstraints\n\n1 \\leq H, W \\leq 100\n\na_{i, j} is . or #.\n\nThere is at least one black square in the whole grid.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{1, 1}...a_{1, W}\n:\na_{H, 1}...a_{H, W}\n\nOutput\n\nPrint the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.\n\nSample Input 1\n\n4 4\n##.#\n....\n##.#\n.#.#\n\nSample Output 1\n\n###\n###\n.##\n\nThe second row and the third column in the original grid will be removed.\n\nSample Input 2\n\n3 3\n#..\n.#.\n..#\n\nSample Output 2\n\n#..\n.#.\n..#\n\nAs there is no row or column that consists only of white squares, no operation will be performed.\n\nSample Input 3\n\n4 5\n.....\n.....\n..#..\n.....\n\nSample Output 3\n\n#\n\nSample Input 4\n\n7 6\n......\n....#.\n.#....\n..#...\n..#...\n......\n.#..#.\n\nSample Output 4\n\n..#\n#..\n.#.\n.#.\n#.#", "sample_input": "4 4\n##.#\n....\n##.#\n.#.#\n"}, "reference_outputs": ["###\n###\n.##\n"], "source_document_id": "p03273", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere is a grid of squares with H horizontal rows and W vertical columns.\nThe square at the i-th row from the top and the j-th column from the left is represented as (i, j).\nEach square is black or white.\nThe color of the square is given as an H-by-W matrix (a_{i, j}).\nIf a_{i, j} is ., the square (i, j) is white; if a_{i, j} is #, the square (i, j) is black.\n\nSnuke is compressing this grid.\nHe will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:\n\nOperation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.\n\nIt can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.\nFind the final state of the grid.\n\nConstraints\n\n1 \\leq H, W \\leq 100\n\na_{i, j} is . or #.\n\nThere is at least one black square in the whole grid.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nH W\na_{1, 1}...a_{1, W}\n:\na_{H, 1}...a_{H, W}\n\nOutput\n\nPrint the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.\n\nSample Input 1\n\n4 4\n##.#\n....\n##.#\n.#.#\n\nSample Output 1\n\n###\n###\n.##\n\nThe second row and the third column in the original grid will be removed.\n\nSample Input 2\n\n3 3\n#..\n.#.\n..#\n\nSample Output 2\n\n#..\n.#.\n..#\n\nAs there is no row or column that consists only of white squares, no operation will be performed.\n\nSample Input 3\n\n4 5\n.....\n.....\n..#..\n.....\n\nSample Output 3\n\n#\n\nSample Input 4\n\n7 6\n......\n....#.\n.#....\n..#...\n..#...\n......\n.#..#.\n\nSample Output 4\n\n..#\n#..\n.#.\n.#.\n#.#", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1094, "cpu_time_ms": 162, "memory_kb": 16228}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s408173318", "group_id": "codeNet:p03274", "input_text": ";;; body\n\n(defun solve (n k x)\n (flet ((calc-dist (i-left i-right)\n (let ((left (aref x i-left))\n (right (aref x (1- i-right))))\n (min (+ (abs left) (abs (- right left)))\n (+ (abs right) (abs (- right left)))))))\n (if (= n 1)\n (abs (aref x 0))\n (reduce #'min \n (let ((acc nil))\n (loop with i = 0 while (<= (+ i k) n) do\n (push (calc-dist i\n (+ i k))\n acc)\n (incf i))\n acc)))))\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": 1599828859, "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/s408173318.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s408173318", "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 (let ((left (aref x i-left))\n (right (aref x (1- i-right))))\n (min (+ (abs left) (abs (- right left)))\n (+ (abs right) (abs (- right left)))))))\n (if (= n 1)\n (abs (aref x 0))\n (reduce #'min \n (let ((acc nil))\n (loop with i = 0 while (<= (+ i k) n) do\n (push (calc-dist i\n (+ i k))\n acc)\n (incf i))\n acc)))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 836, "cpu_time_ms": 148, "memory_kb": 78456}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s528421575", "group_id": "codeNet:p03274", "input_text": "(let* ((n (read))\n (m (read))\n (lst (loop :repeat n :collect (read)))\n (z (loop :for k :on lst\n :for j :from 0\n :if (cdr k)\n :if (<= (first k) 0 (second k))\n :return (if (= 0 (first k))\n (cons j j)\n (cons j (1+ j))) :end\n :else :return j)))\n (princ (loop :for k :from (- (car z) (1- m)) :upto (1+ (car z))\n :for j := (+ k m)\n :if (and (<= 0 k) (<= j n))\n :minimize (let* ((a (subseq lst k (1+ (car z))))\n (b (subseq lst (cdr z) j)))\n (min (+ (* 2 (abs (car a))) (car (last b)))\n (+ (abs (car a)) (* 2 (car (last b)))))))))", "language": "Lisp", "metadata": {"date": 1591697914, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s528421575.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s528421575", "user_id": "u610490393"}, "prompt_components": {"gold_output": "40\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst (loop :repeat n :collect (read)))\n (z (loop :for k :on lst\n :for j :from 0\n :if (cdr k)\n :if (<= (first k) 0 (second k))\n :return (if (= 0 (first k))\n (cons j j)\n (cons j (1+ j))) :end\n :else :return j)))\n (princ (loop :for k :from (- (car z) (1- m)) :upto (1+ (car z))\n :for j := (+ k m)\n :if (and (<= 0 k) (<= j n))\n :minimize (let* ((a (subseq lst k (1+ (car z))))\n (b (subseq lst (cdr z) j)))\n (min (+ (* 2 (abs (car a))) (car (last b)))\n (+ (abs (car a)) (* 2 (car (last b)))))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 822, "cpu_time_ms": 2106, "memory_kb": 74060}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s851565538", "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 (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 (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": 1560992851, "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/s851565538.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s851565538", "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 (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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9519, "cpu_time_ms": 266, "memory_kb": 57832}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s150897227", "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 get-median (l)\n (let* ((size (length l))\n (check (round (/ (float size) 2))))\n (nth check l)))\n\n(defun main ()\n (let ((s (read-line)))\n (let* ((l (split-string s #\\Space))\n (result (reverse l)))\n (dotimes (n *N*)\n (let ((right (+ n 1)))\n (if (/= right *N*)\n (progn\n (let* ((tmp (list (nth n l) (nth right l)))\n (sorted (sort tmp #'<)))\n (push (cadr sorted) result)))\n (push (get-median (sort l #'<)) result))))\n (setq result (sort (reverse result) #'<))\n (format t \"~A~%\" (get-median result)))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1535299358, "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/s150897227.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s150897227", "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 get-median (l)\n (let* ((size (length l))\n (check (round (/ (float size) 2))))\n (nth check l)))\n\n(defun main ()\n (let ((s (read-line)))\n (let* ((l (split-string s #\\Space))\n (result (reverse l)))\n (dotimes (n *N*)\n (let ((right (+ n 1)))\n (if (/= right *N*)\n (progn\n (let* ((tmp (list (nth n l) (nth right l)))\n (sorted (sort tmp #'<)))\n (push (cadr sorted) result)))\n (push (get-median (sort l #'<)) result))))\n (setq result (sort (reverse result) #'<))\n (format t \"~A~%\" (get-median result)))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1141, "cpu_time_ms": 2105, "memory_kb": 65888}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s931237284", "group_id": "codeNet:p03280", "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* ((a (read))\n (b (read)))\n (println (+ (* a b) (- a) (- b) 1))))\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 \"2 2\n\" nil)))\n (5am:is\n (equal \"24\n\"\n (run \"5 7\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600763203, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03280.html", "problem_id": "p03280", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03280/input.txt", "sample_output_relpath": "derived/input_output/data/p03280/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03280/Lisp/s931237284.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s931237284", "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;; BEGIN_USE_PACKAGE\n(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((a (read))\n (b (read)))\n (println (+ (* a b) (- a) (- b) 1))))\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 \"2 2\n\" nil)))\n (5am:is\n (equal \"24\n\"\n (run \"5 7\n\" nil))))\n", "problem_context": "Score: 100 points\n\nProblem Statement\n\nThere is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)\n\nWhat is the area of this yard excluding the roads? Find it.\n\nNote\n\nIt can be proved that the positions of the roads do not affect the area.\n\nConstraints\n\nA is an integer between 2 and 100 (inclusive).\n\nB is an integer between 2 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the area of this yard excluding the roads (in square yards).\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n1\n\nIn this case, the area is 1 square yard.\n\nSample Input 2\n\n5 7\n\nSample Output 2\n\n24\n\nIn this case, the area is 24 square yards.", "sample_input": "2 2\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03280", "source_text": "Score: 100 points\n\nProblem Statement\n\nThere is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)\n\nWhat is the area of this yard excluding the roads? Find it.\n\nNote\n\nIt can be proved that the positions of the roads do not affect the area.\n\nConstraints\n\nA is an integer between 2 and 100 (inclusive).\n\nB is an integer between 2 and 100 (inclusive).\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nPrint the area of this yard excluding the roads (in square yards).\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n1\n\nIn this case, the area is 1 square yard.\n\nSample Input 2\n\n5 7\n\nSample Output 2\n\n24\n\nIn this case, the area is 24 square yards.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3386, "cpu_time_ms": 17, "memory_kb": 24636}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s040217089", "group_id": "codeNet:p03281", "input_text": "(let ((n (read))\n (ans 0)\n (yakusu 0))\n\n (loop for i from 1 to n by 2 do\n (progn\n (setq yakusu 0)\n (loop for j from 1 while (<= (* j j) i) do\n (if (zerop (rem i j))\n (progn\n (incf yakusu)\n (if (not (= (* j j) i))\n (incf yakusu)\n )\n )\n )\n )\n (if (= yakusu 8)\n (incf ans)\n )\n )\n )\n (princ ans )\n)", "language": "Lisp", "metadata": {"date": 1594218185, "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/s040217089.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s040217089", "user_id": "u136500538"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((n (read))\n (ans 0)\n (yakusu 0))\n\n (loop for i from 1 to n by 2 do\n (progn\n (setq yakusu 0)\n (loop for j from 1 while (<= (* j j) i) do\n (if (zerop (rem i j))\n (progn\n (incf yakusu)\n (if (not (= (* j j) i))\n (incf yakusu)\n )\n )\n )\n )\n (if (= yakusu 8)\n (incf ans)\n )\n )\n )\n (princ ans )\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 19, "memory_kb": 24368}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s708114100", "group_id": "codeNet:p03281", "input_text": "(defparameter n (read))\n(defparameter target-list (loop for i from 1 to n by 2 collect i))\n\n(defun count-8 ()\n (count 8 (mapcar #'calc-divisor target-list)))\n\n(defun calc-divisor (num)\n (loop for i from 1 to num count (= 0 (mod num i))))\n\n(princ (count-8))", "language": "Lisp", "metadata": {"date": 1563833334, "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/s708114100.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s708114100", "user_id": "u480300350"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defparameter n (read))\n(defparameter target-list (loop for i from 1 to n by 2 collect i))\n\n(defun count-8 ()\n (count 8 (mapcar #'calc-divisor target-list)))\n\n(defun calc-divisor (num)\n (loop for i from 1 to num count (= 0 (mod num i))))\n\n(princ (count-8))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 142, "memory_kb": 13408}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s736666661", "group_id": "codeNet:p03282", "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 (str k)\n (if (every (lambda (x) (char= x #\\1)) (subseq str 0 (min (length str) k)))\n #\\1\n (loop for i across str\n when (null (char= i #\\1))\n do (return i))))\n\n(princ (main (read-string) (read)))\n", "language": "Lisp", "metadata": {"date": 1589146509, "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/s736666661.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s736666661", "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 (str k)\n (if (every (lambda (x) (char= x #\\1)) (subseq str 0 (min (length str) k)))\n #\\1\n (loop for i across str\n when (null (char= i #\\1))\n do (return i))))\n\n(princ (main (read-string) (read)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2848, "cpu_time_ms": 204, "memory_kb": 24380}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s309909729", "group_id": "codeNet:p03283", "input_text": "(defun checktrain (a)\n (count-if #'(lambda (n)\n (and (>= (car n) (car a)) (<= (cdr n) (cdr a)))) *train*))\n(defparameter *city* (read))\n(defparameter *n-train* (read))\n(defparameter *n-q* (read))\n(defparameter *train* (loop :for s :from 1 :upto *n-train* collect(cons (read) (read))))\n(defparameter *q* (loop :for l :from 1 :upto *n-q* collect(cons (read) (read))))\n(loop :for w :from 1 :upto *n-q* do(format t \"~A~%\" (checktrain (nth (1- w) *q*))))\n", "language": "Lisp", "metadata": {"date": 1535653872, "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/s309909729.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s309909729", "user_id": "u610490393"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun checktrain (a)\n (count-if #'(lambda (n)\n (and (>= (car n) (car a)) (<= (cdr n) (cdr a)))) *train*))\n(defparameter *city* (read))\n(defparameter *n-train* (read))\n(defparameter *n-q* (read))\n(defparameter *train* (loop :for s :from 1 :upto *n-train* collect(cons (read) (read))))\n(defparameter *q* (loop :for l :from 1 :upto *n-q* collect(cons (read) (read))))\n(loop :for w :from 1 :upto *n-q* do(format t \"~A~%\" (checktrain (nth (1- w) *q*))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 3157, "memory_kb": 68040}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s074205822", "group_id": "codeNet:p03284", "input_text": "(princ(if(>(mod(read)(read))0)1 0))", "language": "Lisp", "metadata": {"date": 1534044297, "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/s074205822.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s074205822", "user_id": "u657913472"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(princ(if(>(mod(read)(read))0)1 0))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 35, "cpu_time_ms": 21, "memory_kb": 3808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s284955710", "group_id": "codeNet:p03285", "input_text": "(let* ((n (read)) (max-q (nth-value 0 (floor n 7))) (flag 0))\n (dotimes (i (1+ max-q))\n (if (= (mod (- n (* i 7)) 4) 0)\n (progn (setq flag 1) (return))))\n (princ (if (= flag 1) \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1563343375, "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/s284955710.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s284955710", "user_id": "u480300350"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((n (read)) (max-q (nth-value 0 (floor n 7))) (flag 0))\n (dotimes (i (1+ max-q))\n (if (= (mod (- n (* i 7)) 4) 0)\n (progn (setq flag 1) (return))))\n (princ (if (= flag 1) \"Yes\" \"No\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 137, "memory_kb": 13544}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s457106080", "group_id": "codeNet:p03285", "input_text": "(defparameter yen (read))\n(defparameter stk (list 0))\n(defun lp ()\n (princ stk)\n (cond ((= (reduce #'+ stk) yen) (princ \"Yes\"))\n ((< (reduce #'+ stk) yen) (push 4 stk) (lp))\n ((= (first stk) 0) (princ \"No\"))\n ((= (pop stk) 4) (pop stk) (push 7 stk) (lp))\n (t (lp))))", "language": "Lisp", "metadata": {"date": 1539835481, "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/s457106080.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s457106080", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defparameter yen (read))\n(defparameter stk (list 0))\n(defun lp ()\n (princ stk)\n (cond ((= (reduce #'+ stk) yen) (princ \"Yes\"))\n ((< (reduce #'+ stk) yen) (push 4 stk) (lp))\n ((= (first stk) 0) (princ \"No\"))\n ((= (pop stk) 4) (pop stk) (push 7 stk) (lp))\n (t (lp))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 10, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s069991669", "group_id": "codeNet:p03285", "input_text": "(let ((a (read)))\n (if (or (= 0 (mod (mod a 7) 4)) (= 0 (mod a 7)))\n (princ \"Yes\")\n (princ \"No\")))\n", "language": "Lisp", "metadata": {"date": 1539295830, "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/s069991669.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s069991669", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((a (read)))\n (if (or (= 0 (mod (mod a 7) 4)) (= 0 (mod a 7)))\n (princ \"Yes\")\n (princ \"No\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 81, "memory_kb": 9188}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s942178622", "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": 1539295630, "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/s942178622.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s942178622", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 123, "memory_kb": 12132}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s326210432", "group_id": "codeNet:p03288", "input_text": "(setq x (read))\n(princ (if (< x 1200) \"ABC\" (if (< x 2800) \"ARC\" \"AGC\")))", "language": "Lisp", "metadata": {"date": 1576900792, "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/s326210432.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s326210432", "user_id": "u493610446"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(setq x (read))\n(princ (if (< x 1200) \"ABC\" (if (< x 2800) \"ARC\" \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 15, "memory_kb": 3688}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s844950228", "group_id": "codeNet:p03288", "input_text": "(let ((rate (read)))\n (cond\n ((< rate 1200) (princ \"ABC\"))\n ((< rate 2800) (princ \"ARC\"))\n (t (princ \"AGC\"))))", "language": "Lisp", "metadata": {"date": 1533687433, "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/s844950228.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s844950228", "user_id": "u913204306"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(let ((rate (read)))\n (cond\n ((< rate 1200) (princ \"ABC\"))\n ((< rate 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 8, "memory_kb": 3176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s883917776", "group_id": "codeNet:p03289", "input_text": "(let ((s (read-line)))\n (princ (if (and (char= (char s 0) #\\A)\n (= 1 (count #\\C s :start 2 :end (- (length s) 1) :test #'char=))\n (not (some #'upper-case-p (remove #\\C (subseq s 2) :count 1))))\n \"AC\"\n \"WA\")))", "language": "Lisp", "metadata": {"date": 1563341841, "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/s883917776.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s883917776", "user_id": "u480300350"}, "prompt_components": {"gold_output": "AC\n", "input_to_evaluate": "(let ((s (read-line)))\n (princ (if (and (char= (char s 0) #\\A)\n (= 1 (count #\\C s :start 2 :end (- (length s) 1) :test #'char=))\n (not (some #'upper-case-p (remove #\\C (subseq s 2) :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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 130, "memory_kb": 12004}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s633397778", "group_id": "codeNet:p03289", "input_text": "(let ((str (read-line)))\n (defun char-down-p (a)\n (<= 97 (char-code a) 122))\n (if (and (char= #\\A (aref str 0))\n (= 1 (count #\\C (subseq str 2 (- (length str) 1)) :test #'char=))\n (equal \"AC\" (remove-if #'char-down-p str)))\n (princ \"AC\")\n (princ \"WA\")))", "language": "Lisp", "metadata": {"date": 1560447746, "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/s633397778.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s633397778", "user_id": "u610490393"}, "prompt_components": {"gold_output": "AC\n", "input_to_evaluate": "(let ((str (read-line)))\n (defun char-down-p (a)\n (<= 97 (char-code a) 122))\n (if (and (char= #\\A (aref str 0))\n (= 1 (count #\\C (subseq str 2 (- (length str) 1)) :test #'char=))\n (equal \"AC\" (remove-if #'char-down-p str)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 288, "cpu_time_ms": 19, "memory_kb": 4452}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s347820266", "group_id": "codeNet:p03289", "input_text": "(defun chkchartype (a)\n (and (>= (char-code a) 97) (<= (char-code a) 122)))\n\n(let ((str (concatenate 'list (read-line))))\n (if (and (char= #\\A (pop str)) (chkchartype (pop str)) (char= #\\C (pop str)) (string= (concatenate 'string str) (string-downcase (concatenate 'string str))))\n (princ \"AC\")\n (princ \"WA\")))", "language": "Lisp", "metadata": {"date": 1539365051, "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/s347820266.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s347820266", "user_id": "u610490393"}, "prompt_components": {"gold_output": "AC\n", "input_to_evaluate": "(defun chkchartype (a)\n (and (>= (char-code a) 97) (<= (char-code a) 122)))\n\n(let ((str (concatenate 'list (read-line))))\n (if (and (char= #\\A (pop str)) (chkchartype (pop str)) (char= #\\C (pop str)) (string= (concatenate 'string str) (string-downcase (concatenate 'string str))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 322, "cpu_time_ms": 16, "memory_kb": 3936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s301602234", "group_id": "codeNet:p03289", "input_text": "(let ((s (read-line)))\n (princ (if (and (char= (char s 0) #\\A)\n (= (count #\\C (subseq s 2 (1- (length s)))) 1)\n (string= (remove-if #'lower-case-p (remove #\\C (subseq s 1) :count 1)) \"\"))\n \"AC\"\n \"WA\")))", "language": "Lisp", "metadata": {"date": 1533688430, "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/s301602234.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s301602234", "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 (subseq s 2 (1- (length s)))) 1)\n (string= (remove-if #'lower-case-p (remove #\\C (subseq s 1) :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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 4068}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s916191035", "group_id": "codeNet:p03289", "input_text": "(let ((s (read-line)))\n (princ (if (and (equal (char s 0) #\\A) (= 1 (count #\\C (subseq s 2)))) \"AC\" \"WA\")))\n", "language": "Lisp", "metadata": {"date": 1533670332, "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/s916191035.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s916191035", "user_id": "u994767958"}, "prompt_components": {"gold_output": "AC\n", "input_to_evaluate": "(let ((s (read-line)))\n (princ (if (and (equal (char s 0) #\\A) (= 1 (count #\\C (subseq s 2)))) \"AC\" \"WA\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 99, "memory_kb": 10472}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s358426216", "group_id": "codeNet:p03292", "input_text": "(defun calc (l)\n (+ (abs (- (nth 1 l) (nth 0 l))) (abs (- (nth 2 l) (nth 1 l)))))\n\n(defun perm (now next)\n (let ((minimum 1000000000) (tmp nil))\n (if (equal now nil)\n (calc next)\n (dotimes (i (length now) minimum)\n (setq tmp (perm (append (subseq now 0 i) (nthcdr (+ i 1) now)) (append next (list (nth i now)))))\n (when (> minimum tmp) (setq minimum tmp))))))\n\n(format t \"~a~%\" (perm (list (read) (read) (read)) '()))", "language": "Lisp", "metadata": {"date": 1569126549, "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/s358426216.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s358426216", "user_id": "u358554431"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun calc (l)\n (+ (abs (- (nth 1 l) (nth 0 l))) (abs (- (nth 2 l) (nth 1 l)))))\n\n(defun perm (now next)\n (let ((minimum 1000000000) (tmp nil))\n (if (equal now nil)\n (calc next)\n (dotimes (i (length now) minimum)\n (setq tmp (perm (append (subseq now 0 i) (nthcdr (+ i 1) now)) (append next (list (nth i now)))))\n (when (> minimum tmp) (setq minimum tmp))))))\n\n(format t \"~a~%\" (perm (list (read) (read) (read)) '()))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 128, "memory_kb": 12388}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s401003238", "group_id": "codeNet:p03292", "input_text": "(defun TaskSchedulingProblem (tList)\n (sort tList #'<)\n (+ (- (cadr tList) (car tList)) (- (caddr tList) (cadr tList))))\n\n(format t \"~A~%\" (TaskSchedulingProblem (list (read) (read) (read))))", "language": "Lisp", "metadata": {"date": 1532240150, "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/s401003238.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s401003238", "user_id": "u231458241"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun TaskSchedulingProblem (tList)\n (sort tList #'<)\n (+ (- (cadr tList) (car tList)) (- (caddr tList) (cadr tList))))\n\n(format t \"~A~%\" (TaskSchedulingProblem (list (read) (read) (read))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 9, "memory_kb": 3304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s162233186", "group_id": "codeNet:p03292", "input_text": "(let ((a (read))\n (b (read))\n (c (read)))\n (princ (- (max a b c) (min a b c))))", "language": "Lisp", "metadata": {"date": 1532221422, "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/s162233186.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s162233186", "user_id": "u994767958"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read)))\n (princ (- (max a b c) (min a b c))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 321, "memory_kb": 10980}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s165283187", "group_id": "codeNet:p03293", "input_text": "(let ((l1 (concatenate 'list (read-line)))\n (l2 (concatenate 'list (read-line))))\n\n (defun f (lst)\n (reverse (cdr (reverse (append (last lst) lst)))))\n\n\n (defun g (lst1 lst2 &optional (cnt (length lst1)))\n (if (minusp cnt)\n nil\n (if (equal lst1 lst2)\n T\n (g (f lst1) lst2 (1- cnt)))))\n\n\n (format t \"~A~%\"\n (if (g l1 l2)\n \"Yes\"\n \"No\")))\n", "language": "Lisp", "metadata": {"date": 1600120885, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s165283187.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s165283187", "user_id": "u336541610"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((l1 (concatenate 'list (read-line)))\n (l2 (concatenate 'list (read-line))))\n\n (defun f (lst)\n (reverse (cdr (reverse (append (last lst) lst)))))\n\n\n (defun g (lst1 lst2 &optional (cnt (length lst1)))\n (if (minusp cnt)\n nil\n (if (equal lst1 lst2)\n T\n (g (f lst1) lst2 (1- cnt)))))\n\n\n (format t \"~A~%\"\n (if (g l1 l2)\n \"Yes\"\n \"No\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 405, "cpu_time_ms": 22, "memory_kb": 23728}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s108998157", "group_id": "codeNet:p03294", "input_text": "(princ (reduce (lambda (x y) (+ x (1- y)))\n\t(loop :repeat (read) :collect (read))\n\t:initial-value 0))", "language": "Lisp", "metadata": {"date": 1584916928, "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/s108998157.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s108998157", "user_id": "u334552723"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(princ (reduce (lambda (x y) (+ x (1- y)))\n\t(loop :repeat (read) :collect (read))\n\t:initial-value 0))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 20, "memory_kb": 8552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s146100694", "group_id": "codeNet:p03294", "input_text": "(let* ((n (read))\n (lst (loop :repeat n :collect (read))))\n (princ (loop :for a :from 1 :upto (reduce #'* lst)\n :maximize(reduce #'+ (mapcar (lambda (k) (mod a k)) lst)))))", "language": "Lisp", "metadata": {"date": 1560795210, "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/s146100694.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s146100694", "user_id": "u610490393"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(let* ((n (read))\n (lst (loop :repeat n :collect (read))))\n (princ (loop :for a :from 1 :upto (reduce #'* lst)\n :maximize(reduce #'+ (mapcar (lambda (k) (mod a k)) lst)))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2105, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s618383674", "group_id": "codeNet:p03294", "input_text": "(read-line) ; Drop the first line.\n(princ\n (apply #'+\n (mapcar #'(lambda (x)\n (1- x))\n (read-from-string (concatenate 'string \"(\" (read-line) \")\")))))", "language": "Lisp", "metadata": {"date": 1533418677, "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/s618383674.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s618383674", "user_id": "u913204306"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(read-line) ; Drop the first line.\n(princ\n (apply #'+\n (mapcar #'(lambda (x)\n (1- x))\n (read-from-string (concatenate 'string \"(\" (read-line) \")\")))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 39, "memory_kb": 5096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s907077710", "group_id": "codeNet:p03295", "input_text": "(let ((land-num (read))\n (request-num (read))\n (lands (make-array (1+ land-num))))\n (loop repeat request-num\n for land1 = (read)\n for land2 = (read)\n do (setf (aref lands land2) (max land1 (aref lands land2))))\n (loop with ans = 0\n for i from 1 upto land-num\n do (and (not (= 0 (aref lands i)))\n (= (aref lands (aref lands i)) ans)\n (incf ans))\n (setf (aref lands i) ans)\n finally (format t \"~A~%\" ans)))", "language": "Lisp", "metadata": {"date": 1533430509, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03295.html", "problem_id": "p03295", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03295/input.txt", "sample_output_relpath": "derived/input_output/data/p03295/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03295/Lisp/s907077710.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s907077710", "user_id": "u913204306"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((land-num (read))\n (request-num (read))\n (lands (make-array (1+ land-num))))\n (loop repeat request-num\n for land1 = (read)\n for land2 = (read)\n do (setf (aref lands land2) (max land1 (aref lands land2))))\n (loop with ans = 0\n for i from 1 upto land-num\n do (and (not (= 0 (aref lands i)))\n (= (aref lands (aref lands i)) ans)\n (incf ans))\n (setf (aref lands i) ans)\n finally (format t \"~A~%\" ans)))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N islands lining up from west to east, connected by N-1 bridges.\n\nThe i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.\n\nOne day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:\n\nRequest i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible.\n\nYou decided to remove some bridges to meet all these M requests.\n\nFind the minimum number of bridges that must be removed.\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 a_i < b_i \\leq N\n\nAll pairs (a_i, b_i) are distinct.\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\nPrint the minimum number of bridges that must be removed.\n\nSample Input 1\n\n5 2\n1 4\n2 5\n\nSample Output 1\n\n1\n\nThe requests can be met by removing the bridge connecting the second and third islands from the west.\n\nSample Input 2\n\n9 5\n1 8\n2 7\n3 5\n4 6\n7 9\n\nSample Output 2\n\n2\n\nSample Input 3\n\n5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n\nSample Output 3\n\n4", "sample_input": "5 2\n1 4\n2 5\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03295", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N islands lining up from west to east, connected by N-1 bridges.\n\nThe i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.\n\nOne day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:\n\nRequest i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible.\n\nYou decided to remove some bridges to meet all these M requests.\n\nFind the minimum number of bridges that must be removed.\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 a_i < b_i \\leq N\n\nAll pairs (a_i, b_i) are distinct.\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\nPrint the minimum number of bridges that must be removed.\n\nSample Input 1\n\n5 2\n1 4\n2 5\n\nSample Output 1\n\n1\n\nThe requests can be met by removing the bridge connecting the second and third islands from the west.\n\nSample Input 2\n\n9 5\n1 8\n2 7\n3 5\n4 6\n7 9\n\nSample Output 2\n\n2\n\nSample Input 3\n\n5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n\nSample Output 3\n\n4", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 498, "cpu_time_ms": 482, "memory_kb": 18532}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s354918221", "group_id": "codeNet:p03295", "input_text": "(let (ilands)\n (defun init-irands (n)\n (setq ilands (loop repeat n collect 1)))\n\n (defun remove-bridge (iland1 iland2)\n (if (not (find 0 (subseq ilands (1- iland1) (1- iland2))))\n (setq ilands (concatenate 'list (subseq ilands 0 (- iland2 2)) '(0) (subseq ilands (1- iland2))))))\n\n (defun get-ilands ()\n ilands))\n\n(defun get-requests (m)\n (loop repeat m collect (list (read) (read))))\n\n(defun merge-sort (sequence)\n (let ((split (floor (length sequence) 2)))\n (if (zerop split)\n (copy-seq sequence)\n (merge 'list\n (merge-sort (subseq sequence 0 split))\n (merge-sort (subseq sequence split))\n #'(lambda (a b) (< (cadr a) (cadr b)))))))\n\n(defun Islands-War ()\n (init-irands (read))\n (let ((requests (merge-sort (get-requests (read)))))\n (labels ((islands-war (requests cnt)\n (if requests\n (if (remove-bridge (caar requests) (cadar requests))\n (islands-war (cdr requests) (1+ cnt))\n (islands-war (cdr requests) cnt))\n cnt)))\n (islands-war requests 0))))\n\n(Islands-War)", "language": "Lisp", "metadata": {"date": 1533427900, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03295.html", "problem_id": "p03295", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03295/input.txt", "sample_output_relpath": "derived/input_output/data/p03295/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03295/Lisp/s354918221.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s354918221", "user_id": "u913204306"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let (ilands)\n (defun init-irands (n)\n (setq ilands (loop repeat n collect 1)))\n\n (defun remove-bridge (iland1 iland2)\n (if (not (find 0 (subseq ilands (1- iland1) (1- iland2))))\n (setq ilands (concatenate 'list (subseq ilands 0 (- iland2 2)) '(0) (subseq ilands (1- iland2))))))\n\n (defun get-ilands ()\n ilands))\n\n(defun get-requests (m)\n (loop repeat m collect (list (read) (read))))\n\n(defun merge-sort (sequence)\n (let ((split (floor (length sequence) 2)))\n (if (zerop split)\n (copy-seq sequence)\n (merge 'list\n (merge-sort (subseq sequence 0 split))\n (merge-sort (subseq sequence split))\n #'(lambda (a b) (< (cadr a) (cadr b)))))))\n\n(defun Islands-War ()\n (init-irands (read))\n (let ((requests (merge-sort (get-requests (read)))))\n (labels ((islands-war (requests cnt)\n (if requests\n (if (remove-bridge (caar requests) (cadar requests))\n (islands-war (cdr requests) (1+ cnt))\n (islands-war (cdr requests) cnt))\n cnt)))\n (islands-war requests 0))))\n\n(Islands-War)", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N islands lining up from west to east, connected by N-1 bridges.\n\nThe i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.\n\nOne day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:\n\nRequest i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible.\n\nYou decided to remove some bridges to meet all these M requests.\n\nFind the minimum number of bridges that must be removed.\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 a_i < b_i \\leq N\n\nAll pairs (a_i, b_i) are distinct.\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\nPrint the minimum number of bridges that must be removed.\n\nSample Input 1\n\n5 2\n1 4\n2 5\n\nSample Output 1\n\n1\n\nThe requests can be met by removing the bridge connecting the second and third islands from the west.\n\nSample Input 2\n\n9 5\n1 8\n2 7\n3 5\n4 6\n7 9\n\nSample Output 2\n\n2\n\nSample Input 3\n\n5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n\nSample Output 3\n\n4", "sample_input": "5 2\n1 4\n2 5\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03295", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N islands lining up from west to east, connected by N-1 bridges.\n\nThe i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.\n\nOne day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:\n\nRequest i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible.\n\nYou decided to remove some bridges to meet all these M requests.\n\nFind the minimum number of bridges that must be removed.\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 a_i < b_i \\leq N\n\nAll pairs (a_i, b_i) are distinct.\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\nPrint the minimum number of bridges that must be removed.\n\nSample Input 1\n\n5 2\n1 4\n2 5\n\nSample Output 1\n\n1\n\nThe requests can be met by removing the bridge connecting the second and third islands from the west.\n\nSample Input 2\n\n9 5\n1 8\n2 7\n3 5\n4 6\n7 9\n\nSample Output 2\n\n2\n\nSample Input 3\n\n5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n\nSample Output 3\n\n4", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1149, "cpu_time_ms": 2107, "memory_kb": 100744}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s896328330", "group_id": "codeNet:p03295", "input_text": "(let (ilands)\n (defun init-irands (n)\n (setq ilands (loop repeat n collect 1)))\n\n (defun remove-bridge (iland1 iland2)\n (if (find 0 (subseq ilands (1- iland1) (1- iland2)))\n ilands\n (setq ilands (concatenate 'list (subseq ilands 0 (- iland2 2)) '(0) (subseq ilands (1- iland2))))))\n\n (defun get-ilands ()\n ilands))\n\n(defun get-requests (m)\n (loop repeat m collect (list (read) (read))))\n\n(defun Islands-War ()\n (init-irands (read))\n (loop for request in (sort (get-requests (read)) #'(lambda (a b) (< (cadr a) (cadr b)))) do\n (remove-bridge (first request) (second request)))\n (princ (count 0 (get-ilands))))\n\n(Islands-War)", "language": "Lisp", "metadata": {"date": 1533425828, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03295.html", "problem_id": "p03295", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03295/input.txt", "sample_output_relpath": "derived/input_output/data/p03295/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03295/Lisp/s896328330.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s896328330", "user_id": "u913204306"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let (ilands)\n (defun init-irands (n)\n (setq ilands (loop repeat n collect 1)))\n\n (defun remove-bridge (iland1 iland2)\n (if (find 0 (subseq ilands (1- iland1) (1- iland2)))\n ilands\n (setq ilands (concatenate 'list (subseq ilands 0 (- iland2 2)) '(0) (subseq ilands (1- iland2))))))\n\n (defun get-ilands ()\n ilands))\n\n(defun get-requests (m)\n (loop repeat m collect (list (read) (read))))\n\n(defun Islands-War ()\n (init-irands (read))\n (loop for request in (sort (get-requests (read)) #'(lambda (a b) (< (cadr a) (cadr b)))) do\n (remove-bridge (first request) (second request)))\n (princ (count 0 (get-ilands))))\n\n(Islands-War)", "problem_context": "Score : 400 points\n\nProblem Statement\n\nThere are N islands lining up from west to east, connected by N-1 bridges.\n\nThe i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.\n\nOne day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:\n\nRequest i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible.\n\nYou decided to remove some bridges to meet all these M requests.\n\nFind the minimum number of bridges that must be removed.\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 a_i < b_i \\leq N\n\nAll pairs (a_i, b_i) are distinct.\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\nPrint the minimum number of bridges that must be removed.\n\nSample Input 1\n\n5 2\n1 4\n2 5\n\nSample Output 1\n\n1\n\nThe requests can be met by removing the bridge connecting the second and third islands from the west.\n\nSample Input 2\n\n9 5\n1 8\n2 7\n3 5\n4 6\n7 9\n\nSample Output 2\n\n2\n\nSample Input 3\n\n5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n\nSample Output 3\n\n4", "sample_input": "5 2\n1 4\n2 5\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03295", "source_text": "Score : 400 points\n\nProblem Statement\n\nThere are N islands lining up from west to east, connected by N-1 bridges.\n\nThe i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.\n\nOne day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:\n\nRequest i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible.\n\nYou decided to remove some bridges to meet all these M requests.\n\nFind the minimum number of bridges that must be removed.\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 a_i < b_i \\leq N\n\nAll pairs (a_i, b_i) are distinct.\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\nPrint the minimum number of bridges that must be removed.\n\nSample Input 1\n\n5 2\n1 4\n2 5\n\nSample Output 1\n\n1\n\nThe requests can be met by removing the bridge connecting the second and third islands from the west.\n\nSample Input 2\n\n9 5\n1 8\n2 7\n3 5\n4 6\n7 9\n\nSample Output 2\n\n2\n\nSample Input 3\n\n5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n\nSample Output 3\n\n4", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 656, "cpu_time_ms": 2108, "memory_kb": 104824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s183064356", "group_id": "codeNet:p03296", "input_text": "(let ((n (read))\n (pre -1)\n (rep 0)\n (temp 0)\n (ans 0))\n (loop repeat n do\n (setf temp (read))\n (if (eq pre temp) (progn (incf rep)\n (if (eq 0 (rem rep 2)) (incf ans)))\n (progn (setf pre temp)\n (setf rep 1))))\n (princ ans))\n", "language": "Lisp", "metadata": {"date": 1531692234, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03296.html", "problem_id": "p03296", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03296/input.txt", "sample_output_relpath": "derived/input_output/data/p03296/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03296/Lisp/s183064356.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s183064356", "user_id": "u994767958"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((n (read))\n (pre -1)\n (rep 0)\n (temp 0)\n (ans 0))\n (loop repeat n do\n (setf temp (read))\n (if (eq pre temp) (progn (incf rep)\n (if (eq 0 (rem rep 2)) (incf ans)))\n (progn (setf pre temp)\n (setf rep 1))))\n (princ ans))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nTakahashi lives in another world. There are slimes (creatures) of 10000 colors in this world. Let us call these colors Color 1, 2, ..., 10000.\n\nTakahashi has N slimes, and they are standing in a row from left to right. The color of the i-th slime from the left is a_i.\nIf two slimes of the same color are adjacent, they will start to combine themselves. Because Takahashi likes smaller slimes, he has decided to change the colors of some of the slimes with his magic.\n\nTakahashi can change the color of one slime to any of the 10000 colors by one spell.\nHow many spells are required so that no slimes will start to combine themselves?\n\nConstraints\n\n2 \\leq N \\leq 100\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\nPrint the minimum number of spells required.\n\nSample Input 1\n\n5\n1 1 2 2 2\n\nSample Output 1\n\n2\n\nFor example, if we change the color of the second slime from the left to 4, and the color of the fourth slime to 5, the colors of the slimes will be 1, 4, 2, 5, 2, which satisfy the condition.\n\nSample Input 2\n\n3\n1 2 1\n\nSample Output 2\n\n0\n\nAlthough the colors of the first and third slimes are the same, they are not adjacent, so no spell is required.\n\nSample Input 3\n\n5\n1 1 1 1 1\n\nSample Output 3\n\n2\n\nFor example, if we change the colors of the second and fourth slimes from the left to 2, the colors of the slimes will be 1, 2, 1, 2, 1, which satisfy the condition.\n\nSample Input 4\n\n14\n1 2 2 3 3 3 4 4 4 4 1 2 3 4\n\nSample Output 4\n\n4", "sample_input": "5\n1 1 2 2 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03296", "source_text": "Score : 200 points\n\nProblem Statement\n\nTakahashi lives in another world. There are slimes (creatures) of 10000 colors in this world. Let us call these colors Color 1, 2, ..., 10000.\n\nTakahashi has N slimes, and they are standing in a row from left to right. The color of the i-th slime from the left is a_i.\nIf two slimes of the same color are adjacent, they will start to combine themselves. Because Takahashi likes smaller slimes, he has decided to change the colors of some of the slimes with his magic.\n\nTakahashi can change the color of one slime to any of the 10000 colors by one spell.\nHow many spells are required so that no slimes will start to combine themselves?\n\nConstraints\n\n2 \\leq N \\leq 100\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\nPrint the minimum number of spells required.\n\nSample Input 1\n\n5\n1 1 2 2 2\n\nSample Output 1\n\n2\n\nFor example, if we change the color of the second slime from the left to 4, and the color of the fourth slime to 5, the colors of the slimes will be 1, 4, 2, 5, 2, which satisfy the condition.\n\nSample Input 2\n\n3\n1 2 1\n\nSample Output 2\n\n0\n\nAlthough the colors of the first and third slimes are the same, they are not adjacent, so no spell is required.\n\nSample Input 3\n\n5\n1 1 1 1 1\n\nSample Output 3\n\n2\n\nFor example, if we change the colors of the second and fourth slimes from the left to 2, the colors of the slimes will be 1, 2, 1, 2, 1, which satisfy the condition.\n\nSample Input 4\n\n14\n1 2 2 3 3 3 4 4 4 4 1 2 3 4\n\nSample Output 4\n\n4", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 321, "cpu_time_ms": 15, "memory_kb": 4196}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s464009540", "group_id": "codeNet:p03298", "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(defun displace (vec &optional (start 0) end)\n \"displaced subseq\"\n (let ((end (or end (length vec))))\n (make-array (- end start)\n :element-type (array-element-type vec)\n :displaced-to vec\n :displaced-index-offset start)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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(declaim (inline simple-base-string40=))\n(defun simple-base-string40= (s1 s2)\n (declare #.OPT\n ((simple-base-string 40) s1 s2))\n (equal s1 s2))\n\n(declaim (inline sxhash-sbs40))\n(defun sxhash-sbs40 (string)\n (declare #.OPT\n ((simple-base-string 40) string))\n (macrolet ((set-result (form)\n `(setf result (ldb (byte 64 0) ,form))))\n (let ((result 0))\n (declare (uint64 result))\n (dotimes (i 5)\n (set-result (+ result (sb-kernel:%vector-raw-bits string i)))\n (set-result (logxor result (ash result -6))))\n (set-result (logxor result (ash result -11)))\n (logand result most-positive-fixnum))))\n\n(sb-ext:define-hash-table-test simple-base-string40= sxhash-sbs40)\n\n(declaim (inline extract))\n(defun extract (mask s)\n (let* ((res (make-string 40 :element-type 'base-char :initial-element #\\Nul)))\n (loop with red-i = 0\n with blue-i = 20\n for pos below (length s)\n do (if (logbitp pos mask)\n (progn (setf (aref res red-i) (aref s pos))\n (incf red-i))\n (progn (setf (aref res blue-i) (aref s pos))\n (incf blue-i))))\n res))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (s (read-line))\n (s1 (coerce (reverse (displace s 0 n)) 'simple-base-string))\n (s2 (coerce (displace s n (+ n n)) 'simple-base-string))\n (table (make-hash-table :test #'simple-base-string40= :size #.(expt 2 18))))\n (declare ((integer 1 18) n))\n (dotimes (mask (expt 2 n))\n (let ((key (extract mask s1)))\n (multiple-value-bind (value presentp) (gethash key table)\n (if presentp\n (setf (gethash key table) (1+ (the uint32 value)))\n (setf (gethash key table) 1)))))\n (let ((res 0))\n (declare (fixnum res))\n (dotimes (mask (expt 2 n))\n (let* ((key (extract mask s2))\n (value (gethash key table)))\n (when value\n (incf res (the uint32 value)))))\n (println res))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1552481914, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03298.html", "problem_id": "p03298", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03298/input.txt", "sample_output_relpath": "derived/input_output/data/p03298/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03298/Lisp/s464009540.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s464009540", "user_id": "u352600849"}, "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 :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(defun displace (vec &optional (start 0) end)\n \"displaced subseq\"\n (let ((end (or end (length vec))))\n (make-array (- end start)\n :element-type (array-element-type vec)\n :displaced-to vec\n :displaced-index-offset start)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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(declaim (inline simple-base-string40=))\n(defun simple-base-string40= (s1 s2)\n (declare #.OPT\n ((simple-base-string 40) s1 s2))\n (equal s1 s2))\n\n(declaim (inline sxhash-sbs40))\n(defun sxhash-sbs40 (string)\n (declare #.OPT\n ((simple-base-string 40) string))\n (macrolet ((set-result (form)\n `(setf result (ldb (byte 64 0) ,form))))\n (let ((result 0))\n (declare (uint64 result))\n (dotimes (i 5)\n (set-result (+ result (sb-kernel:%vector-raw-bits string i)))\n (set-result (logxor result (ash result -6))))\n (set-result (logxor result (ash result -11)))\n (logand result most-positive-fixnum))))\n\n(sb-ext:define-hash-table-test simple-base-string40= sxhash-sbs40)\n\n(declaim (inline extract))\n(defun extract (mask s)\n (let* ((res (make-string 40 :element-type 'base-char :initial-element #\\Nul)))\n (loop with red-i = 0\n with blue-i = 20\n for pos below (length s)\n do (if (logbitp pos mask)\n (progn (setf (aref res red-i) (aref s pos))\n (incf red-i))\n (progn (setf (aref res blue-i) (aref s pos))\n (incf blue-i))))\n res))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (s (read-line))\n (s1 (coerce (reverse (displace s 0 n)) 'simple-base-string))\n (s2 (coerce (displace s n (+ n n)) 'simple-base-string))\n (table (make-hash-table :test #'simple-base-string40= :size #.(expt 2 18))))\n (declare ((integer 1 18) n))\n (dotimes (mask (expt 2 n))\n (let ((key (extract mask s1)))\n (multiple-value-bind (value presentp) (gethash key table)\n (if presentp\n (setf (gethash key table) (1+ (the uint32 value)))\n (setf (gethash key table) 1)))))\n (let ((res 0))\n (declare (fixnum res))\n (dotimes (mask (expt 2 n))\n (let* ((key (extract mask s2))\n (value (gethash key table)))\n (when value\n (incf res (the uint32 value)))))\n (println res))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nYou are given a string S of length 2N consisting of lowercase English letters.\n\nThere are 2^{2N} ways to color each character in S red or blue. Among these ways, how many satisfy the following condition?\n\nThe string obtained by reading the characters painted red from left to right is equal to the string obtained by reading the characters painted blue from right to left.\n\nConstraints\n\n1 \\leq N \\leq 18\n\nThe length of S is 2N.\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the number of ways to paint the string that satisfy the condition.\n\nSample Input 1\n\n4\ncabaacba\n\nSample Output 1\n\n4\n\nThere are four ways to paint the string, as follows:\n\ncabaacba\n\ncabaacba\n\ncabaacba\n\ncabaacba\n\nSample Input 2\n\n11\nmippiisssisssiipsspiim\n\nSample Output 2\n\n504\n\nSample Input 3\n\n4\nabcdefgh\n\nSample Output 3\n\n0\n\nSample Input 4\n\n18\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n\nSample Output 4\n\n9075135300\n\nThe answer may not be representable as a 32-bit integer.", "sample_input": "4\ncabaacba\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03298", "source_text": "Score : 600 points\n\nProblem Statement\n\nYou are given a string S of length 2N consisting of lowercase English letters.\n\nThere are 2^{2N} ways to color each character in S red or blue. Among these ways, how many satisfy the following condition?\n\nThe string obtained by reading the characters painted red from left to right is equal to the string obtained by reading the characters painted blue from right to left.\n\nConstraints\n\n1 \\leq N \\leq 18\n\nThe length of S is 2N.\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the number of ways to paint the string that satisfy the condition.\n\nSample Input 1\n\n4\ncabaacba\n\nSample Output 1\n\n4\n\nThere are four ways to paint the string, as follows:\n\ncabaacba\n\ncabaacba\n\ncabaacba\n\ncabaacba\n\nSample Input 2\n\n11\nmippiisssisssiipsspiim\n\nSample Output 2\n\n504\n\nSample Input 3\n\n4\nabcdefgh\n\nSample Output 3\n\n0\n\nSample Input 4\n\n18\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n\nSample Output 4\n\n9075135300\n\nThe answer may not be representable as a 32-bit integer.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3265, "cpu_time_ms": 376, "memory_kb": 74216}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s969367203", "group_id": "codeNet:p03303", "input_text": "(let ((s (read-line))\n (n (read)))\n (loop for i from 0 upto (floor (/ (- (length s) 1) n)) do (format t \"~a\" (char s (* i n))))\n (format t \"~%\"))\n", "language": "Lisp", "metadata": {"date": 1531085840, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03303.html", "problem_id": "p03303", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03303/input.txt", "sample_output_relpath": "derived/input_output/data/p03303/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03303/Lisp/s969367203.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s969367203", "user_id": "u994767958"}, "prompt_components": {"gold_output": "adg\n", "input_to_evaluate": "(let ((s (read-line))\n (n (read)))\n (loop for i from 0 upto (floor (/ (- (length s) 1) n)) do (format t \"~a\" (char s (* i n))))\n (format t \"~%\"))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S consisting of lowercase English letters.\nWe will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.\n\nConstraints\n\n1 \\leq w \\leq |S| \\leq 1000\n\nS consists of lowercase English letters.\n\nw is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nw\n\nOutput\n\nPrint the desired string in one line.\n\nSample Input 1\n\nabcdefgh\n3\n\nSample Output 1\n\nadg\n\nWhen we write down abcdefgh, starting a new line after every three letters, we get the following:\n\nabc\n\ndef\n\ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain adg.\n\nSample Input 2\n\nlllll\n1\n\nSample Output 2\n\nlllll\n\nSample Input 3\n\nsouuundhound\n2\n\nSample Output 3\n\nsuudon", "sample_input": "abcdefgh\n3\n"}, "reference_outputs": ["adg\n"], "source_document_id": "p03303", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S consisting of lowercase English letters.\nWe will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.\n\nConstraints\n\n1 \\leq w \\leq |S| \\leq 1000\n\nS consists of lowercase English letters.\n\nw is an integer.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nS\nw\n\nOutput\n\nPrint the desired string in one line.\n\nSample Input 1\n\nabcdefgh\n3\n\nSample Output 1\n\nadg\n\nWhen we write down abcdefgh, starting a new line after every three letters, we get the following:\n\nabc\n\ndef\n\ngh\n\nConcatenating the letters at the beginnings of these lines, we obtain adg.\n\nSample Input 2\n\nlllll\n1\n\nSample Output 2\n\nlllll\n\nSample Input 3\n\nsouuundhound\n2\n\nSample Output 3\n\nsuudon", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 4328}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s414687877", "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 * (*)) :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 (test (heap-test heap))\n (next-position (heap-next-position heap)))\n (labels ((update (pos)\n (unless (= pos 1)\n (let ((parent-pos (floor pos 2)))\n (when (funcall test (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (update parent-pos))))))\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 (test (heap-test heap))\n (next-position (heap-next-position heap)))\n (labels ((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 (funcall test (aref data child-pos1) (aref data child-pos2))\n (unless (funcall test (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (update child-pos1))\n (unless (funcall test (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (update child-pos2)))\n (unless (funcall test (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\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(defun heap-peak (heap &optional (error t) null-value)\n (if (= 1 (heap-next-position heap))\n (if error\n (error \"No element in heap\")\n null-value)\n (aref (heap-data heap) 1)))\n\n;; For test\n;; (eval-when (:compile-toplevel :load-toplevel :execute)\n;; (ql:quickload :fiveam)\n;; (use-package :fiveam))\n\n;; (test heap-test\n;; (let ((h (make-heap 20)))\n;; (finishes (dolist (o (list 7 18 22 15 27 9 11))\n;; (heap-push o h)))\n;; (is (= 7 (heap-peak h)))\n;; (is (equal '(7 9 11 15 18 22 27)\n;; (loop repeat 7 collect (heap-pop h))))\n;; (signals error (heap-pop h))\n;; (is (eql 'eof (heap-pop h nil 'eof)))\n;; (is (eql 'eof (heap-peak h nil 'eof))))\n;; (is (typep (heap-data (make-heap 10 :element-type 'fixnum))\n;; '(simple-array fixnum (*)))))\n\n;; (run! 'heap-test)\n\n(defun bench (&optional (size 2000000))\n (declare (optimize (speed 3)))\n (let* ((heap (make-heap size :element-type 'fixnum))\n (seed (seed-random-state 0)))\n (time (dotimes (i size)\n (heap-push (random most-positive-fixnum seed) heap)))\n (time (dotimes (i size)\n (heap-pop heap)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 (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 (yen-table (make-array n :element-type 'fixnum :initial-element most-positive-fixnum))\n (snook-table (make-array n :element-type 'fixnum :initial-element most-positive-fixnum)))\n (dotimes (i m)\n (split-ints-and-bind (u v a b) (buffered-read-line 50)\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 (let ((pqueue (make-heap 200000 :test (lambda (p1 p2) (< (cdr p1) (cdr p2)))\n :element-type '(cons uint32 fixnum)))\n (visited (make-array n :element-type 'boolean :initial-element nil)))\n (heap-push (cons src 0) pqueue)\n (loop for (current . cost) = (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 yen-table current))\n (setf (aref yen-table current) cost))\n (dolist (neighbor (aref graph-yen current))\n (heap-push (cons (car neighbor) (+ cost (cdr neighbor))) pqueue)))))\n (let ((pqueue (make-heap 200000 :test (lambda (p1 p2) (< (cdr p1) (cdr p2)))\n :element-type '(cons uint32 fixnum)))\n (visited (make-array n :element-type 'boolean :initial-element nil)))\n (heap-push (cons dest 0) pqueue)\n (loop for (current . cost) = (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 snook-table current))\n (setf (aref snook-table current) cost))\n (dolist (neighbor (aref graph-snook current))\n (heap-push (cons (car neighbor) (+ cost (cdr neighbor))) pqueue)))))\n (let ((hub-to-cost (make-array n :element-type 'fixnum))\n (year-to-cost (make-array n :element-type 'fixnum)))\n (dotimes (i n)\n (setf (aref hub-to-cost i)\n (- #.(expt 10 15) (+ (aref yen-table i) (aref snook-table 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)\n (println (aref year-to-cost y))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1547819561, "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/s414687877.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s414687877", "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 * (*)) :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 (test (heap-test heap))\n (next-position (heap-next-position heap)))\n (labels ((update (pos)\n (unless (= pos 1)\n (let ((parent-pos (floor pos 2)))\n (when (funcall test (aref data pos) (aref data parent-pos))\n (rotatef (aref data pos) (aref data parent-pos))\n (update parent-pos))))))\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 (test (heap-test heap))\n (next-position (heap-next-position heap)))\n (labels ((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 (funcall test (aref data child-pos1) (aref data child-pos2))\n (unless (funcall test (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))\n (update child-pos1))\n (unless (funcall test (aref data pos) (aref data child-pos2))\n (rotatef (aref data pos) (aref data child-pos2))\n (update child-pos2)))\n (unless (funcall test (aref data pos) (aref data child-pos1))\n (rotatef (aref data pos) (aref data child-pos1))))))))\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(defun heap-peak (heap &optional (error t) null-value)\n (if (= 1 (heap-next-position heap))\n (if error\n (error \"No element in heap\")\n null-value)\n (aref (heap-data heap) 1)))\n\n;; For test\n;; (eval-when (:compile-toplevel :load-toplevel :execute)\n;; (ql:quickload :fiveam)\n;; (use-package :fiveam))\n\n;; (test heap-test\n;; (let ((h (make-heap 20)))\n;; (finishes (dolist (o (list 7 18 22 15 27 9 11))\n;; (heap-push o h)))\n;; (is (= 7 (heap-peak h)))\n;; (is (equal '(7 9 11 15 18 22 27)\n;; (loop repeat 7 collect (heap-pop h))))\n;; (signals error (heap-pop h))\n;; (is (eql 'eof (heap-pop h nil 'eof)))\n;; (is (eql 'eof (heap-peak h nil 'eof))))\n;; (is (typep (heap-data (make-heap 10 :element-type 'fixnum))\n;; '(simple-array fixnum (*)))))\n\n;; (run! 'heap-test)\n\n(defun bench (&optional (size 2000000))\n (declare (optimize (speed 3)))\n (let* ((heap (make-heap size :element-type 'fixnum))\n (seed (seed-random-state 0)))\n (time (dotimes (i size)\n (heap-push (random most-positive-fixnum seed) heap)))\n (time (dotimes (i size)\n (heap-pop heap)))))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 (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 (yen-table (make-array n :element-type 'fixnum :initial-element most-positive-fixnum))\n (snook-table (make-array n :element-type 'fixnum :initial-element most-positive-fixnum)))\n (dotimes (i m)\n (split-ints-and-bind (u v a b) (buffered-read-line 50)\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 (let ((pqueue (make-heap 200000 :test (lambda (p1 p2) (< (cdr p1) (cdr p2)))\n :element-type '(cons uint32 fixnum)))\n (visited (make-array n :element-type 'boolean :initial-element nil)))\n (heap-push (cons src 0) pqueue)\n (loop for (current . cost) = (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 yen-table current))\n (setf (aref yen-table current) cost))\n (dolist (neighbor (aref graph-yen current))\n (heap-push (cons (car neighbor) (+ cost (cdr neighbor))) pqueue)))))\n (let ((pqueue (make-heap 200000 :test (lambda (p1 p2) (< (cdr p1) (cdr p2)))\n :element-type '(cons uint32 fixnum)))\n (visited (make-array n :element-type 'boolean :initial-element nil)))\n (heap-push (cons dest 0) pqueue)\n (loop for (current . cost) = (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 snook-table current))\n (setf (aref snook-table current) cost))\n (dolist (neighbor (aref graph-snook current))\n (heap-push (cons (car neighbor) (+ cost (cdr neighbor))) pqueue)))))\n (let ((hub-to-cost (make-array n :element-type 'fixnum))\n (year-to-cost (make-array n :element-type 'fixnum)))\n (dotimes (i n)\n (setf (aref hub-to-cost i)\n (- #.(expt 10 15) (+ (aref yen-table i) (aref snook-table 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)\n (println (aref year-to-cost y))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8844, "cpu_time_ms": 1271, "memory_kb": 79072}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s503676628", "group_id": "codeNet:p03307", "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* ((n (read)))\n (println (if (evenp n) n (* n 2)))))\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 \"6\n\"\n (run \"3\n\" nil)))\n (5am:is\n (equal \"10\n\"\n (run \"10\n\" nil)))\n (5am:is\n (equal \"1999999998\n\"\n (run \"999999999\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600763465, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s503676628.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s503676628", "user_id": "u352600849"}, "prompt_components": {"gold_output": "6\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* ((n (read)))\n (println (if (evenp n) n (* n 2)))))\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 \"6\n\"\n (run \"3\n\" nil)))\n (5am:is\n (equal \"10\n\"\n (run \"10\n\" nil)))\n (5am:is\n (equal \"1999999998\n\"\n (run \"999999999\n\" nil))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3431, "cpu_time_ms": 17, "memory_kb": 24764}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s552923812", "group_id": "codeNet:p03307", "input_text": "(defun solve(n)\n (if (= (mod n 2) 0))\n (princ n)\n (princ (* n 2)))\n\n(format t \"~A\" (solve (read)))", "language": "Lisp", "metadata": {"date": 1571066143, "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/s552923812.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s552923812", "user_id": "u975644365"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defun solve(n)\n (if (= (mod n 2) 0))\n (princ n)\n (princ (* n 2)))\n\n(format t \"~A\" (solve (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 136, "memory_kb": 10724}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s280298316", "group_id": "codeNet:p03307", "input_text": "(defvar *N* nil)\n(setf *N* (read))\n\n(defvar *count* *N*)\n(defvar *list1* (list nil))\n(dotimes (x 10)\n (declare (ignore x))\n (if (= (mod *count* *N*) 0)\n (push *count* *list1*))\n (setq *count* (+ *count* *N*)))\n\n(setq *list1* (cdr (reverse *list1*)))\n\n(setq *count* *N*)\n(defvar *list2* (list nil))\n(dotimes (x 10)\n (declare (ignore x))\n (when (= (mod *count* 2) 0)\n (push *count* *list2*))\n (setq *count* (+ *count* *N*)))\n\n(setq *list2* (cdr (reverse *list2*)))\n\n\n(dolist (x *list1*)\n (dolist (y *list2*)\n (if (= x y)\n (progn (format t \"~d~%\" x)\n (sb-ext:quit)))))\n\n", "language": "Lisp", "metadata": {"date": 1530587974, "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/s280298316.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s280298316", "user_id": "u631655863"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defvar *N* nil)\n(setf *N* (read))\n\n(defvar *count* *N*)\n(defvar *list1* (list nil))\n(dotimes (x 10)\n (declare (ignore x))\n (if (= (mod *count* *N*) 0)\n (push *count* *list1*))\n (setq *count* (+ *count* *N*)))\n\n(setq *list1* (cdr (reverse *list1*)))\n\n(setq *count* *N*)\n(defvar *list2* (list nil))\n(dotimes (x 10)\n (declare (ignore x))\n (when (= (mod *count* 2) 0)\n (push *count* *list2*))\n (setq *count* (+ *count* *N*)))\n\n(setq *list2* (cdr (reverse *list2*)))\n\n\n(dolist (x *list1*)\n (dolist (y *list2*)\n (if (= x y)\n (progn (format t \"~d~%\" x)\n (sb-ext:quit)))))\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 608, "cpu_time_ms": 146, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s190628754", "group_id": "codeNet:p03308", "input_text": "(let ((a (sort (loop repeat (read) collect (read)) #'<)))\n (princ (- (first (last a))\n (first a))))", "language": "Lisp", "metadata": {"date": 1600455284, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s190628754.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s190628754", "user_id": "u425762225"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((a (sort (loop repeat (read) collect (read)) #'<)))\n (princ (- (first (last a))\n (first a))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 24260}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s206616798", "group_id": "codeNet:p03308", "input_text": "(let* ((n (read))\n (l (sort (loop repeat n\n collect (read))\n #'>)))\n\n (format t \"~A~%\"\n (- (car l)\n (car (last l)))))\n", "language": "Lisp", "metadata": {"date": 1599946837, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s206616798.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s206616798", "user_id": "u336541610"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let* ((n (read))\n (l (sort (loop repeat n\n collect (read))\n #'>)))\n\n (format t \"~A~%\"\n (- (car l)\n (car (last l)))))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 19, "memory_kb": 24428}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s527373089", "group_id": "codeNet:p03308", "input_text": "# include \n# include \n\nint main()\n{\n std::string s, t;\n std::cin >> s >> t;\n int n = s.length();\n\n int flag = 0;\n for (int i=0; i\n# include \n\nint main()\n{\n std::string s, t;\n std::cin >> s >> t;\n int n = s.length();\n\n int flag = 0;\n for (int i=0; i b n) minsad) )))\n\n(defvar N (read))\n(princ (solve N (loop :repeat N :collect (read))))\n\n", "language": "Lisp", "metadata": {"date": 1584916611, "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/s919021018.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s919021018", "user_id": "u334552723"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun sad-diff (N newlst)\n (- (* 2 (count-if #'minusp newlst)) N))\n\n(defun range (m n &optional l)\n (if (< n m) l\n (range m (1- n) (cons n l)) ))\n\n(defun solve (N lst)\n (setf lst (mapcar #'- lst (range 1 N)))\n (let ((m (reduce #'min lst))\n (n (reduce #'max lst)))\n (do* ((b m (1+ b))\n (l (mapcar (lambda (x) (- x b)) lst)\n (mapcar #'1- lst))\n (sad (reduce \n (lambda (x y) (+ x (abs y)))\n l :initial-value 0 )\n (+ sad (sad-diff N l)))\n (minsad sad (min sad minsad)))\n ((> b n) minsad) )))\n\n(defvar N (read))\n(princ (solve N (loop :repeat N :collect (read))))\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 692, "cpu_time_ms": 2107, "memory_kb": 111028}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s652604692", "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": 1531972822, "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/s652604692.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s652604692", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 298, "cpu_time_ms": 612, "memory_kb": 60520}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s396335295", "group_id": "codeNet:p03309", "input_text": "(defparameter *n* (read))\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(defun LinearApproximation ()\n (let ((B) (sb 0) (count 0))\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 \n(format t \"~A~%\" (LinearApproximation))", "language": "Lisp", "metadata": {"date": 1531972186, "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/s396335295.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s396335295", "user_id": "u231458241"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defparameter *n* (read))\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(defun LinearApproximation ()\n (let ((B) (sb 0) (count 0))\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 \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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 545, "cpu_time_ms": 611, "memory_kb": 60520}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s860045128", "group_id": "codeNet:p03309", "input_text": ";; WA\n(defun subi (a xs)\n (if (null xs)\n ()\n (cons (- a (car xs)) (subi a (cdr xs)))))\n\n(let ((N (read))\n A)\n (format t \"~A~%\"\n (apply #'+\n (mapcar #'abs\n (let ((sorted (sort\n (dotimes (i N A) (push (- (read) i 1) A))\n #'<)))\n (subi\n (nth (1- (ceiling (/ (length A) 2))) sorted) A))))))", "language": "Lisp", "metadata": {"date": 1530558083, "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/s860045128.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s860045128", "user_id": "u299647642"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": ";; WA\n(defun subi (a xs)\n (if (null xs)\n ()\n (cons (- a (car xs)) (subi a (cdr xs)))))\n\n(let ((N (read))\n A)\n (format t \"~A~%\"\n (apply #'+\n (mapcar #'abs\n (let ((sorted (sort\n (dotimes (i N A) (push (- (read) i 1) A))\n #'<)))\n (subi\n (nth (1- (ceiling (/ (length A) 2))) sorted) A))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2107, "memory_kb": 110180}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s770605535", "group_id": "codeNet:p03309", "input_text": "(defun subi (a xs)\n (if (null xs)\n ()\n (cons (- a (car xs)) (subi a (cdr xs)))))\n\n(let ((N (read))\n A)\n (format t \"~A~%\"\n (apply #'+\n (mapcar #'abs\n (let ((sorted (sort\n (dotimes (i N A) (push (- (read) i 1) A))\n #'<)))\n (subi\n (nth (floor (/ (length A) 2)) sorted) A))))))", "language": "Lisp", "metadata": {"date": 1530549559, "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/s770605535.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s770605535", "user_id": "u299647642"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun subi (a xs)\n (if (null xs)\n ()\n (cons (- a (car xs)) (subi a (cdr xs)))))\n\n(let ((N (read))\n A)\n (format t \"~A~%\"\n (apply #'+\n (mapcar #'abs\n (let ((sorted (sort\n (dotimes (i N A) (push (- (read) i 1) A))\n #'<)))\n (subi\n (nth (floor (/ (length A) 2)) sorted) A))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2105, "memory_kb": 110176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s500282893", "group_id": "codeNet:p03313", "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 unique-merge))\n(defun unique-merge (list1 list2 order &key (key #'identity) end)\n (declare (function order))\n (labels\n ((recur (list1 list2 len)\n (declare ((integer 0 #.most-positive-fixnum) len))\n (cond\n ((zerop len) nil)\n ((null list1) list2)\n ((null list2) list1)\n (t\n (let ((val1 (funcall key (car list1)))\n (val2 (funcall key (car list2))))\n (cond ((funcall order val1 val2)\n (cons (car list1)\n (recur (cdr list1) list2 (- len 1))))\n ((funcall order val2 val1)\n (cons (car list2)\n (recur list1 (cdr list2) (- len 1))))\n ((eql (car list1) (car list2))\n (cons (car list1)\n (recur (cdr list1) (cdr list2) (- len 1))))\n (t\n (cons (car list1)\n (recur (cdr list1) list2 (- len 1))))))))))\n (recur list1 list2 (or end most-positive-fixnum))))\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(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 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 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\n;; 添え字集合∪添え字集合で大きいほう2つを残すという操作を⊕とすると、結合的かつ可換。\n;; つまり、F(S) = ⊕_{T ⊆ S} f(T)を求めれば良いけど、fは何?\n;; → f(T) = {T}か。\n;; これでi∨j ⊆ K に対する最大値は求まる。\n;; i∨j <= K ⇔ k∈[K]が存在してi∨j = k\n;; ⇒ k∈[K]が存在してi∨j⊆k\n;; 最後は逆も成り立つ。k∈[K]が与えられたとき、任意のl⊆kについてl∈Kだから\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (power (expt 2 n))\n (as (make-array power :element-type 'uint32))\n (dp (make-array power :element-type 'list)))\n (declare ((integer 1 18) n))\n (dotimes (i power)\n (setf (aref as i) (read-fixnum)\n (aref dp i) (list i)))\n (zeta-subtransform!\n dp\n (lambda (set1 set2)\n (unique-merge (copy-list set1)\n (copy-list set2)\n #'>\n :key (lambda (x) (aref as x))\n :end 2)))\n (let ((res 0))\n (declare (uint32 res))\n (with-buffered-stdout\n (loop for x from 1 below power\n for (idx1 idx2) = (aref dp x)\n do (setf res (max res (+ (aref as idx1) (aref as idx2))))\n (println res))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1569437775, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03313.html", "problem_id": "p03313", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03313/input.txt", "sample_output_relpath": "derived/input_output/data/p03313/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03313/Lisp/s500282893.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s500282893", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n4\n5\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 unique-merge))\n(defun unique-merge (list1 list2 order &key (key #'identity) end)\n (declare (function order))\n (labels\n ((recur (list1 list2 len)\n (declare ((integer 0 #.most-positive-fixnum) len))\n (cond\n ((zerop len) nil)\n ((null list1) list2)\n ((null list2) list1)\n (t\n (let ((val1 (funcall key (car list1)))\n (val2 (funcall key (car list2))))\n (cond ((funcall order val1 val2)\n (cons (car list1)\n (recur (cdr list1) list2 (- len 1))))\n ((funcall order val2 val1)\n (cons (car list2)\n (recur list1 (cdr list2) (- len 1))))\n ((eql (car list1) (car list2))\n (cons (car list1)\n (recur (cdr list1) (cdr list2) (- len 1))))\n (t\n (cons (car list1)\n (recur (cdr list1) list2 (- len 1))))))))))\n (recur list1 list2 (or end most-positive-fixnum))))\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(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 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 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\n;; 添え字集合∪添え字集合で大きいほう2つを残すという操作を⊕とすると、結合的かつ可換。\n;; つまり、F(S) = ⊕_{T ⊆ S} f(T)を求めれば良いけど、fは何?\n;; → f(T) = {T}か。\n;; これでi∨j ⊆ K に対する最大値は求まる。\n;; i∨j <= K ⇔ k∈[K]が存在してi∨j = k\n;; ⇒ k∈[K]が存在してi∨j⊆k\n;; 最後は逆も成り立つ。k∈[K]が与えられたとき、任意のl⊆kについてl∈Kだから\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (power (expt 2 n))\n (as (make-array power :element-type 'uint32))\n (dp (make-array power :element-type 'list)))\n (declare ((integer 1 18) n))\n (dotimes (i power)\n (setf (aref as i) (read-fixnum)\n (aref dp i) (list i)))\n (zeta-subtransform!\n dp\n (lambda (set1 set2)\n (unique-merge (copy-list set1)\n (copy-list set2)\n #'>\n :key (lambda (x) (aref as x))\n :end 2)))\n (let ((res 0))\n (declare (uint32 res))\n (with-buffered-stdout\n (loop for x from 1 below power\n for (idx1 idx2) = (aref dp x)\n do (setf res (max res (+ (aref as idx1) (aref as idx2))))\n (println res))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nThere is an integer sequence of length 2^N: A_0, A_1, ..., A_{2^N-1}. (Note that the sequence is 0-indexed.)\n\nFor every integer K satisfying 1 \\leq K \\leq 2^N-1, solve the following problem:\n\nLet i and j be integers. Find the maximum value of A_i + A_j where 0 \\leq i < j \\leq 2^N-1 and (i or j) \\leq K.\nHere, or denotes the bitwise OR.\n\nConstraints\n\n1 \\leq N \\leq 18\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_0 A_1 ... A_{2^N-1}\n\nOutput\n\nPrint 2^N-1 lines.\nIn the i-th line, print the answer of the problem above for K=i.\n\nSample Input 1\n\n2\n1 2 3 1\n\nSample Output 1\n\n3\n4\n5\n\nFor K=1, the only possible pair of i and j is (i,j)=(0,1), so the answer is A_0+A_1=1+2=3.\n\nFor K=2, the possible pairs of i and j are (i,j)=(0,1),(0,2).\nWhen (i,j)=(0,2), A_i+A_j=1+3=4. This is the maximum value, so the answer is 4.\n\nFor K=3, the possible pairs of i and j are (i,j)=(0,1),(0,2),(0,3),(1,2),(1,3),(2,3) .\nWhen (i,j)=(1,2), A_i+A_j=2+3=5. This is the maximum value, so the answer is 5.\n\nSample Input 2\n\n3\n10 71 84 33 6 47 23 25\n\nSample Output 2\n\n81\n94\n155\n155\n155\n155\n155\n\nSample Input 3\n\n4\n75 26 45 72 81 47 97 97 2 2 25 82 84 17 56 32\n\nSample Output 3\n\n101\n120\n147\n156\n156\n178\n194\n194\n194\n194\n194\n194\n194\n194\n194", "sample_input": "2\n1 2 3 1\n"}, "reference_outputs": ["3\n4\n5\n"], "source_document_id": "p03313", "source_text": "Score : 700 points\n\nProblem Statement\n\nThere is an integer sequence of length 2^N: A_0, A_1, ..., A_{2^N-1}. (Note that the sequence is 0-indexed.)\n\nFor every integer K satisfying 1 \\leq K \\leq 2^N-1, solve the following problem:\n\nLet i and j be integers. Find the maximum value of A_i + A_j where 0 \\leq i < j \\leq 2^N-1 and (i or j) \\leq K.\nHere, or denotes the bitwise OR.\n\nConstraints\n\n1 \\leq N \\leq 18\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_0 A_1 ... A_{2^N-1}\n\nOutput\n\nPrint 2^N-1 lines.\nIn the i-th line, print the answer of the problem above for K=i.\n\nSample Input 1\n\n2\n1 2 3 1\n\nSample Output 1\n\n3\n4\n5\n\nFor K=1, the only possible pair of i and j is (i,j)=(0,1), so the answer is A_0+A_1=1+2=3.\n\nFor K=2, the possible pairs of i and j are (i,j)=(0,1),(0,2).\nWhen (i,j)=(0,2), A_i+A_j=1+3=4. This is the maximum value, so the answer is 4.\n\nFor K=3, the possible pairs of i and j are (i,j)=(0,1),(0,2),(0,3),(1,2),(1,3),(2,3) .\nWhen (i,j)=(1,2), A_i+A_j=2+3=5. This is the maximum value, so the answer is 5.\n\nSample Input 2\n\n3\n10 71 84 33 6 47 23 25\n\nSample Output 2\n\n81\n94\n155\n155\n155\n155\n155\n\nSample Input 3\n\n4\n75 26 45 72 81 47 97 97 2 2 25 82 84 17 56 32\n\nSample Output 3\n\n101\n120\n147\n156\n156\n178\n194\n194\n194\n194\n194\n194\n194\n194\n194", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6460, "cpu_time_ms": 506, "memory_kb": 89448}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s130581159", "group_id": "codeNet:p03315", "input_text": "(defun func (x)\n (if x\n\t(+ (if (char= (car x) #\\+) 1 -1) (func (cdr x)))\n\t0))\n\n(princ (func (concatenate 'list (read-line))))\n", "language": "Lisp", "metadata": {"date": 1576898961, "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/s130581159.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s130581159", "user_id": "u493610446"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun func (x)\n (if x\n\t(+ (if (char= (car x) #\\+) 1 -1) (func (cdr x)))\n\t0))\n\n(princ (func (concatenate 'list (read-line))))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 3816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s305333217", "group_id": "codeNet:p03316", "input_text": "(defun parse-int-ex (n)\n (cond ((stringp n) (parse-integer n))\n ((char= n #\\1) 1)\n ((char= n #\\2) 2)\n ((char= n #\\3) 3)\n ((char= n #\\4) 4)\n ((char= n #\\5) 5)\n ((char= n #\\6) 6)\n ((char= n #\\7) 7)\n ((char= n #\\8) 8)\n ((char= n #\\9) 9)\n ((char= n #\\0) 0)))\n(defun f (k)\n (reduce #'+ (mapcar #'parse-int-ex (concatenate 'list (format nil \"~A\" k)))))\n(let* ((n (read)))\n (if (= 0 (mod n (f n))) (princ \"Yes\") (princ \"No\")))\n", "language": "Lisp", "metadata": {"date": 1560448861, "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/s305333217.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s305333217", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun parse-int-ex (n)\n (cond ((stringp n) (parse-integer n))\n ((char= n #\\1) 1)\n ((char= n #\\2) 2)\n ((char= n #\\3) 3)\n ((char= n #\\4) 4)\n ((char= n #\\5) 5)\n ((char= n #\\6) 6)\n ((char= n #\\7) 7)\n ((char= n #\\8) 8)\n ((char= n #\\9) 9)\n ((char= n #\\0) 0)))\n(defun f (k)\n (reduce #'+ (mapcar #'parse-int-ex (concatenate 'list (format nil \"~A\" k)))))\n(let* ((n (read)))\n (if (= 0 (mod n (f n))) (princ \"Yes\") (princ \"No\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 493, "cpu_time_ms": 29, "memory_kb": 7272}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s968581629", "group_id": "codeNet:p03317", "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 \"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 (k (read))\n (as (make-array n :element-type 'uint31))\n (res 0))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (labels ((frob (as)\n (unless (= 1 (aref as 0))\n (let ((prev 0)\n passed)\n (loop\n (when passed\n (setf (aref as prev) 1)\n (return))\n (loop for i from prev below (min (+ prev k) n)\n do (when (= (aref as i) 1)\n (setq passed t)))\n (incf res)\n (setq prev (min (- n 1) (+ prev (- k 1)))))))))\n (frob as)\n #>res\n (frob (reverse as))\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 \"4 3\n2 3 1 4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2 3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 3\n7 3 1 8 4 6 2 5\n\"\n \"4\n\")))\n", "language": "Lisp", "metadata": {"date": 1578196839, "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/s968581629.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s968581629", "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 \"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 (k (read))\n (as (make-array n :element-type 'uint31))\n (res 0))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (labels ((frob (as)\n (unless (= 1 (aref as 0))\n (let ((prev 0)\n passed)\n (loop\n (when passed\n (setf (aref as prev) 1)\n (return))\n (loop for i from prev below (min (+ prev k) n)\n do (when (= (aref as i) 1)\n (setq passed t)))\n (incf res)\n (setq prev (min (- n 1) (+ prev (- k 1)))))))))\n (frob as)\n #>res\n (frob (reverse as))\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 \"4 3\n2 3 1 4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 2 3\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 3\n7 3 1 8 4 6 2 5\n\"\n \"4\n\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5722, "cpu_time_ms": 217, "memory_kb": 24420}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s459871263", "group_id": "codeNet:p03318", "input_text": "(defun int-to-digit (n &key (base 10)) ;; (int-to-digit 123) => (1 2 3)\n (if (zerop n)\n `(0)\n (labels ((rec (n list)\n (if (= n 0)\n list\n (rec (floor n base) (cons (rem n base) list)))))\n (rec n nil))))\n\n(defun solver ()\n (let ((k (read)) (count 0) current (temp 1))\n (loop for i fixnum from 2 do\n (when (= count k) (return))\n (setf current (/ i (apply #'+ (int-to-digit i))))\n (when (<= temp current)\n (format t \"~a~%\" (1- i)) (incf count))\n (setf temp current))))\n\n(solver)\n", "language": "Lisp", "metadata": {"date": 1529805618, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03318.html", "problem_id": "p03318", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03318/input.txt", "sample_output_relpath": "derived/input_output/data/p03318/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03318/Lisp/s459871263.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s459871263", "user_id": "u183015556"}, "prompt_components": {"gold_output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n", "input_to_evaluate": "(defun int-to-digit (n &key (base 10)) ;; (int-to-digit 123) => (1 2 3)\n (if (zerop n)\n `(0)\n (labels ((rec (n list)\n (if (= n 0)\n list\n (rec (floor n base) (cons (rem n base) list)))))\n (rec n nil))))\n\n(defun solver ()\n (let ((k (read)) (count 0) current (temp 1))\n (loop for i fixnum from 2 do\n (when (= count k) (return))\n (setf current (/ i (apply #'+ (int-to-digit i))))\n (when (<= temp current)\n (format t \"~a~%\" (1- i)) (incf count))\n (setf temp current))))\n\n(solver)\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": "p03318", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 601, "cpu_time_ms": 365, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s220227739", "group_id": "codeNet:p03323", "input_text": "(format t \"~a~%\" (if (and (< (read) 9) (< (read) 9)) \"Yay!\" \":(\"))\n", "language": "Lisp", "metadata": {"date": 1529228982, "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/s220227739.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s220227739", "user_id": "u994767958"}, "prompt_components": {"gold_output": "Yay!\n", "input_to_evaluate": "(format t \"~a~%\" (if (and (< (read) 9) (< (read) 9)) \"Yay!\" \":(\"))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 70, "memory_kb": 9064}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s867968383", "group_id": "codeNet:p03325", "input_text": "(defun div2count (N)\n (let ((str (format nil \"~B\" N)))\n (1- (- (length str)\n\t (position #\\1 str :from-end t)) )))\n\n\n(defun solve (l)\n (reduce (lambda (x y) (+ x (div2count y)))\n\t l :initial-value 0) )\n\n(princ (solve (loop :repeat (read) :collect (read))))", "language": "Lisp", "metadata": {"date": 1584911376, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03325.html", "problem_id": "p03325", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03325/input.txt", "sample_output_relpath": "derived/input_output/data/p03325/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03325/Lisp/s867968383.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s867968383", "user_id": "u334552723"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun div2count (N)\n (let ((str (format nil \"~B\" N)))\n (1- (- (length str)\n\t (position #\\1 str :from-end t)) )))\n\n\n(defun solve (l)\n (reduce (lambda (x y) (+ x (div2count y)))\n\t l :initial-value 0) )\n\n(princ (solve (loop :repeat (read) :collect (read))))", "problem_context": "Score: 300 points\n\nProblem Statement\n\nAs AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}.\n\nSnuke, an employee, would like to play with this sequence.\n\nSpecifically, he would like to repeat the following operation as many times as possible:\n\nFor every i satisfying 1 \\leq i \\leq N, perform one of the following: \"divide a_i by 2\" and \"multiply a_i by 3\".\nHere, choosing \"multiply a_i by 3\" for every i is not allowed, and the value of a_i after the operation must be an integer.\n\nAt most how many operations can be performed?\n\nConstraints\n\nN is an integer between 1 and 10 \\ 000 (inclusive).\n\na_i is an integer between 1 and 1 \\ 000 \\ 000 \\ 000 (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 the maximum number of operations that Snuke can perform.\n\nSample Input 1\n\n3\n5 2 4\n\nSample Output 1\n\n3\n\nThe sequence is initially {5, 2, 4}. Three operations can be performed as follows:\n\nFirst, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {15, 6, 2}.\n\nNext, multiply a_1 by 3, divide a_2 by 2 and multiply a_3 by 3. The sequence is now {45, 3, 6}.\n\nFinally, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {135, 9, 3}.\n\nSample Input 2\n\n4\n631 577 243 199\n\nSample Output 2\n\n0\n\nNo operation can be performed since all the elements are odd. Thus, the answer is 0.\n\nSample Input 3\n\n10\n2184 2126 1721 1800 1024 2528 3360 1945 1280 1776\n\nSample Output 3\n\n39", "sample_input": "3\n5 2 4\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03325", "source_text": "Score: 300 points\n\nProblem Statement\n\nAs AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}.\n\nSnuke, an employee, would like to play with this sequence.\n\nSpecifically, he would like to repeat the following operation as many times as possible:\n\nFor every i satisfying 1 \\leq i \\leq N, perform one of the following: \"divide a_i by 2\" and \"multiply a_i by 3\".\nHere, choosing \"multiply a_i by 3\" for every i is not allowed, and the value of a_i after the operation must be an integer.\n\nAt most how many operations can be performed?\n\nConstraints\n\nN is an integer between 1 and 10 \\ 000 (inclusive).\n\na_i is an integer between 1 and 1 \\ 000 \\ 000 \\ 000 (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 the maximum number of operations that Snuke can perform.\n\nSample Input 1\n\n3\n5 2 4\n\nSample Output 1\n\n3\n\nThe sequence is initially {5, 2, 4}. Three operations can be performed as follows:\n\nFirst, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {15, 6, 2}.\n\nNext, multiply a_1 by 3, divide a_2 by 2 and multiply a_3 by 3. The sequence is now {45, 3, 6}.\n\nFinally, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {135, 9, 3}.\n\nSample Input 2\n\n4\n631 577 243 199\n\nSample Output 2\n\n0\n\nNo operation can be performed since all the elements are odd. Thus, the answer is 0.\n\nSample Input 3\n\n10\n2184 2126 1721 1800 1024 2528 3360 1945 1280 1776\n\nSample Output 3\n\n39", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 65, "memory_kb": 24936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s614303360", "group_id": "codeNet:p03325", "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(deftype uint nil `(integer 0 ,(expt 10 9)))\n\n(defun count-2-as-factor (num)\n (loop with i = 0\n until (oddp num)\n do (setf num (ash num -1))\n (incf i)\n finally (return i)))\n\n(defun main ()\n (let ((n (read)))\n (loop for i below n\n sum (count-2-as-factor (read)))))\n\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": 1529479971, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03325.html", "problem_id": "p03325", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03325/input.txt", "sample_output_relpath": "derived/input_output/data/p03325/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03325/Lisp/s614303360.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s614303360", "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(deftype uint nil `(integer 0 ,(expt 10 9)))\n\n(defun count-2-as-factor (num)\n (loop with i = 0\n until (oddp num)\n do (setf num (ash num -1))\n (incf i)\n finally (return i)))\n\n(defun main ()\n (let ((n (read)))\n (loop for i below n\n sum (count-2-as-factor (read)))))\n\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\nAs AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}.\n\nSnuke, an employee, would like to play with this sequence.\n\nSpecifically, he would like to repeat the following operation as many times as possible:\n\nFor every i satisfying 1 \\leq i \\leq N, perform one of the following: \"divide a_i by 2\" and \"multiply a_i by 3\".\nHere, choosing \"multiply a_i by 3\" for every i is not allowed, and the value of a_i after the operation must be an integer.\n\nAt most how many operations can be performed?\n\nConstraints\n\nN is an integer between 1 and 10 \\ 000 (inclusive).\n\na_i is an integer between 1 and 1 \\ 000 \\ 000 \\ 000 (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 the maximum number of operations that Snuke can perform.\n\nSample Input 1\n\n3\n5 2 4\n\nSample Output 1\n\n3\n\nThe sequence is initially {5, 2, 4}. Three operations can be performed as follows:\n\nFirst, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {15, 6, 2}.\n\nNext, multiply a_1 by 3, divide a_2 by 2 and multiply a_3 by 3. The sequence is now {45, 3, 6}.\n\nFinally, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {135, 9, 3}.\n\nSample Input 2\n\n4\n631 577 243 199\n\nSample Output 2\n\n0\n\nNo operation can be performed since all the elements are odd. Thus, the answer is 0.\n\nSample Input 3\n\n10\n2184 2126 1721 1800 1024 2528 3360 1945 1280 1776\n\nSample Output 3\n\n39", "sample_input": "3\n5 2 4\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03325", "source_text": "Score: 300 points\n\nProblem Statement\n\nAs AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}.\n\nSnuke, an employee, would like to play with this sequence.\n\nSpecifically, he would like to repeat the following operation as many times as possible:\n\nFor every i satisfying 1 \\leq i \\leq N, perform one of the following: \"divide a_i by 2\" and \"multiply a_i by 3\".\nHere, choosing \"multiply a_i by 3\" for every i is not allowed, and the value of a_i after the operation must be an integer.\n\nAt most how many operations can be performed?\n\nConstraints\n\nN is an integer between 1 and 10 \\ 000 (inclusive).\n\na_i is an integer between 1 and 1 \\ 000 \\ 000 \\ 000 (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 the maximum number of operations that Snuke can perform.\n\nSample Input 1\n\n3\n5 2 4\n\nSample Output 1\n\n3\n\nThe sequence is initially {5, 2, 4}. Three operations can be performed as follows:\n\nFirst, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {15, 6, 2}.\n\nNext, multiply a_1 by 3, divide a_2 by 2 and multiply a_3 by 3. The sequence is now {45, 3, 6}.\n\nFinally, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {135, 9, 3}.\n\nSample Input 2\n\n4\n631 577 243 199\n\nSample Output 2\n\n0\n\nNo operation can be performed since all the elements are odd. Thus, the answer is 0.\n\nSample Input 3\n\n10\n2184 2126 1721 1800 1024 2528 3360 1945 1280 1776\n\nSample Output 3\n\n39", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1430, "cpu_time_ms": 168, "memory_kb": 53736}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s496521033", "group_id": "codeNet:p03328", "input_text": "(defun fact (n)\n (if (< n 1)\n 0\n (+ n (fact (1- n)))))\n\n(defun solve (a b)\n (- (fact (- b a)) b))\n\n(princ (solve (read) (read)))\n(fresh-line)", "language": "Lisp", "metadata": {"date": 1593706747, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03328.html", "problem_id": "p03328", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03328/input.txt", "sample_output_relpath": "derived/input_output/data/p03328/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03328/Lisp/s496521033.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s496521033", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun fact (n)\n (if (< n 1)\n 0\n (+ n (fact (1- n)))))\n\n(defun solve (a b)\n (- (fact (- b a)) b))\n\n(princ (solve (read) (read)))\n(fresh-line)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIn some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.\n\nIt had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.\n\nAssuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.\n\nAssume also that the depth of the snow cover is always at least 1 meter.\n\nConstraints\n\n1 \\leq a < b < 499500(=1+2+3+...+999)\n\nAll values in input are integers.\n\nThere is no input that contradicts the assumption.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the depth of the snow cover is x meters, print x as an integer.\n\nSample Input 1\n\n8 13\n\nSample Output 1\n\n2\n\nThe heights of the two towers are 10 meters and 15 meters, respectively.\nThus, we can see that the depth of the snow cover is 2 meters.\n\nSample Input 2\n\n54 65\n\nSample Output 2\n\n1", "sample_input": "8 13\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03328", "source_text": "Score : 200 points\n\nProblem Statement\n\nIn some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.\n\nIt had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.\n\nAssuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.\n\nAssume also that the depth of the snow cover is always at least 1 meter.\n\nConstraints\n\n1 \\leq a < b < 499500(=1+2+3+...+999)\n\nAll values in input are integers.\n\nThere is no input that contradicts the assumption.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the depth of the snow cover is x meters, print x as an integer.\n\nSample Input 1\n\n8 13\n\nSample Output 1\n\n2\n\nThe heights of the two towers are 10 meters and 15 meters, respectively.\nThus, we can see that the depth of the snow cover is 2 meters.\n\nSample Input 2\n\n54 65\n\nSample Output 2\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 21, "memory_kb": 24228}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s926169388", "group_id": "codeNet:p03328", "input_text": "(let ((a (read))\n (b (read)))\n (princ (- (/ (* (- b a) (- b a -1)) 2) b)))", "language": "Lisp", "metadata": {"date": 1533767582, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03328.html", "problem_id": "p03328", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03328/input.txt", "sample_output_relpath": "derived/input_output/data/p03328/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03328/Lisp/s926169388.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s926169388", "user_id": "u913204306"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (princ (- (/ (* (- b a) (- b a -1)) 2) b)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIn some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.\n\nIt had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.\n\nAssuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.\n\nAssume also that the depth of the snow cover is always at least 1 meter.\n\nConstraints\n\n1 \\leq a < b < 499500(=1+2+3+...+999)\n\nAll values in input are integers.\n\nThere is no input that contradicts the assumption.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the depth of the snow cover is x meters, print x as an integer.\n\nSample Input 1\n\n8 13\n\nSample Output 1\n\n2\n\nThe heights of the two towers are 10 meters and 15 meters, respectively.\nThus, we can see that the depth of the snow cover is 2 meters.\n\nSample Input 2\n\n54 65\n\nSample Output 2\n\n1", "sample_input": "8 13\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03328", "source_text": "Score : 200 points\n\nProblem Statement\n\nIn some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.\n\nIt had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.\n\nAssuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.\n\nAssume also that the depth of the snow cover is always at least 1 meter.\n\nConstraints\n\n1 \\leq a < b < 499500(=1+2+3+...+999)\n\nAll values in input are integers.\n\nThere is no input that contradicts the assumption.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the depth of the snow cover is x meters, print x as an integer.\n\nSample Input 1\n\n8 13\n\nSample Output 1\n\n2\n\nThe heights of the two towers are 10 meters and 15 meters, respectively.\nThus, we can see that the depth of the snow cover is 2 meters.\n\nSample Input 2\n\n54 65\n\nSample Output 2\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 3940}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s154502564", "group_id": "codeNet:p03328", "input_text": "(let ((a (read))\n (b (read)))\n (princ (- (apply #'+ (loop for i from 1 upto (- b a) collect i)) b)))", "language": "Lisp", "metadata": {"date": 1533766913, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03328.html", "problem_id": "p03328", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03328/input.txt", "sample_output_relpath": "derived/input_output/data/p03328/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03328/Lisp/s154502564.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s154502564", "user_id": "u913204306"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (princ (- (apply #'+ (loop for i from 1 upto (- b a) collect i)) b)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIn some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.\n\nIt had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.\n\nAssuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.\n\nAssume also that the depth of the snow cover is always at least 1 meter.\n\nConstraints\n\n1 \\leq a < b < 499500(=1+2+3+...+999)\n\nAll values in input are integers.\n\nThere is no input that contradicts the assumption.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the depth of the snow cover is x meters, print x as an integer.\n\nSample Input 1\n\n8 13\n\nSample Output 1\n\n2\n\nThe heights of the two towers are 10 meters and 15 meters, respectively.\nThus, we can see that the depth of the snow cover is 2 meters.\n\nSample Input 2\n\n54 65\n\nSample Output 2\n\n1", "sample_input": "8 13\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03328", "source_text": "Score : 200 points\n\nProblem Statement\n\nIn some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.\n\nIt had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.\n\nAssuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.\n\nAssume also that the depth of the snow cover is always at least 1 meter.\n\nConstraints\n\n1 \\leq a < b < 499500(=1+2+3+...+999)\n\nAll values in input are integers.\n\nThere is no input that contradicts the assumption.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the depth of the snow cover is x meters, print x as an integer.\n\nSample Input 1\n\n8 13\n\nSample Output 1\n\n2\n\nThe heights of the two towers are 10 meters and 15 meters, respectively.\nThus, we can see that the depth of the snow cover is 2 meters.\n\nSample Input 2\n\n54 65\n\nSample Output 2\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 113, "memory_kb": 10724}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s812661482", "group_id": "codeNet:p03328", "input_text": "(princ(/(-(expt(-(setq a(read))(setq b(read)))2)a b)2))", "language": "Lisp", "metadata": {"date": 1528681998, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03328.html", "problem_id": "p03328", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03328/input.txt", "sample_output_relpath": "derived/input_output/data/p03328/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03328/Lisp/s812661482.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s812661482", "user_id": "u657913472"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ(/(-(expt(-(setq a(read))(setq b(read)))2)a b)2))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIn some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.\n\nIt had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.\n\nAssuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.\n\nAssume also that the depth of the snow cover is always at least 1 meter.\n\nConstraints\n\n1 \\leq a < b < 499500(=1+2+3+...+999)\n\nAll values in input are integers.\n\nThere is no input that contradicts the assumption.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the depth of the snow cover is x meters, print x as an integer.\n\nSample Input 1\n\n8 13\n\nSample Output 1\n\n2\n\nThe heights of the two towers are 10 meters and 15 meters, respectively.\nThus, we can see that the depth of the snow cover is 2 meters.\n\nSample Input 2\n\n54 65\n\nSample Output 2\n\n1", "sample_input": "8 13\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03328", "source_text": "Score : 200 points\n\nProblem Statement\n\nIn some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.\n\nIt had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.\n\nAssuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.\n\nAssume also that the depth of the snow cover is always at least 1 meter.\n\nConstraints\n\n1 \\leq a < b < 499500(=1+2+3+...+999)\n\nAll values in input are integers.\n\nThere is no input that contradicts the assumption.\n\nInput\n\nInput is given from Standard Input in the following format:\n\na b\n\nOutput\n\nIf the depth of the snow cover is x meters, print x as an integer.\n\nSample Input 1\n\n8 13\n\nSample Output 1\n\n2\n\nThe heights of the two towers are 10 meters and 15 meters, respectively.\nThus, we can see that the depth of the snow cover is 2 meters.\n\nSample Input 2\n\n54 65\n\nSample Output 2\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 386, "memory_kb": 8292}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s110490898", "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 10)\n :initial-element *inf*)))\n (setf (aref memo 0) 0)\n (loop for i from 0 to n do\n (loop with k = 9 while (<= (+ i k) n) do\n (setf (aref memo (+ i k))\n (min (1+ (aref memo i))\n (aref memo (+ i k))))\n (setf k (* k 9)))\n (loop with k = 6 while (<= (+ i k) n) do\n (setf (aref memo (+ i k))\n (min (1+ (aref memo i))\n (aref memo (+ i k))))\n (setf k (* k 6)))\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": 1600092807, "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/s110490898.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s110490898", "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 10)\n :initial-element *inf*)))\n (setf (aref memo 0) 0)\n (loop for i from 0 to n do\n (loop with k = 9 while (<= (+ i k) n) do\n (setf (aref memo (+ i k))\n (min (1+ (aref memo i))\n (aref memo (+ i k))))\n (setf k (* k 9)))\n (loop with k = 6 while (<= (+ i k) n) do\n (setf (aref memo (+ i k))\n (min (1+ (aref memo i))\n (aref memo (+ i k))))\n (setf k (* k 6)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4056, "cpu_time_ms": 51, "memory_kb": 26744}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s089731239", "group_id": "codeNet:p03337", "input_text": "(let ((a (read))\n (b (read)))\n(princ (max (+ a b)(- a b)(* a b))))", "language": "Lisp", "metadata": {"date": 1550717369, "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/s089731239.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s089731239", "user_id": "u994767958"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n(princ (max (+ a b)(- 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 124, "memory_kb": 11620}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s434285971", "group_id": "codeNet:p03337", "input_text": "(let ((a (read))\n (b (read)))\n (princ (max (+ a b) (- a b) (* a b))))", "language": "Lisp", "metadata": {"date": 1533777997, "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/s434285971.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s434285971", "user_id": "u913204306"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (princ (max (+ a b) (- 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 120, "memory_kb": 11620}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s711849441", "group_id": "codeNet:p03338", "input_text": "(defun duplicate-char-counter (str separator)\n (labels ((duplicate-char-counter (char-list cnt)\n (if char-list\n (duplicate-char-counter (cdr char-list)\n (if (find (car char-list) str :start separator :test #'char=)\n (1+ cnt)\n cnt))\n cnt)))\n (let ((char-list (coerce (remove-duplicates (subseq str 0 separator)) 'list)))\n (duplicate-char-counter char-list 0))))\n\n(princ (loop for separator from 1 upto (1- (read))\n with input-str = (read-line)\n maximize (duplicate-char-counter input-str separator)))", "language": "Lisp", "metadata": {"date": 1533806335, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03338.html", "problem_id": "p03338", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03338/input.txt", "sample_output_relpath": "derived/input_output/data/p03338/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03338/Lisp/s711849441.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s711849441", "user_id": "u913204306"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun duplicate-char-counter (str separator)\n (labels ((duplicate-char-counter (char-list cnt)\n (if char-list\n (duplicate-char-counter (cdr char-list)\n (if (find (car char-list) str :start separator :test #'char=)\n (1+ cnt)\n cnt))\n cnt)))\n (let ((char-list (coerce (remove-duplicates (subseq str 0 separator)) 'list)))\n (duplicate-char-counter char-list 0))))\n\n(princ (loop for separator from 1 upto (1- (read))\n with input-str = (read-line)\n maximize (duplicate-char-counter input-str separator)))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of lowercase English letters.\nWe will cut this string at one position into two strings X and Y.\nHere, we would like to maximize the number of different letters contained in both X and Y.\nFind the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.\n\nConstraints\n\n2 \\leq N \\leq 100\n\n|S| = N\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the largest possible number of different letters contained in both X and Y.\n\nSample Input 1\n\n6\naabbca\n\nSample Output 1\n\n2\n\nIf we cut the string between the third and fourth letters into X = aab and Y = bca, the letters contained in both X and Y are a and b.\nThere will never be three or more different letters contained in both X and Y, so the answer is 2.\n\nSample Input 2\n\n10\naaaaaaaaaa\n\nSample Output 2\n\n1\n\nHowever we divide S, only a will be contained in both X and Y.\n\nSample Input 3\n\n45\ntgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir\n\nSample Output 3\n\n9", "sample_input": "6\naabbca\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03338", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given a string S of length N consisting of lowercase English letters.\nWe will cut this string at one position into two strings X and Y.\nHere, we would like to maximize the number of different letters contained in both X and Y.\nFind the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.\n\nConstraints\n\n2 \\leq N \\leq 100\n\n|S| = N\n\nS consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS\n\nOutput\n\nPrint the largest possible number of different letters contained in both X and Y.\n\nSample Input 1\n\n6\naabbca\n\nSample Output 1\n\n2\n\nIf we cut the string between the third and fourth letters into X = aab and Y = bca, the letters contained in both X and Y are a and b.\nThere will never be three or more different letters contained in both X and Y, so the answer is 2.\n\nSample Input 2\n\n10\naaaaaaaaaa\n\nSample Output 2\n\n1\n\nHowever we divide S, only a will be contained in both X and Y.\n\nSample Input 3\n\n45\ntgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir\n\nSample Output 3\n\n9", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 704, "cpu_time_ms": 132, "memory_kb": 12260}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s240871079", "group_id": "codeNet:p03341", "input_text": "(defun solve (N arr)\n (let (tmp)\n (loop for i from (1- N) downto 0\n with sum = 0\n do (push sum tmp)\n if (eq (aref arr i) #\\E) do (incf sum))\n (loop for x across arr with sum = 0\n for y in tmp\n minimize (+ y sum)\n if (eq x #\\W) do (incf sum))))\n\n(princ (solve (read) (concatenate 'vector (read-line))))", "language": "Lisp", "metadata": {"date": 1588286650, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03341.html", "problem_id": "p03341", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03341/input.txt", "sample_output_relpath": "derived/input_output/data/p03341/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03341/Lisp/s240871079.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s240871079", "user_id": "u334552723"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defun solve (N arr)\n (let (tmp)\n (loop for i from (1- N) downto 0\n with sum = 0\n do (push sum tmp)\n if (eq (aref arr i) #\\E) do (incf sum))\n (loop for x across arr with sum = 0\n for y in tmp\n minimize (+ y sum)\n if (eq x #\\W) do (incf sum))))\n\n(princ (solve (read) (concatenate 'vector (read-line))))", "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": "p03341", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 57, "memory_kb": 14696}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s089317954", "group_id": "codeNet:p03346", "input_text": "(defun solve (p)\n (let ((last (aref p 0))\n (amax 0)\n idx\n (a 0))\n (loop for i from 1 below (length p)\n do (let ((p2 (aref p i)))\n (if (< p2 last)\n (if (< amax p2)\n (setf amax p2\n idx i))\n (setf last p2))))\n (when idx \n (loop for i to idx\n do (when (<= (aref p i) amax)\n (incf a))))\n a))\n\n(let ((p (make-array (read))))\n (loop for i below (length p)\n do (setf (aref p i) (read)))\n (princ (solve p))\n (terpri))\n", "language": "Lisp", "metadata": {"date": 1526869966, "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/s089317954.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s089317954", "user_id": "u188771036"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve (p)\n (let ((last (aref p 0))\n (amax 0)\n idx\n (a 0))\n (loop for i from 1 below (length p)\n do (let ((p2 (aref p i)))\n (if (< p2 last)\n (if (< amax p2)\n (setf amax p2\n idx i))\n (setf last p2))))\n (when idx \n (loop for i to idx\n do (when (<= (aref p i) amax)\n (incf a))))\n a))\n\n(let ((p (make-array (read))))\n (loop for i below (length p)\n do (setf (aref p i) (read)))\n (princ (solve p))\n (terpri))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 525, "memory_kb": 69732}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s521731073", "group_id": "codeNet:p03351", "input_text": "(let ((a (read))\n (b (read))\n (c (read))\n (d (read)))\n (princ (if (or (<= (abs (- c a)) d)\n (and (<= (abs (- b a)) d)\n (<= (abs (- c b)) d)))\n \"Yes\"\n \"No\")))", "language": "Lisp", "metadata": {"date": 1533807420, "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/s521731073.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s521731073", "user_id": "u913204306"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read))\n (d (read)))\n (princ (if (or (<= (abs (- c a)) d)\n (and (<= (abs (- b a)) d)\n (<= (abs (- c b)) d)))\n \"Yes\"\n \"No\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 101, "memory_kb": 11108}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s704169118", "group_id": "codeNet:p03353", "input_text": "(let* ((s (read-line))\n (k (read))\n (l (length s))\n (lset))\n (loop for i from 1 to k \n do (loop for j to (- l i)\n do (pushnew (subseq s j (+ i j)) lset\n :test #'equal)))\n (format t \"~A~%\"\n (nth (1- k) (sort lset #'string<))))", "language": "Lisp", "metadata": {"date": 1570420916, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03353.html", "problem_id": "p03353", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03353/input.txt", "sample_output_relpath": "derived/input_output/data/p03353/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03353/Lisp/s704169118.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s704169118", "user_id": "u672956630"}, "prompt_components": {"gold_output": "b\n", "input_to_evaluate": "(let* ((s (read-line))\n (k (read))\n (l (length s))\n (lset))\n (loop for i from 1 to k \n do (loop for j to (- l i)\n do (pushnew (subseq s j (+ i j)) lset\n :test #'equal)))\n (format t \"~A~%\"\n (nth (1- k) (sort lset #'string<))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given a string s.\nAmong the different substrings of s, print the K-th lexicographically smallest one.\n\nA substring of s is a string obtained by taking out a non-empty contiguous part in s.\nFor example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not.\nAlso, we say that substrings are different when they are different as strings.\n\nLet X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \\neq y_{j}.\n\nConstraints\n\n1 ≤ |s| ≤ 5000\n\ns consists of lowercase English letters.\n\n1 ≤ K ≤ 5\n\ns has at least K different substrings.\n\nPartial Score\n\n200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nK\n\nOutput\n\nPrint the K-th lexicographically smallest substring of K.\n\nSample Input 1\n\naba\n4\n\nSample Output 1\n\nb\n\ns has five substrings: a, b, ab, ba and aba.\nAmong them, we should print the fourth smallest one, b.\nNote that we do not count a twice.\n\nSample Input 2\n\natcoderandatcodeer\n5\n\nSample Output 2\n\nandat\n\nSample Input 3\n\nz\n1\n\nSample Output 3\n\nz", "sample_input": "aba\n4\n"}, "reference_outputs": ["b\n"], "source_document_id": "p03353", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given a string s.\nAmong the different substrings of s, print the K-th lexicographically smallest one.\n\nA substring of s is a string obtained by taking out a non-empty contiguous part in s.\nFor example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not.\nAlso, we say that substrings are different when they are different as strings.\n\nLet X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \\neq y_{j}.\n\nConstraints\n\n1 ≤ |s| ≤ 5000\n\ns consists of lowercase English letters.\n\n1 ≤ K ≤ 5\n\ns has at least K different substrings.\n\nPartial Score\n\n200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nK\n\nOutput\n\nPrint the K-th lexicographically smallest substring of K.\n\nSample Input 1\n\naba\n4\n\nSample Output 1\n\nb\n\ns has five substrings: a, b, ab, ba and aba.\nAmong them, we should print the fourth smallest one, b.\nNote that we do not count a twice.\n\nSample Input 2\n\natcoderandatcodeer\n5\n\nSample Output 2\n\nandat\n\nSample Input 3\n\nz\n1\n\nSample Output 3\n\nz", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 305, "cpu_time_ms": 2104, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s432032893", "group_id": "codeNet:p03353", "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(declaim (inline dict<))\n(defun dict< (str1 str2)\n (declare #.OPT\n (base-string str1 str2))\n (let* ((len1 (length str1))\n (len2 (length str2))\n (len (min len1 len2)))\n (loop for i below len\n for c1 = (aref str1 i)\n for c2 = (aref str2 i)\n do (cond ((char< c1 c2) (return t))\n ((char> c1 c2) (return nil)))\n finally (return (if (< len1 len2) t nil)))))\n\n(declaim (inline enum-words))\n(defun enum-words (source)\n (declare #.OPT\n (base-string source))\n (let ((len (length source))\n res)\n (dotimes (idx1 len res)\n (loop for width from 1 to 5\n while (<= (+ idx1 width) len)\n do (push (make-array width\n :element-type 'base-char\n :displaced-to source\n :displaced-index-offset idx1)\n res)))))\n\n(defun get-min (tmp-min lst)\n (declare #.OPT)\n (cond ((null lst) tmp-min)\n ((dict< (car lst) tmp-min) (get-min (car lst) (cdr lst)))\n (t (get-min tmp-min (cdr lst)))))\n\n(defun get-nth-min (n lst)\n (declare #.OPT\n (uint n))\n (let ((min (get-min (car lst) lst)))\n (if (= n 1)\n min\n (get-nth-min (- n 1)\n (delete min lst :test #'string=)))))\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n(defun main ()\n (declare #.OPT)\n (let ((str (coerce (read-line) 'base-string))\n (n (read)))\n (write-line (get-nth-min n (enum-words str)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1527330243, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03353.html", "problem_id": "p03353", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03353/input.txt", "sample_output_relpath": "derived/input_output/data/p03353/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03353/Lisp/s432032893.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s432032893", "user_id": "u352600849"}, "prompt_components": {"gold_output": "b\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(declaim (inline dict<))\n(defun dict< (str1 str2)\n (declare #.OPT\n (base-string str1 str2))\n (let* ((len1 (length str1))\n (len2 (length str2))\n (len (min len1 len2)))\n (loop for i below len\n for c1 = (aref str1 i)\n for c2 = (aref str2 i)\n do (cond ((char< c1 c2) (return t))\n ((char> c1 c2) (return nil)))\n finally (return (if (< len1 len2) t nil)))))\n\n(declaim (inline enum-words))\n(defun enum-words (source)\n (declare #.OPT\n (base-string source))\n (let ((len (length source))\n res)\n (dotimes (idx1 len res)\n (loop for width from 1 to 5\n while (<= (+ idx1 width) len)\n do (push (make-array width\n :element-type 'base-char\n :displaced-to source\n :displaced-index-offset idx1)\n res)))))\n\n(defun get-min (tmp-min lst)\n (declare #.OPT)\n (cond ((null lst) tmp-min)\n ((dict< (car lst) tmp-min) (get-min (car lst) (cdr lst)))\n (t (get-min tmp-min (cdr lst)))))\n\n(defun get-nth-min (n lst)\n (declare #.OPT\n (uint n))\n (let ((min (get-min (car lst) lst)))\n (if (= n 1)\n min\n (get-nth-min (- n 1)\n (delete min lst :test #'string=)))))\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n(defun main ()\n (declare #.OPT)\n (let ((str (coerce (read-line) 'base-string))\n (n (read)))\n (write-line (get-nth-min n (enum-words str)))))\n\n#-swank(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given a string s.\nAmong the different substrings of s, print the K-th lexicographically smallest one.\n\nA substring of s is a string obtained by taking out a non-empty contiguous part in s.\nFor example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not.\nAlso, we say that substrings are different when they are different as strings.\n\nLet X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \\neq y_{j}.\n\nConstraints\n\n1 ≤ |s| ≤ 5000\n\ns consists of lowercase English letters.\n\n1 ≤ K ≤ 5\n\ns has at least K different substrings.\n\nPartial Score\n\n200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nK\n\nOutput\n\nPrint the K-th lexicographically smallest substring of K.\n\nSample Input 1\n\naba\n4\n\nSample Output 1\n\nb\n\ns has five substrings: a, b, ab, ba and aba.\nAmong them, we should print the fourth smallest one, b.\nNote that we do not count a twice.\n\nSample Input 2\n\natcoderandatcodeer\n5\n\nSample Output 2\n\nandat\n\nSample Input 3\n\nz\n1\n\nSample Output 3\n\nz", "sample_input": "aba\n4\n"}, "reference_outputs": ["b\n"], "source_document_id": "p03353", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given a string s.\nAmong the different substrings of s, print the K-th lexicographically smallest one.\n\nA substring of s is a string obtained by taking out a non-empty contiguous part in s.\nFor example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not.\nAlso, we say that substrings are different when they are different as strings.\n\nLet X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \\neq y_{j}.\n\nConstraints\n\n1 ≤ |s| ≤ 5000\n\ns consists of lowercase English letters.\n\n1 ≤ K ≤ 5\n\ns has at least K different substrings.\n\nPartial Score\n\n200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns\nK\n\nOutput\n\nPrint the K-th lexicographically smallest substring of K.\n\nSample Input 1\n\naba\n4\n\nSample Output 1\n\nb\n\ns has five substrings: a, b, ab, ba and aba.\nAmong them, we should print the fourth smallest one, b.\nNote that we do not count a twice.\n\nSample Input 2\n\natcoderandatcodeer\n5\n\nSample Output 2\n\nandat\n\nSample Input 3\n\nz\n1\n\nSample Output 3\n\nz", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1889, "cpu_time_ms": 276, "memory_kb": 20068}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s344374603", "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 (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 (optimize (speed 3))\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(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) sucbv-count))\n(defun sucbv-count (sucbv value end)\n \"Counts the number of VALUEs in the range [0, END)\"\n (declare (optimize (speed 3))\n (bit value)\n ((integer 0 #.most-positive-fixnum) end))\n (let ((count1 (sucbv-rank sucbv end)))\n (if (= value 1)\n count1\n (- end count1))))\n\n(defun sucbv-select (sucbv num)\n \"Detects the position of (1-based) NUM-th 1 in SUCBV. (SUCBV-SELECT 0) always\nreturns 0.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) num))\n (let* ((storage (sucbv-storage sucbv))\n (chunks (sucbv-chunks sucbv))\n (blocks (sucbv-blocks sucbv))\n (chunk-size (length chunks)))\n (unless (<= num (aref chunks (- chunk-size 1)))\n ;; FIXME: introduce condition class\n (error \"~&There aren't ~W 1's in ~W\" num sucbv))\n (labels ((chunk-bisect (ok ng)\n (declare ((unsigned-byte 32) ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (<= num (aref chunks mid))\n (chunk-bisect ok mid)\n (chunk-bisect mid ng))))))\n (let* ((chunk-idx (chunk-bisect 0 chunk-size))\n (num (- num (aref chunks chunk-idx))))\n (labels ((block-bisect (ok ng)\n (declare ((unsigned-byte 32) ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (<= num (aref blocks chunk-idx mid))\n (block-bisect ok mid)\n (block-bisect mid ng))))))\n (let* ((block-idx (block-bisect 0 +block-number+))\n (num (- num (aref blocks chunk-idx block-idx)))\n (word-pos (+ block-idx (* chunk-idx +block-number+)))\n (word (sb-kernel:%vector-raw-bits storage word-pos)))\n (labels ((pos-bisect (ok ng)\n (declare ((integer 0 64) ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (<= num (logcount (ldb (byte mid 0) word)))\n (pos-bisect ok mid)\n (pos-bisect mid ng))))))\n (let ((pos (pos-bisect 0 64)))\n (+ (* 64 word-pos) pos)))))))))\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(defun wavelet-range-count (wmatrix lo hi &key (start 0) end)\n (declare (optimize (speed 3))\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 (assert (<= lo hi))\n (unless (<= start end (wavelet-length wmatrix))\n (error 'invalid-wavelet-index-error :index (cons start end) :wavelet 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 (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 12 ws-plan))\n (bs-plan (make-wavelet 12 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": 1578826046, "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/s344374603.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s344374603", "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 (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 (optimize (speed 3))\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(declaim (ftype (function * (values (integer 0 #.most-positive-fixnum) &optional)) sucbv-count))\n(defun sucbv-count (sucbv value end)\n \"Counts the number of VALUEs in the range [0, END)\"\n (declare (optimize (speed 3))\n (bit value)\n ((integer 0 #.most-positive-fixnum) end))\n (let ((count1 (sucbv-rank sucbv end)))\n (if (= value 1)\n count1\n (- end count1))))\n\n(defun sucbv-select (sucbv num)\n \"Detects the position of (1-based) NUM-th 1 in SUCBV. (SUCBV-SELECT 0) always\nreturns 0.\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) num))\n (let* ((storage (sucbv-storage sucbv))\n (chunks (sucbv-chunks sucbv))\n (blocks (sucbv-blocks sucbv))\n (chunk-size (length chunks)))\n (unless (<= num (aref chunks (- chunk-size 1)))\n ;; FIXME: introduce condition class\n (error \"~&There aren't ~W 1's in ~W\" num sucbv))\n (labels ((chunk-bisect (ok ng)\n (declare ((unsigned-byte 32) ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (<= num (aref chunks mid))\n (chunk-bisect ok mid)\n (chunk-bisect mid ng))))))\n (let* ((chunk-idx (chunk-bisect 0 chunk-size))\n (num (- num (aref chunks chunk-idx))))\n (labels ((block-bisect (ok ng)\n (declare ((unsigned-byte 32) ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (<= num (aref blocks chunk-idx mid))\n (block-bisect ok mid)\n (block-bisect mid ng))))))\n (let* ((block-idx (block-bisect 0 +block-number+))\n (num (- num (aref blocks chunk-idx block-idx)))\n (word-pos (+ block-idx (* chunk-idx +block-number+)))\n (word (sb-kernel:%vector-raw-bits storage word-pos)))\n (labels ((pos-bisect (ok ng)\n (declare ((integer 0 64) ok ng))\n (if (<= (- ng ok) 1)\n ok\n (let ((mid (ash (+ ok ng) -1)))\n (if (<= num (logcount (ldb (byte mid 0) word)))\n (pos-bisect ok mid)\n (pos-bisect mid ng))))))\n (let ((pos (pos-bisect 0 64)))\n (+ (* 64 word-pos) pos)))))))))\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(defun wavelet-range-count (wmatrix lo hi &key (start 0) end)\n (declare (optimize (speed 3))\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 (assert (<= lo hi))\n (unless (<= start end (wavelet-length wmatrix))\n (error 'invalid-wavelet-index-error :index (cons start end) :wavelet 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 (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 12 ws-plan))\n (bs-plan (make-wavelet 12 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 17495, "cpu_time_ms": 2105, "memory_kb": 53988}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s828872120", "group_id": "codeNet:p03359", "input_text": "(let ((a (read))\n (b (read)))\n (if (> a b)\n (format t \"~A\" (1- a))\n (format t \"~A\" a)))", "language": "Lisp", "metadata": {"date": 1539899882, "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/s828872120.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s828872120", "user_id": "u610490393"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (if (> a b)\n (format t \"~A\" (1- a))\n (format t \"~A\" a)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 11744}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s075523376", "group_id": "codeNet:p03359", "input_text": "(let ((ans (- (read) 1))\n (n (read)))\n (format t \"~A~%\" (if (< n ans) ans (1+ ans))))", "language": "Lisp", "metadata": {"date": 1525578005, "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/s075523376.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s075523376", "user_id": "u994767958"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((ans (- (read) 1))\n (n (read)))\n (format t \"~A~%\" (if (< n ans) ans (1+ ans))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 90, "cpu_time_ms": 11, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s363541375", "group_id": "codeNet:p03359", "input_text": "(defun sieve (n)\n (let ((is-prime (make-array (1+ n)\n :initial-element t))\n (primes '()))\n (setf (svref is-prime 0) nil)\n (setf (svref is-prime 1) nil)\n (loop for i from 2 to n\n do (when (svref is-prime i)\n (push i primes)\n (loop for j from (* 2 i) to n by i\n do (setf (svref is-prime j) nil))))\n (nreverse primes)))\n\n(defparameter goods\n (remove-if (lambda (n) (/= (mod n 5) 1))\n (sieve 55555)))\n\n(defparameter n (read))\n(format t \"~{~a~^ ~}~%\"\n (subseq goods 0 n))\n", "language": "Lisp", "metadata": {"date": 1525575501, "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/s363541375.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s363541375", "user_id": "u390181802"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun sieve (n)\n (let ((is-prime (make-array (1+ n)\n :initial-element t))\n (primes '()))\n (setf (svref is-prime 0) nil)\n (setf (svref is-prime 1) nil)\n (loop for i from 2 to n\n do (when (svref is-prime i)\n (push i primes)\n (loop for j from (* 2 i) to n by i\n do (setf (svref is-prime j) nil))))\n (nreverse primes)))\n\n(defparameter goods\n (remove-if (lambda (n) (/= (mod n 5) 1))\n (sieve 55555)))\n\n(defparameter n (read))\n(format t \"~{~a~^ ~}~%\"\n (subseq goods 0 n))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 593, "cpu_time_ms": 131, "memory_kb": 16996}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s486764852", "group_id": "codeNet:p03359", "input_text": "(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\n(defun readline-to-list ()\n (let ((str (read-line *standard-input* nil)))\n (cond\n ((null str) nil)\n ((string= str \"\") nil)\n (t (cons str (readline-to-list))))))\n\n\n(defun takahashi (a b)\n (let ((result (+ (parse-integer a) (if (>= (parse-integer b) (parse-integer a)) 0 -1))))\n (format t \"~A~%\" result)))\n\n(apply #'takahashi (split-string (read-line)))\n", "language": "Lisp", "metadata": {"date": 1525570771, "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/s486764852.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s486764852", "user_id": "u940017040"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(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\n(defun readline-to-list ()\n (let ((str (read-line *standard-input* nil)))\n (cond\n ((null str) nil)\n ((string= str \"\") nil)\n (t (cons str (readline-to-list))))))\n\n\n(defun takahashi (a b)\n (let ((result (+ (parse-integer a) (if (>= (parse-integer b) (parse-integer a)) 0 -1))))\n (format t \"~A~%\" result)))\n\n(apply #'takahashi (split-string (read-line)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 30, "memory_kb": 4964}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s501660531", "group_id": "codeNet:p03359", "input_text": "(defun solver ()\n (let* ((a (read)) (b (read)))\n (if (>= b a)\n (format t \"~a~%\" a)\n (format t \"~a~%\" (1- a)))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1525569206, "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/s501660531.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s501660531", "user_id": "u183015556"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defun solver ()\n (let* ((a (read)) (b (read)))\n (if (>= b a)\n (format t \"~a~%\" a)\n (format t \"~a~%\" (1- a)))))\n\n(solver)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 492, "memory_kb": 12260}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s793931348", "group_id": "codeNet:p03360", "input_text": "(setq a(read))\n(setq b(read))\n(setq c(read))\n(princ(+ a b c(*(max a b c)(1-(expt 2(read))))))", "language": "Lisp", "metadata": {"date": 1533045070, "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/s793931348.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s793931348", "user_id": "u657913472"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": "(setq a(read))\n(setq b(read))\n(setq c(read))\n(princ(+ a b c(*(max a b c)(1-(expt 2(read))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 10, "memory_kb": 3428}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s624485229", "group_id": "codeNet:p03360", "input_text": "(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\n(defun readline-to-list ()\n (let ((str (read-line *standard-input* nil)))\n (cond\n ((null str) nil)\n ((string= str \"\") nil)\n (t (cons str (readline-to-list))))))\n\n\n(defun MaximumSum (k a b c)\n (let* ((sortedList (sort (list (parse-integer c) (parse-integer b) (parse-integer a)) #'>)) (m (car sortedList)))\n (dotimes (i (parse-integer k)) (setf m (* 2 m)))\n (format t \"~A~%\" (+ m (cadr sortedList) (caddr sortedList)))))\n\n(let* ((r-list (readline-to-list))\n (tmp (split-string (car r-list)))\n (real-list (cons (cadr r-list) tmp)))\n (apply #'MaximumSum real-list))\n\n", "language": "Lisp", "metadata": {"date": 1525573663, "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/s624485229.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s624485229", "user_id": "u940017040"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": "(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\n(defun readline-to-list ()\n (let ((str (read-line *standard-input* nil)))\n (cond\n ((null str) nil)\n ((string= str \"\") nil)\n (t (cons str (readline-to-list))))))\n\n\n(defun MaximumSum (k a b c)\n (let* ((sortedList (sort (list (parse-integer c) (parse-integer b) (parse-integer a)) #'>)) (m (car sortedList)))\n (dotimes (i (parse-integer k)) (setf m (* 2 m)))\n (format t \"~A~%\" (+ m (cadr sortedList) (caddr sortedList)))))\n\n(let* ((r-list (readline-to-list))\n (tmp (split-string (car r-list)))\n (real-list (cons (cadr r-list) tmp)))\n (apply #'MaximumSum real-list))\n\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 909, "cpu_time_ms": 315, "memory_kb": 16104}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s171204053", "group_id": "codeNet:p03360", "input_text": "(defun solver ()\n (let* ((a (read)) (b (read)) (c (read))\n (k (read)) (result 0) (max (max a b c))\n (max2 (* (expt 2 k) max)))\n (cond ((= a max) (setf result (+ max2 b c)))\n ((= b max) (setf result (+ a max2 c)))\n ((= c max) (setf result (+ a b max2))))\n (format t \"~a~%\" result)))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1525569569, "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/s171204053.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s171204053", "user_id": "u183015556"}, "prompt_components": {"gold_output": "30\n", "input_to_evaluate": "(defun solver ()\n (let* ((a (read)) (b (read)) (c (read))\n (k (read)) (result 0) (max (max a b c))\n (max2 (* (expt 2 k) max)))\n (cond ((= a max) (setf result (+ max2 b c)))\n ((= b max) (setf result (+ a max2 c)))\n ((= c max) (setf result (+ a b max2))))\n (format t \"~a~%\" result)))\n\n(solver)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 340, "memory_kb": 13280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s107253678", "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\" \"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 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 (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 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(defun main (h w map)\n (every\n (lambda (y)\n (every\n (lambda (x)\n (or (char= (aref map y x) #\\.)\n (and (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(let ((h (read))\n (w (read)))\n (format t \"~a~%\" (if (main\n h w\n (make-array\n (list h w)\n :initial-contents (collect-times h (read-string))))\n \"Yes\"\n \"No\")))\n", "language": "Lisp", "metadata": {"date": 1589579016, "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/s107253678.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s107253678", "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 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 (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 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(defun main (h w map)\n (every\n (lambda (y)\n (every\n (lambda (x)\n (or (char= (aref map y x) #\\.)\n (and (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(let ((h (read))\n (w (read)))\n (format t \"~a~%\" (if (main\n h w\n (make-array\n (list h w)\n :initial-contents (collect-times h (read-string))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5514, "cpu_time_ms": 285, "memory_kb": 64056}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s060500608", "group_id": "codeNet:p03362", "input_text": "(format t\"~{~A ~}\"(subseq'(11 31 41 61 71 101 131 151 181 191 211 241 251 271 281 311 331 401 421 431 461 491 521 541 571 601 631 641 661 691 701 751 761 811 821 881 911 941 971 991 1021 1031 1051 1061 1091 1151 1171 1181 1201 1231 1291 1301 1321 1361 1381)0(read)))", "language": "Lisp", "metadata": {"date": 1549010840, "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/s060500608.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s060500608", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3 5 7 11 31\n", "input_to_evaluate": "(format t\"~{~A ~}\"(subseq'(11 31 41 61 71 101 131 151 181 191 211 241 251 271 281 311 331 401 421 431 461 491 521 541 571 601 631 641 661 691 701 751 761 811 821 881 911 941 971 991 1021 1031 1051 1061 1091 1151 1171 1181 1201 1231 1291 1301 1321 1361 1381)0(read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 266, "cpu_time_ms": 6, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s050902246", "group_id": "codeNet:p03370", "input_text": "\n(let* ((n (read))\n (m (read))\n (lst (sort (loop :for k :from 1 :upto n collect(read)) #'<)))\n (format t \"~A\" (+ n (floor (- m (reduce #'+ lst)) (first lst)))))", "language": "Lisp", "metadata": {"date": 1539902263, "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/s050902246.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s050902246", "user_id": "u610490393"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "\n(let* ((n (read))\n (m (read))\n (lst (sort (loop :for k :from 1 :upto n collect(read)) #'<)))\n (format t \"~A\" (+ n (floor (- m (reduce #'+ lst)) (first lst)))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 171, "cpu_time_ms": 22, "memory_kb": 4836}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s730413867", "group_id": "codeNet:p03370", "input_text": "(defun solver ()\n (let* ((n (read)) (x (read))\n (mi (make-array n :fill-pointer 0))\n m-temp (m-min 1001)\n (answer n))\n (loop repeat n do\n (vector-push (read) mi))\n (loop for i from 0 below n do\n (setf m-temp (aref mi i))\n (decf x m-temp)\n (when (< m-temp m-min) (setf m-min m-temp)))\n (incf answer (floor x m-min))\n (format t \"~a~%\" answer)))\n\n(solver)\n", "language": "Lisp", "metadata": {"date": 1524359836, "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/s730413867.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s730413867", "user_id": "u183015556"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun solver ()\n (let* ((n (read)) (x (read))\n (mi (make-array n :fill-pointer 0))\n m-temp (m-min 1001)\n (answer n))\n (loop repeat n do\n (vector-push (read) mi))\n (loop for i from 0 below n do\n (setf m-temp (aref mi i))\n (decf x m-temp)\n (when (< m-temp m-min) (setf m-min m-temp)))\n (incf answer (floor x m-min))\n (format t \"~a~%\" answer)))\n\n(solver)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 479, "memory_kb": 16740}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s122919102", "group_id": "codeNet:p03371", "input_text": "(let* ((a (read))\n (b (read))\n (c (read))\n (x (read))\n (y (read)))\n (princ (min\n (+ (* 2 c (min x y)) (* a (- x (min x y))) (* b (- y (min x y))))\n (+ (* 2 c (max x y)))\n (+ (* a x) (* b y)))))", "language": "Lisp", "metadata": {"date": 1582584836, "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/s122919102.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s122919102", "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 (princ (min\n (+ (* 2 c (min x y)) (* a (- x (min x y))) (* b (- y (min x y))))\n (+ (* 2 c (max x y)))\n (+ (* 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 115, "memory_kb": 13028}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s442267234", "group_id": "codeNet:p03372", "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(defun solve (xs vs c)\n (declare #.OPT\n ((simple-array uint62 (*)) xs)\n ((simple-array uint32 (*)) vs))\n (let* ((n (length xs))\n (cumuls-clock (make-array n :element-type 'fixnum))\n (cumuls-anticlock (make-array n :element-type 'fixnum))\n (dp-clock (make-array n :element-type 'fixnum))\n (dp-anticlock (make-array n :element-type 'fixnum)))\n (setf (aref cumuls-clock 0) (- (aref vs 0) (aref xs 0)))\n (loop for i from 1 below n\n do (setf (aref cumuls-clock i)\n (+ (aref cumuls-clock (- i 1))\n (aref vs i)\n (- (aref xs (- i 1)) (aref xs i)))))\n (setf (aref cumuls-anticlock (- n 1)) (- (aref vs (- n 1))\n (* 2 (- c (aref xs (- n 1))))))\n (loop for i from (- n 2) downto 0\n do (setf (aref cumuls-anticlock i)\n (+ (aref cumuls-anticlock (+ i 1))\n (aref vs i)\n (- (* 2 (- (aref xs (+ i 1)) (aref xs i)))))))\n (setf (aref dp-clock 0) (aref cumuls-clock 0))\n (loop for i from 1 below n\n do (setf (aref dp-clock i)\n (max (aref dp-clock (- i 1)) (aref cumuls-clock i))))\n (setf (aref dp-anticlock (- n 1)) (aref cumuls-anticlock (- n 1)))\n (loop for i from (- n 2) downto 0\n do (setf (aref dp-anticlock i)\n (max (aref dp-anticlock (+ i 1)) (aref cumuls-anticlock i))))\n (max (reduce #'max cumuls-clock)\n (loop for i from 0 below (- n 1)\n maximize (+ (aref dp-clock i) (aref dp-anticlock (+ i 1)))))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (c (read))\n (xs (make-array n :element-type 'uint62))\n (rev-xs (make-array n :element-type 'uint62))\n (vs (make-array n :element-type 'uint32))\n (rev-vs (make-array n :element-type 'uint32)))\n (declare (uint62 c) (uint32 n))\n (dotimes (i n)\n (let ((x (read-fixnum))\n (v (read-fixnum)))\n (setf (aref xs i) x)\n (setf (aref rev-xs (- n i 1)) (- c x))\n (setf (aref vs i) v)\n (setf (aref rev-vs (- n i 1)) v)))\n (println (max 0 (solve xs vs c) (solve rev-xs rev-vs c)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558392033, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03372.html", "problem_id": "p03372", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03372/input.txt", "sample_output_relpath": "derived/input_output/data/p03372/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03372/Lisp/s442267234.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s442267234", "user_id": "u352600849"}, "prompt_components": {"gold_output": "191\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(defun solve (xs vs c)\n (declare #.OPT\n ((simple-array uint62 (*)) xs)\n ((simple-array uint32 (*)) vs))\n (let* ((n (length xs))\n (cumuls-clock (make-array n :element-type 'fixnum))\n (cumuls-anticlock (make-array n :element-type 'fixnum))\n (dp-clock (make-array n :element-type 'fixnum))\n (dp-anticlock (make-array n :element-type 'fixnum)))\n (setf (aref cumuls-clock 0) (- (aref vs 0) (aref xs 0)))\n (loop for i from 1 below n\n do (setf (aref cumuls-clock i)\n (+ (aref cumuls-clock (- i 1))\n (aref vs i)\n (- (aref xs (- i 1)) (aref xs i)))))\n (setf (aref cumuls-anticlock (- n 1)) (- (aref vs (- n 1))\n (* 2 (- c (aref xs (- n 1))))))\n (loop for i from (- n 2) downto 0\n do (setf (aref cumuls-anticlock i)\n (+ (aref cumuls-anticlock (+ i 1))\n (aref vs i)\n (- (* 2 (- (aref xs (+ i 1)) (aref xs i)))))))\n (setf (aref dp-clock 0) (aref cumuls-clock 0))\n (loop for i from 1 below n\n do (setf (aref dp-clock i)\n (max (aref dp-clock (- i 1)) (aref cumuls-clock i))))\n (setf (aref dp-anticlock (- n 1)) (aref cumuls-anticlock (- n 1)))\n (loop for i from (- n 2) downto 0\n do (setf (aref dp-anticlock i)\n (max (aref dp-anticlock (+ i 1)) (aref cumuls-anticlock i))))\n (max (reduce #'max cumuls-clock)\n (loop for i from 0 below (- n 1)\n maximize (+ (aref dp-clock i) (aref dp-anticlock (+ i 1)))))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (c (read))\n (xs (make-array n :element-type 'uint62))\n (rev-xs (make-array n :element-type 'uint62))\n (vs (make-array n :element-type 'uint32))\n (rev-vs (make-array n :element-type 'uint32)))\n (declare (uint62 c) (uint32 n))\n (dotimes (i n)\n (let ((x (read-fixnum))\n (v (read-fixnum)))\n (setf (aref xs i) x)\n (setf (aref rev-xs (- n i 1)) (- c x))\n (setf (aref vs i) v)\n (setf (aref rev-vs (- n i 1)) v)))\n (println (max 0 (solve xs vs c) (solve rev-xs rev-vs c)))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\n\"Teishi-zushi\", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.\n\nNakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories.\n\nNakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter.\n\nWhenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n2 ≤ C ≤ 10^{14}\n\n1 ≤ x_1 < x_2 < ... < x_N < C\n\n1 ≤ v_i ≤ 10^9\n\nAll values in input are integers.\n\nSubscores\n\n300 points will be awarded for passing the test set satisfying N ≤ 100.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN C\nx_1 v_1\nx_2 v_2\n:\nx_N v_N\n\nOutput\n\nIf Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c.\n\nSample Input 1\n\n3 20\n2 80\n9 120\n16 1\n\nSample Output 1\n\n191\n\nThere are three sushi on the counter with a circumference of 20 meters. If he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories. If he walks seven more meters clockwise, he can eat a sushi of 120 kilocalories. If he leaves now, the total nutrition taken in is 200 kilocalories, and the total energy consumed is 9 kilocalories, thus he can take in 191 kilocalories on balance, which is the largest possible value.\n\nSample Input 2\n\n3 20\n2 80\n9 1\n16 120\n\nSample Output 2\n\n192\n\nThe second and third sushi have been swapped. Again, if he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories. If he walks six more meters counterclockwise this time, he can eat a sushi of 120 kilocalories. If he leaves now, the total nutrition taken in is 200 kilocalories, and the total energy consumed is 8 kilocalories, thus he can take in 192 kilocalories on balance, which is the largest possible value.\n\nSample Input 3\n\n1 100000000000000\n50000000000000 1\n\nSample Output 3\n\n0\n\nEven though the only sushi is so far that it does not fit into a 32-bit integer, its nutritive value is low, thus he should immediately leave without doing anything.\n\nSample Input 4\n\n15 10000000000\n400000000 1000000000\n800000000 1000000000\n1900000000 1000000000\n2400000000 1000000000\n2900000000 1000000000\n3300000000 1000000000\n3700000000 1000000000\n3800000000 1000000000\n4000000000 1000000000\n4100000000 1000000000\n5200000000 1000000000\n6600000000 1000000000\n8000000000 1000000000\n9300000000 1000000000\n9700000000 1000000000\n\nSample Output 4\n\n6500000000\n\nAll these sample inputs above are included in the test set for the partial score.", "sample_input": "3 20\n2 80\n9 120\n16 1\n"}, "reference_outputs": ["191\n"], "source_document_id": "p03372", "source_text": "Score : 500 points\n\nProblem Statement\n\n\"Teishi-zushi\", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.\n\nNakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories.\n\nNakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter.\n\nWhenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n2 ≤ C ≤ 10^{14}\n\n1 ≤ x_1 < x_2 < ... < x_N < C\n\n1 ≤ v_i ≤ 10^9\n\nAll values in input are integers.\n\nSubscores\n\n300 points will be awarded for passing the test set satisfying N ≤ 100.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN C\nx_1 v_1\nx_2 v_2\n:\nx_N v_N\n\nOutput\n\nIf Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c.\n\nSample Input 1\n\n3 20\n2 80\n9 120\n16 1\n\nSample Output 1\n\n191\n\nThere are three sushi on the counter with a circumference of 20 meters. If he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories. If he walks seven more meters clockwise, he can eat a sushi of 120 kilocalories. If he leaves now, the total nutrition taken in is 200 kilocalories, and the total energy consumed is 9 kilocalories, thus he can take in 191 kilocalories on balance, which is the largest possible value.\n\nSample Input 2\n\n3 20\n2 80\n9 1\n16 120\n\nSample Output 2\n\n192\n\nThe second and third sushi have been swapped. Again, if he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories. If he walks six more meters counterclockwise this time, he can eat a sushi of 120 kilocalories. If he leaves now, the total nutrition taken in is 200 kilocalories, and the total energy consumed is 8 kilocalories, thus he can take in 192 kilocalories on balance, which is the largest possible value.\n\nSample Input 3\n\n1 100000000000000\n50000000000000 1\n\nSample Output 3\n\n0\n\nEven though the only sushi is so far that it does not fit into a 32-bit integer, its nutritive value is low, thus he should immediately leave without doing anything.\n\nSample Input 4\n\n15 10000000000\n400000000 1000000000\n800000000 1000000000\n1900000000 1000000000\n2400000000 1000000000\n2900000000 1000000000\n3300000000 1000000000\n3700000000 1000000000\n3800000000 1000000000\n4000000000 1000000000\n4100000000 1000000000\n5200000000 1000000000\n6600000000 1000000000\n8000000000 1000000000\n9300000000 1000000000\n9700000000 1000000000\n\nSample Output 4\n\n6500000000\n\nAll these sample inputs above are included in the test set for the partial score.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4612, "cpu_time_ms": 233, "memory_kb": 26852}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s347425037", "group_id": "codeNet:p03372", "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-binary-heap (name &key (order '#'>) (element-type 'fixnum))\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-peak (intern (format nil \"~A-PEAK\" 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 (inline ,fname-push))\n (defun ,fname-push (obj 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 (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 (inline ,fname-pop))\n (defun ,fname-pop (heap &optional (error t) null-value)\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 ((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 (if (= position 1)\n (if error\n (error \"No element in heap.\")\n null-value)\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 (setf (,acc-position heap) 1)\n heap)\n\n (declaim (inline ,fname-empty-p))\n (defun ,fname-empty-p (heap)\n (= 1 (,acc-position heap)))\n\n (declaim (inline ,fname-peak))\n (defun ,fname-peak (heap &optional (error t) null-value)\n (if (= 1 (,acc-position heap))\n (if error\n (error \"No element in heap\")\n null-value)\n (aref (,acc-data heap) 1))))))\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(define-binary-heap heap\n :order (lambda (x y) (> (car x) (car y)))\n ;; (cal . index)\n :element-type (cons fixnum fixnum))\n\n(defun solve (xs vs c)\n (declare #.OPT\n ((simple-array uint62 (*)) xs)\n ((simple-array uint32 (*)) vs))\n (let* ((n (length xs))\n (cumuls-clock (make-array n :element-type 'fixnum))\n (cumuls-anticlock (make-array n :element-type 'fixnum)))\n (setf (aref cumuls-clock 0) (- (aref vs 0) (aref xs 0)))\n (loop for i from 1 below n\n do (setf (aref cumuls-clock i)\n (+ (aref cumuls-clock (- i 1))\n (aref vs i)\n (- (aref xs (- i 1)) (aref xs i)))))\n (setf (aref cumuls-anticlock (- n 1)) (- (aref vs (- n 1))\n (* 2 (- c (aref xs (- n 1))))))\n (loop for i from (- n 2) downto 0\n do (setf (aref cumuls-anticlock i)\n (+ (aref cumuls-anticlock (+ i 1))\n (aref vs i)\n (- (* 2 (- (aref xs (+ i 1)) (aref xs i)))))))\n (let ((res (reduce #'max cumuls-clock))\n (pqueue (make-heap n))\n (pos 0))\n (declare (fixnum res))\n (dotimes (i n)\n (heap-push (cons (aref cumuls-anticlock i) i) pqueue))\n (loop (when (heap-empty-p pqueue)\n (return res))\n (destructuring-bind (rev-cal . rev-pos) (heap-peak pqueue)\n (declare (fixnum rev-cal rev-pos))\n (if (<= rev-pos pos)\n (heap-pop pqueue)\n (progn\n (setf res (max res (+ (aref cumuls-clock pos) rev-cal)))\n (incf pos))))))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (c (read))\n (xs (make-array n :element-type 'uint62))\n (rev-xs (make-array n :element-type 'uint62))\n (vs (make-array n :element-type 'uint32))\n (rev-vs (make-array n :element-type 'uint32)))\n (declare (uint62 c) (uint32 n))\n (dotimes (i n)\n (let ((x (read-fixnum))\n (v (read-fixnum)))\n (setf (aref xs i) x)\n (setf (aref rev-xs (- n i 1)) (- c x))\n (setf (aref vs i) v)\n (setf (aref rev-vs (- n i 1)) v)))\n (println (max 0 (solve xs vs c) (solve rev-xs rev-vs c)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558388649, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03372.html", "problem_id": "p03372", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03372/input.txt", "sample_output_relpath": "derived/input_output/data/p03372/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03372/Lisp/s347425037.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s347425037", "user_id": "u352600849"}, "prompt_components": {"gold_output": "191\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-binary-heap (name &key (order '#'>) (element-type 'fixnum))\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-peak (intern (format nil \"~A-PEAK\" 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 (inline ,fname-push))\n (defun ,fname-push (obj 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 (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 (inline ,fname-pop))\n (defun ,fname-pop (heap &optional (error t) null-value)\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 ((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 (if (= position 1)\n (if error\n (error \"No element in heap.\")\n null-value)\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 (setf (,acc-position heap) 1)\n heap)\n\n (declaim (inline ,fname-empty-p))\n (defun ,fname-empty-p (heap)\n (= 1 (,acc-position heap)))\n\n (declaim (inline ,fname-peak))\n (defun ,fname-peak (heap &optional (error t) null-value)\n (if (= 1 (,acc-position heap))\n (if error\n (error \"No element in heap\")\n null-value)\n (aref (,acc-data heap) 1))))))\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(define-binary-heap heap\n :order (lambda (x y) (> (car x) (car y)))\n ;; (cal . index)\n :element-type (cons fixnum fixnum))\n\n(defun solve (xs vs c)\n (declare #.OPT\n ((simple-array uint62 (*)) xs)\n ((simple-array uint32 (*)) vs))\n (let* ((n (length xs))\n (cumuls-clock (make-array n :element-type 'fixnum))\n (cumuls-anticlock (make-array n :element-type 'fixnum)))\n (setf (aref cumuls-clock 0) (- (aref vs 0) (aref xs 0)))\n (loop for i from 1 below n\n do (setf (aref cumuls-clock i)\n (+ (aref cumuls-clock (- i 1))\n (aref vs i)\n (- (aref xs (- i 1)) (aref xs i)))))\n (setf (aref cumuls-anticlock (- n 1)) (- (aref vs (- n 1))\n (* 2 (- c (aref xs (- n 1))))))\n (loop for i from (- n 2) downto 0\n do (setf (aref cumuls-anticlock i)\n (+ (aref cumuls-anticlock (+ i 1))\n (aref vs i)\n (- (* 2 (- (aref xs (+ i 1)) (aref xs i)))))))\n (let ((res (reduce #'max cumuls-clock))\n (pqueue (make-heap n))\n (pos 0))\n (declare (fixnum res))\n (dotimes (i n)\n (heap-push (cons (aref cumuls-anticlock i) i) pqueue))\n (loop (when (heap-empty-p pqueue)\n (return res))\n (destructuring-bind (rev-cal . rev-pos) (heap-peak pqueue)\n (declare (fixnum rev-cal rev-pos))\n (if (<= rev-pos pos)\n (heap-pop pqueue)\n (progn\n (setf res (max res (+ (aref cumuls-clock pos) rev-cal)))\n (incf pos))))))))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (c (read))\n (xs (make-array n :element-type 'uint62))\n (rev-xs (make-array n :element-type 'uint62))\n (vs (make-array n :element-type 'uint32))\n (rev-vs (make-array n :element-type 'uint32)))\n (declare (uint62 c) (uint32 n))\n (dotimes (i n)\n (let ((x (read-fixnum))\n (v (read-fixnum)))\n (setf (aref xs i) x)\n (setf (aref rev-xs (- n i 1)) (- c x))\n (setf (aref vs i) v)\n (setf (aref rev-vs (- n i 1)) v)))\n (println (max 0 (solve xs vs c) (solve rev-xs rev-vs c)))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\n\"Teishi-zushi\", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.\n\nNakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories.\n\nNakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter.\n\nWhenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n2 ≤ C ≤ 10^{14}\n\n1 ≤ x_1 < x_2 < ... < x_N < C\n\n1 ≤ v_i ≤ 10^9\n\nAll values in input are integers.\n\nSubscores\n\n300 points will be awarded for passing the test set satisfying N ≤ 100.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN C\nx_1 v_1\nx_2 v_2\n:\nx_N v_N\n\nOutput\n\nIf Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c.\n\nSample Input 1\n\n3 20\n2 80\n9 120\n16 1\n\nSample Output 1\n\n191\n\nThere are three sushi on the counter with a circumference of 20 meters. If he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories. If he walks seven more meters clockwise, he can eat a sushi of 120 kilocalories. If he leaves now, the total nutrition taken in is 200 kilocalories, and the total energy consumed is 9 kilocalories, thus he can take in 191 kilocalories on balance, which is the largest possible value.\n\nSample Input 2\n\n3 20\n2 80\n9 1\n16 120\n\nSample Output 2\n\n192\n\nThe second and third sushi have been swapped. Again, if he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories. If he walks six more meters counterclockwise this time, he can eat a sushi of 120 kilocalories. If he leaves now, the total nutrition taken in is 200 kilocalories, and the total energy consumed is 8 kilocalories, thus he can take in 192 kilocalories on balance, which is the largest possible value.\n\nSample Input 3\n\n1 100000000000000\n50000000000000 1\n\nSample Output 3\n\n0\n\nEven though the only sushi is so far that it does not fit into a 32-bit integer, its nutritive value is low, thus he should immediately leave without doing anything.\n\nSample Input 4\n\n15 10000000000\n400000000 1000000000\n800000000 1000000000\n1900000000 1000000000\n2400000000 1000000000\n2900000000 1000000000\n3300000000 1000000000\n3700000000 1000000000\n3800000000 1000000000\n4000000000 1000000000\n4100000000 1000000000\n5200000000 1000000000\n6600000000 1000000000\n8000000000 1000000000\n9300000000 1000000000\n9700000000 1000000000\n\nSample Output 4\n\n6500000000\n\nAll these sample inputs above are included in the test set for the partial score.", "sample_input": "3 20\n2 80\n9 120\n16 1\n"}, "reference_outputs": ["191\n"], "source_document_id": "p03372", "source_text": "Score : 500 points\n\nProblem Statement\n\n\"Teishi-zushi\", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.\n\nNakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories.\n\nNakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter.\n\nWhenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n2 ≤ C ≤ 10^{14}\n\n1 ≤ x_1 < x_2 < ... < x_N < C\n\n1 ≤ v_i ≤ 10^9\n\nAll values in input are integers.\n\nSubscores\n\n300 points will be awarded for passing the test set satisfying N ≤ 100.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN C\nx_1 v_1\nx_2 v_2\n:\nx_N v_N\n\nOutput\n\nIf Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c.\n\nSample Input 1\n\n3 20\n2 80\n9 120\n16 1\n\nSample Output 1\n\n191\n\nThere are three sushi on the counter with a circumference of 20 meters. If he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories. If he walks seven more meters clockwise, he can eat a sushi of 120 kilocalories. If he leaves now, the total nutrition taken in is 200 kilocalories, and the total energy consumed is 9 kilocalories, thus he can take in 191 kilocalories on balance, which is the largest possible value.\n\nSample Input 2\n\n3 20\n2 80\n9 1\n16 120\n\nSample Output 2\n\n192\n\nThe second and third sushi have been swapped. Again, if he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories. If he walks six more meters counterclockwise this time, he can eat a sushi of 120 kilocalories. If he leaves now, the total nutrition taken in is 200 kilocalories, and the total energy consumed is 8 kilocalories, thus he can take in 192 kilocalories on balance, which is the largest possible value.\n\nSample Input 3\n\n1 100000000000000\n50000000000000 1\n\nSample Output 3\n\n0\n\nEven though the only sushi is so far that it does not fit into a 32-bit integer, its nutritive value is low, thus he should immediately leave without doing anything.\n\nSample Input 4\n\n15 10000000000\n400000000 1000000000\n800000000 1000000000\n1900000000 1000000000\n2400000000 1000000000\n2900000000 1000000000\n3300000000 1000000000\n3700000000 1000000000\n3800000000 1000000000\n4000000000 1000000000\n4100000000 1000000000\n5200000000 1000000000\n6600000000 1000000000\n8000000000 1000000000\n9300000000 1000000000\n9700000000 1000000000\n\nSample Output 4\n\n6500000000\n\nAll these sample inputs above are included in the test set for the partial score.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8808, "cpu_time_ms": 346, "memory_kb": 41960}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s047192135", "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 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.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": 1549044751, "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/s047192135.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s047192135", "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 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.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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3884, "cpu_time_ms": 667, "memory_kb": 53984}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s560810637", "group_id": "codeNet:p03385", "input_text": "(let ((lst (concatenate 'list (read-line))))\n (if (and (find #\\a lst :test #'char=) (find #\\b lst :test #'char=) (find #\\c lst :test #'char=))\n (format t \"Yes~%\")\n (format t \"No~%\")))", "language": "Lisp", "metadata": {"date": 1540351211, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s560810637.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s560810637", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((lst (concatenate 'list (read-line))))\n (if (and (find #\\a lst :test #'char=) (find #\\b lst :test #'char=) (find #\\c lst :test #'char=))\n (format t \"Yes~%\")\n (format t \"No~%\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 194, "cpu_time_ms": 132, "memory_kb": 11368}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s484474596", "group_id": "codeNet:p03388", "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 (let* ((q (read)))\n (declare (uint32 q))\n (dotimes (_ q)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (declare (uint31 a b))\n (when (> a b) (rotatef a b))\n (let ((res (* 2 (- a 1))))\n (unless (= a b)\n (sb-int:named-let bisect ((ok 0) (ng (- b a)))\n (declare (uint31 ok ng))\n (if (<= (- ng ok) 1)\n (incf res ok)\n (let* ((mid (ash (+ ok ng) -1))\n (x/2 (max 1 (floor mid 2))))\n (declare (uint31 mid x/2))\n (if (< (* (+ a x/2) (+ a mid (- x/2))) (* a b))\n (bisect mid ng)\n (bisect ok mid))))))\n (println res))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565996216, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03388.html", "problem_id": "p03388", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03388/input.txt", "sample_output_relpath": "derived/input_output/data/p03388/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03388/Lisp/s484474596.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s484474596", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1\n12\n4\n11\n14\n57\n31\n671644785\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 (let* ((q (read)))\n (declare (uint32 q))\n (dotimes (_ q)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (declare (uint31 a b))\n (when (> a b) (rotatef a b))\n (let ((res (* 2 (- a 1))))\n (unless (= a b)\n (sb-int:named-let bisect ((ok 0) (ng (- b a)))\n (declare (uint31 ok ng))\n (if (<= (- ng ok) 1)\n (incf res ok)\n (let* ((mid (ash (+ ok ng) -1))\n (x/2 (max 1 (floor mid 2))))\n (declare (uint31 mid x/2))\n (if (< (* (+ a x/2) (+ a mid (- x/2))) (* a b))\n (bisect mid ng)\n (bisect ok mid))))))\n (println res))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\n10^{10^{10}} participants, including Takahashi, competed in two programming contests.\nIn each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.\n\nThe score of a participant is the product of his/her ranks in the two contests.\n\nProcess the following Q queries:\n\nIn the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.\n\nConstraints\n\n1 \\leq Q \\leq 100\n\n1\\leq A_i,B_i\\leq 10^9(1\\leq i\\leq Q)\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\n:\nA_Q B_Q\n\nOutput\n\nFor each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.\n\nSample Input 1\n\n8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 40\n8 36\n314159265 358979323\n\nSample Output 1\n\n1\n12\n4\n11\n14\n57\n31\n671644785\n\nLet us denote a participant who was ranked x-th in the first contest and y-th in the second contest as (x,y).\n\nIn the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1.", "sample_input": "8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 40\n8 36\n314159265 358979323\n"}, "reference_outputs": ["1\n12\n4\n11\n14\n57\n31\n671644785\n"], "source_document_id": "p03388", "source_text": "Score : 700 points\n\nProblem Statement\n\n10^{10^{10}} participants, including Takahashi, competed in two programming contests.\nIn each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.\n\nThe score of a participant is the product of his/her ranks in the two contests.\n\nProcess the following Q queries:\n\nIn the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.\n\nConstraints\n\n1 \\leq Q \\leq 100\n\n1\\leq A_i,B_i\\leq 10^9(1\\leq i\\leq Q)\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\n:\nA_Q B_Q\n\nOutput\n\nFor each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.\n\nSample Input 1\n\n8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 40\n8 36\n314159265 358979323\n\nSample Output 1\n\n1\n12\n4\n11\n14\n57\n31\n671644785\n\nLet us denote a participant who was ranked x-th in the first contest and y-th in the second contest as (x,y).\n\nIn the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3149, "cpu_time_ms": 189, "memory_kb": 21732}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s053472551", "group_id": "codeNet:p03389", "input_text": "(defun solve (a b c)\n (let* ((maxi (max a b c)) \n (da (floor (/ (- maxi a) 2)))\n (db (floor (/ (- maxi b) 2)))\n (dc (floor (/ (- maxi c) 2))))\n (setq a (+ a (* da 2)))\n (setq b (+ b (* db 2)))\n (setq c (+ c (* dc 2)))\n (+ (case (- (* 3 maxi) a b c)\n (0 0)\n (1 2)\n (2 1))\n da db dc)))\n\n(princ (solve (read) (read) (read)))", "language": "Lisp", "metadata": {"date": 1524002085, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03389.html", "problem_id": "p03389", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03389/input.txt", "sample_output_relpath": "derived/input_output/data/p03389/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03389/Lisp/s053472551.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s053472551", "user_id": "u672956630"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve (a b c)\n (let* ((maxi (max a b c)) \n (da (floor (/ (- maxi a) 2)))\n (db (floor (/ (- maxi b) 2)))\n (dc (floor (/ (- maxi c) 2))))\n (setq a (+ a (* da 2)))\n (setq b (+ b (* db 2)))\n (setq c (+ c (* dc 2)))\n (+ (case (- (* 3 maxi) a b c)\n (0 0)\n (1 2)\n (2 1))\n da db dc)))\n\n(princ (solve (read) (read) (read)))", "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": "p03389", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 388, "cpu_time_ms": 24, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s992581313", "group_id": "codeNet:p03391", "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(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 (as (make-array n :element-type 'uint32))\n (bs (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (when (every #'= as bs)\n (println 0)\n (return-from main))\n (let ((min #xffffffff))\n (loop for a across as\n for b across bs\n when (> a b)\n do (minf min b))\n (println (- (reduce #'+ as) min)))))\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\n1 2\n3 2\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n8 3\n0 1\n4 8\n\"\n \"9\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n1 1\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1577334447, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03391.html", "problem_id": "p03391", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03391/input.txt", "sample_output_relpath": "derived/input_output/data/p03391/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03391/Lisp/s992581313.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s992581313", "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(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 (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 (as (make-array n :element-type 'uint32))\n (bs (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (when (every #'= as bs)\n (println 0)\n (return-from main))\n (let ((min #xffffffff))\n (loop for a across as\n for b across bs\n when (> a b)\n do (minf min b))\n (println (- (reduce #'+ as) min)))))\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\n1 2\n3 2\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n8 3\n0 1\n4 8\n\"\n \"9\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1\n1 1\n\"\n \"0\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nYou are given sequences A and B consisting of non-negative integers.\nThe lengths of both A and B are N, and the sums of the elements in A and B are equal.\nThe i-th element in A is A_i, and the i-th element in B is B_i.\n\nTozan and Gezan repeats the following sequence of operations:\n\nIf A and B are equal sequences, terminate the process.\n\nOtherwise, first Tozan chooses a positive element in A and decrease it by 1.\n\nThen, Gezan chooses a positive element in B and decrease it by 1.\n\nThen, give one candy to Takahashi, their pet.\n\nTozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible.\nFind the number of candies given to Takahashi when both of them perform the operations optimally.\n\nConstraints\n\n1 \\leq N \\leq 2 × 10^5\n\n0 \\leq A_i,B_i \\leq 10^9(1\\leq i\\leq N)\n\nThe sums of the elements in A and B are equal.\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 B_N\n\nOutput\n\nPrint the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.\n\nSample Input 1\n\n2\n1 2\n3 2\n\nSample Output 1\n\n2\n\nWhen both Tozan and Gezan perform the operations optimally, the process will proceed as follows:\n\nTozan decreases A_1 by 1.\n\nGezan decreases B_1 by 1.\n\nOne candy is given to Takahashi.\n\nTozan decreases A_2 by 1.\n\nGezan decreases B_1 by 1.\n\nOne candy is given to Takahashi.\n\nAs A and B are equal, the process is terminated.\n\nSample Input 2\n\n3\n8 3\n0 1\n4 8\n\nSample Output 2\n\n9\n\nSample Input 3\n\n1\n1 1\n\nSample Output 3\n\n0", "sample_input": "2\n1 2\n3 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03391", "source_text": "Score : 700 points\n\nProblem Statement\n\nYou are given sequences A and B consisting of non-negative integers.\nThe lengths of both A and B are N, and the sums of the elements in A and B are equal.\nThe i-th element in A is A_i, and the i-th element in B is B_i.\n\nTozan and Gezan repeats the following sequence of operations:\n\nIf A and B are equal sequences, terminate the process.\n\nOtherwise, first Tozan chooses a positive element in A and decrease it by 1.\n\nThen, Gezan chooses a positive element in B and decrease it by 1.\n\nThen, give one candy to Takahashi, their pet.\n\nTozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible.\nFind the number of candies given to Takahashi when both of them perform the operations optimally.\n\nConstraints\n\n1 \\leq N \\leq 2 × 10^5\n\n0 \\leq A_i,B_i \\leq 10^9(1\\leq i\\leq N)\n\nThe sums of the elements in A and B are equal.\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 B_N\n\nOutput\n\nPrint the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.\n\nSample Input 1\n\n2\n1 2\n3 2\n\nSample Output 1\n\n2\n\nWhen both Tozan and Gezan perform the operations optimally, the process will proceed as follows:\n\nTozan decreases A_1 by 1.\n\nGezan decreases B_1 by 1.\n\nOne candy is given to Takahashi.\n\nTozan decreases A_2 by 1.\n\nGezan decreases B_1 by 1.\n\nOne candy is given to Takahashi.\n\nAs A and B are equal, the process is terminated.\n\nSample Input 2\n\n3\n8 3\n0 1\n4 8\n\nSample Output 2\n\n9\n\nSample Input 3\n\n1\n1 1\n\nSample Output 3\n\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5616, "cpu_time_ms": 240, "memory_kb": 28768}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s228137539", "group_id": "codeNet:p03394", "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 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(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 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(defparameter *prime-seq* (make-prime-sequence 30001))\n\n(defparameter *goldbach-table*\n (make-array 20001 :element-type '(cons uint32 uint32)))\n(loop for x across *prime-seq*\n do (loop for y across *prime-seq*\n do (when (and (/= x y)\n (<= (+ x y) 20000))\n (setf (aref *goldbach-table* (+ x y))\n (cons x y)))))\n(defun main ()\n (let* ((n (read)))\n (cond ((= n 3) (write-line \"2 5 63\"))\n ((= n 4) (write-line \"2 5 20 63\"))\n ((= n 6) (write-line \"2 5 20 63 12600\"))\n (t (let ((pair (if (oddp n)\n (cons 2 (- n 2))\n (aref *goldbach-table* n))))\n (with-buffered-stdout\n (dotimes (i (car pair))\n (format t \"~D \" (cdr pair)))\n (dotimes (i (cdr pair))\n (format t \"~D \" (car pair)))\n (terpri)))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563329471, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03394.html", "problem_id": "p03394", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03394/input.txt", "sample_output_relpath": "derived/input_output/data/p03394/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03394/Lisp/s228137539.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s228137539", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2 5 63\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 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(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 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(defparameter *prime-seq* (make-prime-sequence 30001))\n\n(defparameter *goldbach-table*\n (make-array 20001 :element-type '(cons uint32 uint32)))\n(loop for x across *prime-seq*\n do (loop for y across *prime-seq*\n do (when (and (/= x y)\n (<= (+ x y) 20000))\n (setf (aref *goldbach-table* (+ x y))\n (cons x y)))))\n(defun main ()\n (let* ((n (read)))\n (cond ((= n 3) (write-line \"2 5 63\"))\n ((= n 4) (write-line \"2 5 20 63\"))\n ((= n 6) (write-line \"2 5 20 63 12600\"))\n (t (let ((pair (if (oddp n)\n (cons 2 (- n 2))\n (aref *goldbach-table* n))))\n (with-buffered-stdout\n (dotimes (i (car pair))\n (format t \"~D \" (cdr pair)))\n (dotimes (i (cdr pair))\n (format t \"~D \" (car pair)))\n (terpri)))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nNagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.\n\nShe thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \\leq i \\leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.\n\nNagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.\n\nConstraints\n\n3 \\leq N \\leq 20000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nOutput N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :\n\nThe elements must be distinct positive integers not exceeding 30000.\n\nThe gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.\n\nS is a special set.\n\nIf there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2 5 63\n\n\\{2, 5, 63\\} is special because gcd(2, 5 + 63) = 2, gcd(5, 2 + 63) = 5, gcd(63, 2 + 5) = 7. Also, gcd(2, 5, 63) = 1. Thus, this set satisfies all the criteria.\n\nNote that \\{2, 4, 6\\} is not a valid solution because gcd(2, 4, 6) = 2 > 1.\n\nSample Input 2\n\n4\n\nSample Output 2\n\n2 5 20 63\n\n\\{2, 5, 20, 63\\} is special because gcd(2, 5 + 20 + 63) = 2, gcd(5, 2 + 20 + 63) = 5, gcd(20, 2 + 5 + 63) = 10, gcd(63, 2 + 5 + 20) = 9. Also, gcd(2, 5, 20, 63) = 1. Thus, this set satisfies all the criteria.", "sample_input": "3\n"}, "reference_outputs": ["2 5 63\n"], "source_document_id": "p03394", "source_text": "Score : 600 points\n\nProblem Statement\n\nNagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.\n\nShe thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \\leq i \\leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.\n\nNagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.\n\nConstraints\n\n3 \\leq N \\leq 20000\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nOutput N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :\n\nThe elements must be distinct positive integers not exceeding 30000.\n\nThe gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.\n\nS is a special set.\n\nIf there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n2 5 63\n\n\\{2, 5, 63\\} is special because gcd(2, 5 + 63) = 2, gcd(5, 2 + 63) = 5, gcd(63, 2 + 5) = 7. Also, gcd(2, 5, 63) = 1. Thus, this set satisfies all the criteria.\n\nNote that \\{2, 4, 6\\} is not a valid solution because gcd(2, 4, 6) = 2 > 1.\n\nSample Input 2\n\n4\n\nSample Output 2\n\n2 5 20 63\n\n\\{2, 5, 20, 63\\} is special because gcd(2, 5 + 20 + 63) = 2, gcd(5, 2 + 20 + 63) = 5, gcd(20, 2 + 5 + 63) = 10, gcd(63, 2 + 5 + 20) = 9. Also, gcd(2, 5, 20, 63) = 1. Thus, this set satisfies all the criteria.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4262, "cpu_time_ms": 394, "memory_kb": 69732}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s825079369", "group_id": "codeNet:p03399", "input_text": "(format t \"~A~%\" (+ (min (read) (read)) (min (read) (read))))\n", "language": "Lisp", "metadata": {"date": 1522537175, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03399.html", "problem_id": "p03399", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03399/input.txt", "sample_output_relpath": "derived/input_output/data/p03399/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03399/Lisp/s825079369.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s825079369", "user_id": "u948374595"}, "prompt_components": {"gold_output": "520\n", "input_to_evaluate": "(format t \"~A~%\" (+ (min (read) (read)) (min (read) (read))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou planned a trip using trains and buses.\nThe train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket.\nSimilarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket.\n\nFind the minimum total fare when the optimal choices are made for trains and buses.\n\nConstraints\n\n1 \\leq A \\leq 1 000\n\n1 \\leq B \\leq 1 000\n\n1 \\leq C \\leq 1 000\n\n1 \\leq D \\leq 1 000\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\nC\nD\n\nOutput\n\nPrint the minimum total fare.\n\nSample Input 1\n\n600\n300\n220\n420\n\nSample Output 1\n\n520\n\nThe train fare will be 600 yen if you buy ordinary tickets, and 300 yen if you buy an unlimited ticket.\nThus, the optimal choice for trains is to buy an unlimited ticket for 300 yen.\nOn the other hand, the optimal choice for buses is to buy ordinary tickets for 220 yen.\n\nTherefore, the minimum total fare is 300 + 220 = 520 yen.\n\nSample Input 2\n\n555\n555\n400\n200\n\nSample Output 2\n\n755\n\nSample Input 3\n\n549\n817\n715\n603\n\nSample Output 3\n\n1152", "sample_input": "600\n300\n220\n420\n"}, "reference_outputs": ["520\n"], "source_document_id": "p03399", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou planned a trip using trains and buses.\nThe train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket.\nSimilarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket.\n\nFind the minimum total fare when the optimal choices are made for trains and buses.\n\nConstraints\n\n1 \\leq A \\leq 1 000\n\n1 \\leq B \\leq 1 000\n\n1 \\leq C \\leq 1 000\n\n1 \\leq D \\leq 1 000\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\nC\nD\n\nOutput\n\nPrint the minimum total fare.\n\nSample Input 1\n\n600\n300\n220\n420\n\nSample Output 1\n\n520\n\nThe train fare will be 600 yen if you buy ordinary tickets, and 300 yen if you buy an unlimited ticket.\nThus, the optimal choice for trains is to buy an unlimited ticket for 300 yen.\nOn the other hand, the optimal choice for buses is to buy ordinary tickets for 220 yen.\n\nTherefore, the minimum total fare is 300 + 220 = 520 yen.\n\nSample Input 2\n\n555\n555\n400\n200\n\nSample Output 2\n\n755\n\nSample Input 3\n\n549\n817\n715\n603\n\nSample Output 3\n\n1152", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 5, "memory_kb": 2788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s246759639", "group_id": "codeNet:p03400", "input_text": "(let ((n (read))\n (d (read))\n (ans (read)))\n (loop repeat n do\n (incf ans (1+ (floor (/ (1- d) (read))))))\n (princ ans))\n", "language": "Lisp", "metadata": {"date": 1552416439, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03400.html", "problem_id": "p03400", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03400/input.txt", "sample_output_relpath": "derived/input_output/data/p03400/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03400/Lisp/s246759639.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s246759639", "user_id": "u994767958"}, "prompt_components": {"gold_output": "8\n", "input_to_evaluate": "(let ((n (read))\n (d (read))\n (ans (read)))\n (loop repeat n do\n (incf ans (1+ (floor (/ (1- d) (read))))))\n (princ ans))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nSome number of chocolate pieces were prepared for a training camp.\nThe camp had N participants and lasted for D days.\nThe i-th participant (1 \\leq i \\leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on.\nAs a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.\n\nFind the number of chocolate pieces prepared at the beginning of the camp.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq D \\leq 100\n\n1 \\leq X \\leq 100\n\n1 \\leq A_i \\leq 100 (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\nD X\nA_1\nA_2\n:\nA_N\n\nOutput\n\nFind the number of chocolate pieces prepared at the beginning of the camp.\n\nSample Input 1\n\n3\n7 1\n2\n5\n10\n\nSample Output 1\n\n8\n\nThe camp has 3 participants and lasts for 7 days.\nEach participant eats chocolate pieces as follows:\n\nThe first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n\nThe second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n\nThe third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\nSample Input 2\n\n2\n8 20\n1\n10\n\nSample Output 2\n\n29\n\nSample Input 3\n\n5\n30 44\n26\n18\n81\n18\n6\n\nSample Output 3\n\n56", "sample_input": "3\n7 1\n2\n5\n10\n"}, "reference_outputs": ["8\n"], "source_document_id": "p03400", "source_text": "Score : 200 points\n\nProblem Statement\n\nSome number of chocolate pieces were prepared for a training camp.\nThe camp had N participants and lasted for D days.\nThe i-th participant (1 \\leq i \\leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on.\nAs a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.\n\nFind the number of chocolate pieces prepared at the beginning of the camp.\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq D \\leq 100\n\n1 \\leq X \\leq 100\n\n1 \\leq A_i \\leq 100 (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\nD X\nA_1\nA_2\n:\nA_N\n\nOutput\n\nFind the number of chocolate pieces prepared at the beginning of the camp.\n\nSample Input 1\n\n3\n7 1\n2\n5\n10\n\nSample Output 1\n\n8\n\nThe camp has 3 participants and lasts for 7 days.\nEach participant eats chocolate pieces as follows:\n\nThe first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.\n\nThe second participant eats one chocolate piece on Day 1 and 6, for a total of two.\n\nThe third participant eats one chocolate piece only on Day 1, for a total of one.\n\nSince the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.\n\nSample Input 2\n\n2\n8 20\n1\n10\n\nSample Output 2\n\n29\n\nSample Input 3\n\n5\n30 44\n26\n18\n81\n18\n6\n\nSample Output 3\n\n56", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 146, "memory_kb": 13416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s201134056", "group_id": "codeNet:p03404", "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 print-board (b w)\n (labels ((write-point (x)\n (if (zerop x) (write-char #\\.) (write-char #\\#))))\n (dotimes (i 100)\n (dotimes (j 50)\n (write-point (aref b i j)))\n (dotimes (j 50)\n (write-point (aref w i j)))\n (terpri))))\n\n(defun main ()\n (let* ((a (- (read) 1))\n (b (- (read) 1))\n (black-board (make-array '(100 50) :element-type 'bit :initial-element 1))\n (white-board (make-array '(100 50) :element-type 'bit :initial-element 0)))\n (block white-dot\n (loop for i from 0 below 100 by 2\n do (loop for j from 0 below 49 by 2\n do (when (zerop a)\n (return-from white-dot))\n (setf (aref black-board i j) 0)\n (decf a))))\n (block black-dot\n (loop for i from 0 below 100 by 2\n do (loop for j from 1 below 50 by 2\n do (when (zerop b)\n (return-from black-dot))\n (setf (aref white-board i j) 1)\n (decf b))))\n (format t \"100 100~%\")\n (print-board black-board white-board)))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559968132, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03404.html", "problem_id": "p03404", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03404/input.txt", "sample_output_relpath": "derived/input_output/data/p03404/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03404/Lisp/s201134056.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s201134056", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3 3\n##.\n..#\n#.#\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 print-board (b w)\n (labels ((write-point (x)\n (if (zerop x) (write-char #\\.) (write-char #\\#))))\n (dotimes (i 100)\n (dotimes (j 50)\n (write-point (aref b i j)))\n (dotimes (j 50)\n (write-point (aref w i j)))\n (terpri))))\n\n(defun main ()\n (let* ((a (- (read) 1))\n (b (- (read) 1))\n (black-board (make-array '(100 50) :element-type 'bit :initial-element 1))\n (white-board (make-array '(100 50) :element-type 'bit :initial-element 0)))\n (block white-dot\n (loop for i from 0 below 100 by 2\n do (loop for j from 0 below 49 by 2\n do (when (zerop a)\n (return-from white-dot))\n (setf (aref black-board i j) 0)\n (decf a))))\n (block black-dot\n (loop for i from 0 below 100 by 2\n do (loop for j from 1 below 50 by 2\n do (when (zerop b)\n (return-from black-dot))\n (setf (aref white-board i j) 1)\n (decf b))))\n (format t \"100 100~%\")\n (print-board black-board white-board)))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nYou are given two integers A and B.\n\nPrint a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section:\n\nLet the size of the grid be h \\times w (h vertical, w horizontal). Both h and w are at most 100.\n\nThe set of the squares painted white is divided into exactly A connected components.\n\nThe set of the squares painted black is divided into exactly B connected components.\n\nIt can be proved that there always exist one or more solutions under the conditions specified in Constraints section.\nIf there are multiple solutions, any of them may be printed.\n\nNotes\n\nTwo squares painted white, c_1 and c_2, are called connected when the square c_2 can be reached from the square c_1 passing only white squares by repeatedly moving up, down, left or right to an adjacent square.\n\nA set of squares painted white, S, forms a connected component when the following conditions are met:\n\nAny two squares in S are connected.\n\nNo pair of a square painted white that is not included in S and a square included in S is connected.\n\nA connected component of squares painted black is defined similarly.\n\nConstraints\n\n1 \\leq A \\leq 500\n\n1 \\leq B \\leq 500\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nOutput should be in the following format:\n\nIn the first line, print integers h and w representing the size of the grid you constructed, with a space in between.\n\nThen, print h more lines. The i-th (1 \\leq i \\leq h) of these lines should contain a string s_i as follows:\n\nIf the square at the i-th row and j-th column (1 \\leq j \\leq w) in the grid is painted white, the j-th character in s_i should be ..\n\nIf the square at the i-th row and j-th column (1 \\leq j \\leq w) in the grid is painted black, the j-th character in s_i should be #.\n\nSample Input 1\n\n2 3\n\nSample Output 1\n\n3 3\n##.\n..#\n#.#\n\nThis output corresponds to the grid below:\n\nSample Input 2\n\n7 8\n\nSample Output 2\n\n3 5\n#.#.#\n.#.#.\n#.#.#\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\n4 2\n..\n#.\n##\n##\n\nSample Input 4\n\n3 14\n\nSample Output 4\n\n8 18\n..................\n..................\n....##.......####.\n....#.#.....#.....\n...#...#....#.....\n..#.###.#...#.....\n.#.......#..#.....\n#.........#..####.", "sample_input": "2 3\n"}, "reference_outputs": ["3 3\n##.\n..#\n#.#\n"], "source_document_id": "p03404", "source_text": "Score : 500 points\n\nProblem Statement\n\nYou are given two integers A and B.\n\nPrint a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section:\n\nLet the size of the grid be h \\times w (h vertical, w horizontal). Both h and w are at most 100.\n\nThe set of the squares painted white is divided into exactly A connected components.\n\nThe set of the squares painted black is divided into exactly B connected components.\n\nIt can be proved that there always exist one or more solutions under the conditions specified in Constraints section.\nIf there are multiple solutions, any of them may be printed.\n\nNotes\n\nTwo squares painted white, c_1 and c_2, are called connected when the square c_2 can be reached from the square c_1 passing only white squares by repeatedly moving up, down, left or right to an adjacent square.\n\nA set of squares painted white, S, forms a connected component when the following conditions are met:\n\nAny two squares in S are connected.\n\nNo pair of a square painted white that is not included in S and a square included in S is connected.\n\nA connected component of squares painted black is defined similarly.\n\nConstraints\n\n1 \\leq A \\leq 500\n\n1 \\leq B \\leq 500\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B\n\nOutput\n\nOutput should be in the following format:\n\nIn the first line, print integers h and w representing the size of the grid you constructed, with a space in between.\n\nThen, print h more lines. The i-th (1 \\leq i \\leq h) of these lines should contain a string s_i as follows:\n\nIf the square at the i-th row and j-th column (1 \\leq j \\leq w) in the grid is painted white, the j-th character in s_i should be ..\n\nIf the square at the i-th row and j-th column (1 \\leq j \\leq w) in the grid is painted black, the j-th character in s_i should be #.\n\nSample Input 1\n\n2 3\n\nSample Output 1\n\n3 3\n##.\n..#\n#.#\n\nThis output corresponds to the grid below:\n\nSample Input 2\n\n7 8\n\nSample Output 2\n\n3 5\n#.#.#\n.#.#.\n#.#.#\n\nSample Input 3\n\n1 1\n\nSample Output 3\n\n4 2\n..\n#.\n##\n##\n\nSample Input 4\n\n3 14\n\nSample Output 4\n\n8 18\n..................\n..................\n....##.......####.\n....#.#.....#.....\n...#...#....#.....\n..#.###.#...#.....\n.#.......#..#.....\n#.........#..####.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2486, "cpu_time_ms": 191, "memory_kb": 22248}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s336351485", "group_id": "codeNet:p03408", "input_text": "(defun solver ()\n (let* ((n (read)) (si (make-array n :fill-pointer 0))\n (temp 0) (maxcounter 0) word)\n (loop repeat n do\n (vector-push (read) si))\n (let* ((m (read)) (ti (make-array m :fill-pointer 0)))\n (loop repeat m do\n (vector-push (read) ti))\n (loop for i from 0 below n do\n (setf word (aref si i))\n (loop for j from 0 below n do\n (if (equal word (aref si j))\n (incf temp)))\n (loop for j from 0 below m do\n (if (equal word (aref ti j))\n (decf temp)))\n (when (> temp maxcounter) (setf maxcounter temp))\n (setf temp 0))\n (format t \"~a~%\" maxcounter))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1521336579, "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/s336351485.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s336351485", "user_id": "u183015556"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solver ()\n (let* ((n (read)) (si (make-array n :fill-pointer 0))\n (temp 0) (maxcounter 0) word)\n (loop repeat n do\n (vector-push (read) si))\n (let* ((m (read)) (ti (make-array m :fill-pointer 0)))\n (loop repeat m do\n (vector-push (read) ti))\n (loop for i from 0 below n do\n (setf word (aref si i))\n (loop for j from 0 below n do\n (if (equal word (aref si j))\n (incf temp)))\n (loop for j from 0 below m do\n (if (equal word (aref ti j))\n (decf temp)))\n (when (> temp maxcounter) (setf maxcounter temp))\n (setf temp 0))\n (format t \"~a~%\" maxcounter))))\n\n(solver)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 779, "cpu_time_ms": 440, "memory_kb": 16488}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s685796327", "group_id": "codeNet:p03409", "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;;; Maximum bipartite matching by Ford-Fulkerson\n;;;\n(defun find-matching (graph)\n \"Takes adjacency list and returns the maximal bipartite matching. Note that\nthis function doesn't check if GRAPH is bipartite.\"\n (declare #.OPT\n ((simple-array list (*)) graph))\n (let* ((n (length graph))\n (checked (make-array n :element-type 'bit :initial-element 0))\n (matching (make-array n :element-type 'fixnum :initial-element -1))\n (res 0))\n (declare ((integer 0 #.most-positive-fixnum) res))\n (labels ((%match (vertex) ; Returns T if VERTEX is matched.\n (setf (aref checked vertex) 1)\n (dolist (candidate (aref graph vertex))\n (let ((partner-of-candidate (aref matching candidate)))\n (when (or (= -1 partner-of-candidate)\n (and (zerop (aref checked partner-of-candidate))\n (%match partner-of-candidate)))\n (setf (aref matching vertex) candidate\n (aref matching candidate) vertex)\n (return t))))))\n (dotimes (v n (values matching res))\n (when (= -1 (aref matching v))\n (fill checked 0)\n (when (%match v)\n (incf res)))))))\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 dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 main ()\n (declare #.OPT)\n (let* ((n (read))\n (red-xs (make-array n :element-type 'uint8))\n (red-ys (make-array n :element-type 'uint8))\n (blue-xs (make-array n :element-type 'uint8))\n (blue-ys (make-array n :element-type 'uint8))\n (graph (make-array (* 2 n) :element-type 'list :initial-element nil)))\n (declare (uint8 n))\n (dotimes (idx n)\n (split-ints-bind (x y) (read-line)\n (setf (aref red-xs idx) x\n (aref red-ys idx) y)))\n (dotimes (idx n)\n (split-ints-bind (x y) (read-line)\n (setf (aref blue-xs idx) x\n (aref blue-ys idx) y)))\n (dotimes (red-idx n)\n (dotimes (blue-idx n)\n (when (and (< (aref red-xs red-idx)\n (aref blue-xs blue-idx))\n (< (aref red-ys red-idx)\n (aref blue-ys blue-idx)))\n (push (+ n blue-idx) (aref graph red-idx))\n (push red-idx (aref graph (+ n blue-idx))))))\n (println (nth-value 1 (find-matching graph)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1553750495, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03409.html", "problem_id": "p03409", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03409/input.txt", "sample_output_relpath": "derived/input_output/data/p03409/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03409/Lisp/s685796327.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s685796327", "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;;; Maximum bipartite matching by Ford-Fulkerson\n;;;\n(defun find-matching (graph)\n \"Takes adjacency list and returns the maximal bipartite matching. Note that\nthis function doesn't check if GRAPH is bipartite.\"\n (declare #.OPT\n ((simple-array list (*)) graph))\n (let* ((n (length graph))\n (checked (make-array n :element-type 'bit :initial-element 0))\n (matching (make-array n :element-type 'fixnum :initial-element -1))\n (res 0))\n (declare ((integer 0 #.most-positive-fixnum) res))\n (labels ((%match (vertex) ; Returns T if VERTEX is matched.\n (setf (aref checked vertex) 1)\n (dolist (candidate (aref graph vertex))\n (let ((partner-of-candidate (aref matching candidate)))\n (when (or (= -1 partner-of-candidate)\n (and (zerop (aref checked partner-of-candidate))\n (%match partner-of-candidate)))\n (setf (aref matching vertex) candidate\n (aref matching candidate) vertex)\n (return t))))))\n (dotimes (v n (values matching res))\n (when (= -1 (aref matching v))\n (fill checked 0)\n (when (%match v)\n (incf res)))))))\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 dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 main ()\n (declare #.OPT)\n (let* ((n (read))\n (red-xs (make-array n :element-type 'uint8))\n (red-ys (make-array n :element-type 'uint8))\n (blue-xs (make-array n :element-type 'uint8))\n (blue-ys (make-array n :element-type 'uint8))\n (graph (make-array (* 2 n) :element-type 'list :initial-element nil)))\n (declare (uint8 n))\n (dotimes (idx n)\n (split-ints-bind (x y) (read-line)\n (setf (aref red-xs idx) x\n (aref red-ys idx) y)))\n (dotimes (idx n)\n (split-ints-bind (x y) (read-line)\n (setf (aref blue-xs idx) x\n (aref blue-ys idx) y)))\n (dotimes (red-idx n)\n (dotimes (blue-idx n)\n (when (and (< (aref red-xs red-idx)\n (aref blue-xs blue-idx))\n (< (aref red-ys red-idx)\n (aref blue-ys blue-idx)))\n (push (+ n blue-idx) (aref graph red-idx))\n (push red-idx (aref graph (+ n blue-idx))))))\n (println (nth-value 1 (find-matching graph)))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nOn a two-dimensional plane, there are N red points and N blue points.\nThe coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).\n\nA red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.\n\nAt most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq N \\leq 100\n\n0 \\leq a_i, b_i, c_i, d_i < 2N\n\na_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.\n\nb_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.\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 b_N\nc_1 d_1\nc_2 d_2\n:\nc_N d_N\n\nOutput\n\nPrint the maximum number of friendly pairs.\n\nSample Input 1\n\n3\n2 0\n3 1\n1 3\n4 2\n0 4\n5 5\n\nSample Output 1\n\n2\n\nFor example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).\n\nSample Input 2\n\n3\n0 0\n1 1\n5 2\n2 3\n3 4\n4 5\n\nSample Output 2\n\n2\n\nFor example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).\n\nSample Input 3\n\n2\n2 2\n3 3\n0 0\n1 1\n\nSample Output 3\n\n0\n\nIt is possible that no pair can be formed.\n\nSample Input 4\n\n5\n0 0\n7 3\n2 2\n4 8\n1 6\n8 5\n6 9\n5 4\n9 1\n3 7\n\nSample Output 4\n\n5\n\nSample Input 5\n\n5\n0 0\n1 1\n5 5\n6 6\n7 7\n2 2\n3 3\n4 4\n8 8\n9 9\n\nSample Output 5\n\n4", "sample_input": "3\n2 0\n3 1\n1 3\n4 2\n0 4\n5 5\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03409", "source_text": "Score : 400 points\n\nProblem Statement\n\nOn a two-dimensional plane, there are N red points and N blue points.\nThe coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).\n\nA red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.\n\nAt most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.\n\nConstraints\n\nAll input values are integers.\n\n1 \\leq N \\leq 100\n\n0 \\leq a_i, b_i, c_i, d_i < 2N\n\na_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.\n\nb_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.\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 b_N\nc_1 d_1\nc_2 d_2\n:\nc_N d_N\n\nOutput\n\nPrint the maximum number of friendly pairs.\n\nSample Input 1\n\n3\n2 0\n3 1\n1 3\n4 2\n0 4\n5 5\n\nSample Output 1\n\n2\n\nFor example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).\n\nSample Input 2\n\n3\n0 0\n1 1\n5 2\n2 3\n3 4\n4 5\n\nSample Output 2\n\n2\n\nFor example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).\n\nSample Input 3\n\n2\n2 2\n3 3\n0 0\n1 1\n\nSample Output 3\n\n0\n\nIt is possible that no pair can be formed.\n\nSample Input 4\n\n5\n0 0\n7 3\n2 2\n4 8\n1 6\n8 5\n6 9\n5 4\n9 1\n3 7\n\nSample Output 4\n\n5\n\nSample Input 5\n\n5\n0 0\n1 1\n5 5\n6 6\n7 7\n2 2\n3 3\n4 4\n8 8\n9 9\n\nSample Output 5\n\n4", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4120, "cpu_time_ms": 330, "memory_kb": 32608}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s941627073", "group_id": "codeNet:p03415", "input_text": "(format t \"~A~A~A~%\" (subseq (read-line) 0 1) (subseq (read-line) 1 2) (subseq (read-line) 2 3))", "language": "Lisp", "metadata": {"date": 1593827737, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s941627073.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s941627073", "user_id": "u136500538"}, "prompt_components": {"gold_output": "abc\n", "input_to_evaluate": "(format t \"~A~A~A~%\" (subseq (read-line) 0 1) (subseq (read-line) 1 2) (subseq (read-line) 2 3))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 24132}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s774364938", "group_id": "codeNet:p03416", "input_text": "(princ (loop :for x :from (read) :upto (read) :count(= x (parse-integer (reverse (format nil \"~A\" x))))))\n", "language": "Lisp", "metadata": {"date": 1545346146, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s774364938.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s774364938", "user_id": "u610490393"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(princ (loop :for x :from (read) :upto (read) :count(= x (parse-integer (reverse (format nil \"~A\" x))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 230, "memory_kb": 66152}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s121643252", "group_id": "codeNet:p03423", "input_text": "(princ(floor n 3))", "language": "Lisp", "metadata": {"date": 1599546382, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s121643252.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s121643252", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(princ(floor n 3))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 18, "cpu_time_ms": 24, "memory_kb": 26632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s524227485", "group_id": "codeNet:p03423", "input_text": "(format t \"~A~%\" (floor (/ (read) 3)))\n", "language": "Lisp", "metadata": {"date": 1520216657, "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/s524227485.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s524227485", "user_id": "u994767958"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(format t \"~A~%\" (floor (/ (read) 3)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s175449029", "group_id": "codeNet:p03426", "input_text": "(let ((h (read))\n (w (read))\n (d (read))\n (co (make-array '(90001 2) :element-type 'integer\n :initial-element 0\n :adjustable t))\n (dif (make-array '(90001) :element-type 'integer\n :initial-element 0\n :adjustable t))\n (temp 0)\n q\n l\n r)\n (dotimes (i h)\n (dotimes (j w)\n (setf temp (read))\n (setf (aref co temp 0) i)\n (setf (aref co temp 1) j)))\n (loop for x from 1 upto d\n do (loop for y from 1\n do (setf temp (+ x (* y d)))\n while (< temp (* h w)) do (setf (aref dif temp) (+ (aref dif (- temp d)) (abs (- (aref co temp 0) (aref co (- temp d) 0))) (abs (- (aref co temp 1) (aref co (- temp d) 1)))))))\n (setf q (read))\n (dotimes (x q)\n (setf l (read))\n (setf r (read))\n (format t \"~A~%\" (- (aref dif r) (aref dif l)))))", "language": "Lisp", "metadata": {"date": 1520220136, "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/s175449029.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s175449029", "user_id": "u994767958"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(let ((h (read))\n (w (read))\n (d (read))\n (co (make-array '(90001 2) :element-type 'integer\n :initial-element 0\n :adjustable t))\n (dif (make-array '(90001) :element-type 'integer\n :initial-element 0\n :adjustable t))\n (temp 0)\n q\n l\n r)\n (dotimes (i h)\n (dotimes (j w)\n (setf temp (read))\n (setf (aref co temp 0) i)\n (setf (aref co temp 1) j)))\n (loop for x from 1 upto d\n do (loop for y from 1\n do (setf temp (+ x (* y d)))\n while (< temp (* h w)) do (setf (aref dif temp) (+ (aref dif (- temp d)) (abs (- (aref co temp 0) (aref co (- temp d) 0))) (abs (- (aref co temp 1) (aref co (- temp d) 1)))))))\n (setf q (read))\n (dotimes (x q)\n (setf l (read))\n (setf r (read))\n (format t \"~A~%\" (- (aref dif r) (aref dif l)))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 952, "cpu_time_ms": 1375, "memory_kb": 70052}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s554841844", "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 alice)))\n\n (format t \"~A~%\" alice)\n (format t \"~A~%\" bob)\n\n\n (format t \"~A~%\" (- (reduce #'+ alice) (reduce #'+ bob))))\n", "language": "Lisp", "metadata": {"date": 1598576189, "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/s554841844.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s554841844", "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 alice)))\n\n (format t \"~A~%\" alice)\n (format t \"~A~%\" bob)\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 472, "cpu_time_ms": 22, "memory_kb": 24380}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s964647167", "group_id": "codeNet:p03434", "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": 1521663430, "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/s964647167.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s964647167", "user_id": "u711147786"}, "prompt_components": {"gold_output": "2\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\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 38, "memory_kb": 7908}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s384730568", "group_id": "codeNet:p03434", "input_text": "(let* ((n (read))\n (a (make-array n :element-type 'integer\n :adjustable t\n :fill-pointer 0))\n (ch (make-array n :element-type 'integer\n :adjustable t\n :fill-pointer 0))\n (max-num 0)\n pointer\n (point-a 0)\n (point-b 0))\n (dotimes (i n)\n (setf (aref a i) (read))\n (setf (aref ch i) 0))\n (dotimes (i n)\n (setf max-num 0)\n (dotimes (j n)\n (if (and (< max-num (aref a j)) (= 0 (aref ch j))) (progn (setf pointer j)\n (setf max-num (aref a j)))))\n (setf (aref ch pointer) 1)\n (if (= (mod i 2) 0) (setf point-a (+ point-a (aref a pointer))) (setf point-b (+ point-b (aref a pointer)))))\n (format t \"~A~%\" (- point-a point-b)))\n", "language": "Lisp", "metadata": {"date": 1519012972, "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/s384730568.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s384730568", "user_id": "u994767958"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (a (make-array n :element-type 'integer\n :adjustable t\n :fill-pointer 0))\n (ch (make-array n :element-type 'integer\n :adjustable t\n :fill-pointer 0))\n (max-num 0)\n pointer\n (point-a 0)\n (point-b 0))\n (dotimes (i n)\n (setf (aref a i) (read))\n (setf (aref ch i) 0))\n (dotimes (i n)\n (setf max-num 0)\n (dotimes (j n)\n (if (and (< max-num (aref a j)) (= 0 (aref ch j))) (progn (setf pointer j)\n (setf max-num (aref a j)))))\n (setf (aref ch pointer) 1)\n (if (= (mod i 2) 0) (setf point-a (+ point-a (aref a pointer))) (setf point-b (+ point-b (aref a pointer)))))\n (format t \"~A~%\" (- point-a point-b)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 837, "cpu_time_ms": 448, "memory_kb": 16744}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s829829738", "group_id": "codeNet:p03435", "input_text": ";;; Utils (quoted from https://competitive12.blogspot.com/2020/03/common-lisp.html)\n\n\n;; Read fixnum\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;; fast read-line\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\n;;; invoke child process\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; Write code here\n;-------------------\n\n\n(defun judge (board)\n (let ((a (make-array 3))\n (b (make-array 3)))\n (setf (aref a 0) 0)\n (setf (aref b 0) (- (aref board 0 0) (aref a 0)))\n (setf (aref b 1) (- (aref board 0 1) (aref a 0)))\n (setf (aref b 2) (- (aref board 0 2) (aref a 0)))\n (setf (aref a 1) (- (aref board 1 1) (aref b 1)))\n (setf (aref a 2) (- (aref board 2 2) (aref b 2)))\n (let ((flag t))\n (dotimes (i 3)\n (dotimes (j 3)\n (when (/= (aref board i j) (+ (aref a i)\n (aref b j)))\n (setq flag nil))))\n flag)))\n\n\n\n(defun solve (board)\n (if (judge board)\n \"Yes\"\n \"No\"))\n\n(defun main ()\n (let ((board (make-array '(3 3))))\n (dotimes (i 3)\n (dotimes (j 3)\n (setf (aref board i j) (read))))\n (princ (solve board))\n (fresh-line)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1595431831, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s829829738.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s829829738", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";;; Utils (quoted from https://competitive12.blogspot.com/2020/03/common-lisp.html)\n\n\n;; Read fixnum\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;; fast read-line\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\n;;; invoke child process\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; Write code here\n;-------------------\n\n\n(defun judge (board)\n (let ((a (make-array 3))\n (b (make-array 3)))\n (setf (aref a 0) 0)\n (setf (aref b 0) (- (aref board 0 0) (aref a 0)))\n (setf (aref b 1) (- (aref board 0 1) (aref a 0)))\n (setf (aref b 2) (- (aref board 0 2) (aref a 0)))\n (setf (aref a 1) (- (aref board 1 1) (aref b 1)))\n (setf (aref a 2) (- (aref board 2 2) (aref b 2)))\n (let ((flag t))\n (dotimes (i 3)\n (dotimes (j 3)\n (when (/= (aref board i j) (+ (aref a i)\n (aref b j)))\n (setq flag nil))))\n flag)))\n\n\n\n(defun solve (board)\n (if (judge board)\n \"Yes\"\n \"No\"))\n\n(defun main ()\n (let ((board (make-array '(3 3))))\n (dotimes (i 3)\n (dotimes (j 3)\n (setf (aref board i j) (read))))\n (princ (solve board))\n (fresh-line)))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3539, "cpu_time_ms": 35, "memory_kb": 25336}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s954684285", "group_id": "codeNet:p03435", "input_text": "(setq a(read))\n(setq b(read))\n(setq c(read))\n(setq d(read))\n(setq e(read))\n(setq f(read))\n(setq g(read))\n(setq h(read))\n(setq i(read))\n(setq x(+ a (* c -151) (* b 150)))\n(setq y(+ d (* f -151) (* e 150)))\n(setq z(+ g (* i -151) (* h 150)))\n(princ(if(= (* y z)(* x z))\"Yes\"\"No\"))", "language": "Lisp", "metadata": {"date": 1594457506, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s954684285.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s954684285", "user_id": "u657913472"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(setq a(read))\n(setq b(read))\n(setq c(read))\n(setq d(read))\n(setq e(read))\n(setq f(read))\n(setq g(read))\n(setq h(read))\n(setq i(read))\n(setq x(+ a (* c -151) (* b 150)))\n(setq y(+ d (* f -151) (* e 150)))\n(setq z(+ g (* i -151) (* h 150)))\n(princ(if(= (* y z)(* x z))\"Yes\"\"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 278, "cpu_time_ms": 17, "memory_kb": 24352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s756697553", "group_id": "codeNet:p03436", "input_text": "(defun solve-route (s ps cnt)\n (if (null ps)\n s\n (progn\n (loop\n for p in ps\n do (setf (aref s (first p) (second p)) cnt))\n (solve-route\n s\n (remove-if #'null (loop\n for p in ps \n append (loop for x in '((0 -1) (-1 0) (0 1) (1 0))\n collect (let* ((npos (list (+ (first p) (first x))\n (+ (second p) (second x))))\n (nval (aref s (first npos) (second npos))))\n (if nval\n (if (< (1+ cnt) nval)\n npos))))))\n (1+ cnt)))))\n \n(let* ((h (read))\n (w (read))\n (white-pos 0)\n (s (make-array (list (+ h 2) (+ w 2)) :initial-element nil)))\n (loop for i from 1 to h do\n (loop for j from 1 to w\n for c in (concatenate 'list (read-line)) do\n (if (equal c #\\#)\n (setf (aref s i j) -1)\n (progn (incf white-pos)\n (setf (aref s i j) 9999)))))\n (solve-route s '((1 1)) 0)\n (let* ((ans (- white-pos (aref s h w) 1)))\n (if (<= 0 ans)\n (format t \"~a~%\" ans)\n (format t \"~a~%\" -1))))\n", "language": "Lisp", "metadata": {"date": 1569814780, "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/s756697553.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s756697553", "user_id": "u652695471"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun solve-route (s ps cnt)\n (if (null ps)\n s\n (progn\n (loop\n for p in ps\n do (setf (aref s (first p) (second p)) cnt))\n (solve-route\n s\n (remove-if #'null (loop\n for p in ps \n append (loop for x in '((0 -1) (-1 0) (0 1) (1 0))\n collect (let* ((npos (list (+ (first p) (first x))\n (+ (second p) (second x))))\n (nval (aref s (first npos) (second npos))))\n (if nval\n (if (< (1+ cnt) nval)\n npos))))))\n (1+ cnt)))))\n \n(let* ((h (read))\n (w (read))\n (white-pos 0)\n (s (make-array (list (+ h 2) (+ w 2)) :initial-element nil)))\n (loop for i from 1 to h do\n (loop for j from 1 to w\n for c in (concatenate 'list (read-line)) do\n (if (equal c #\\#)\n (setf (aref s i j) -1)\n (progn (incf white-pos)\n (setf (aref s i j) 9999)))))\n (solve-route s '((1 1)) 0)\n (let* ((ans (- white-pos (aref s h w) 1)))\n (if (<= 0 ans)\n (format t \"~a~%\" ans)\n (format t \"~a~%\" -1))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1258, "cpu_time_ms": 2109, "memory_kb": 543300}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s388584500", "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(define-binary-heap heap\n :order (lambda (p1 p2)\n (< (the uint62 (pheap-peek p1))\n (the uint62 (pheap-peek p2))))\n :element-type pheap)\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": 1569990835, "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/s388584500.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s388584500", "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(define-binary-heap heap\n :order (lambda (p1 p2)\n (< (the uint62 (pheap-peek p1))\n (the uint62 (pheap-peek p2))))\n :element-type pheap)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9091, "cpu_time_ms": 268, "memory_kb": 31968}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s912938444", "group_id": "codeNet:p03441", "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(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/shuffle\n (:use :cl)\n (:export #:shuffle!))\n(in-package :cp/shuffle)\n\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;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/shuffle :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 solve (root graph)\n (declare #.cl-user::opt\n ((simple-array list (*)) graph))\n (let ((res 1))\n (declare (uint31 res))\n (sb-int:named-let dfs ((v root) (parent -1))\n (let ((deg 0)\n (antenna 0))\n (declare (uint31 deg antenna))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (incf deg)\n (when (dfs child v)\n (incf antenna))))\n (assert (>= deg antenna))\n (let ((delta (max (- deg antenna 1) 0)))\n (incf res delta)\n (> (+ antenna delta) 0))))\n res))\n\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 'uint31 :initial-element 0)))\n (dotimes (i (- n 1))\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (incf (aref degs a))\n (incf (aref degs b))\n (push a (aref graph b))\n (push b (aref graph a))))\n (let ((roots (coerce (loop for i below n\n when (= 1 (aref degs i))\n collect i)\n '(simple-array uint31 (*)))))\n (shuffle! roots)\n (println (loop for i below (min 200 (length roots))\n for root = (aref roots i)\n minimize (solve root graph))))))\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(5am:test :sample\n (5am:is\n (equal \"2\n\"\n (run \"5\n0 1\n0 2\n0 3\n3 4\n\" nil)))\n (5am:is\n (equal \"1\n\"\n (run \"2\n0 1\n\" nil)))\n (5am:is\n (equal \"3\n\"\n (run \"10\n2 8\n6 0\n4 1\n7 6\n2 3\n8 6\n6 9\n2 4\n5 8\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1600843335, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03441.html", "problem_id": "p03441", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03441/input.txt", "sample_output_relpath": "derived/input_output/data/p03441/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03441/Lisp/s912938444.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s912938444", "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 (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/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/shuffle\n (:use :cl)\n (:export #:shuffle!))\n(in-package :cp/shuffle)\n\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;; BEGIN_USE_PACKAGE\n(eval-when (:compile-toplevel :load-toplevel :execute)\n (use-package :cp/shuffle :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 solve (root graph)\n (declare #.cl-user::opt\n ((simple-array list (*)) graph))\n (let ((res 1))\n (declare (uint31 res))\n (sb-int:named-let dfs ((v root) (parent -1))\n (let ((deg 0)\n (antenna 0))\n (declare (uint31 deg antenna))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (incf deg)\n (when (dfs child v)\n (incf antenna))))\n (assert (>= deg antenna))\n (let ((delta (max (- deg antenna 1) 0)))\n (incf res delta)\n (> (+ antenna delta) 0))))\n res))\n\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 'uint31 :initial-element 0)))\n (dotimes (i (- n 1))\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (incf (aref degs a))\n (incf (aref degs b))\n (push a (aref graph b))\n (push b (aref graph a))))\n (let ((roots (coerce (loop for i below n\n when (= 1 (aref degs i))\n collect i)\n '(simple-array uint31 (*)))))\n (shuffle! roots)\n (println (loop for i below (min 200 (length roots))\n for root = (aref roots i)\n minimize (solve root graph))))))\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(5am:test :sample\n (5am:is\n (equal \"2\n\"\n (run \"5\n0 1\n0 2\n0 3\n3 4\n\" nil)))\n (5am:is\n (equal \"1\n\"\n (run \"2\n0 1\n\" nil)))\n (5am:is\n (equal \"3\n\"\n (run \"10\n2 8\n6 0\n4 1\n7 6\n2 3\n8 6\n6 9\n2 4\n5 8\n\" nil))))\n", "problem_context": "Score : 900 points\n\nProblem Statement\n\nWe have a tree with N vertices.\nThe vertices are numbered 0 through N - 1, and the i-th edge (0 ≤ i < N - 1) comnnects Vertex a_i and b_i.\nFor each pair of vertices u and v (0 ≤ u, v < N), we define the distance d(u, v) as the number of edges in the path u-v.\n\nIt is expected that one of the vertices will be invaded by aliens from outer space.\nSnuke wants to immediately identify that vertex when the invasion happens.\nTo do so, he has decided to install an antenna on some vertices.\n\nFirst, he decides the number of antennas, K (1 ≤ K ≤ N).\nThen, he chooses K different vertices, x_0, x_1, ..., x_{K - 1}, on which he installs Antenna 0, 1, ..., K - 1, respectively.\nIf Vertex v is invaded by aliens, Antenna k (0 ≤ k < K) will output the distance d(x_k, v).\nBased on these K outputs, Snuke will identify the vertex that is invaded.\nThus, in order to identify the invaded vertex no matter which one is invaded, the following condition must hold:\n\nFor each vertex u (0 ≤ u < N), consider the vector (d(x_0, u), ..., d(x_{K - 1}, u)). These N vectors are distinct.\n\nFind the minumum value of K, the number of antennas, when the condition is satisfied.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n0 ≤ a_i, b_i < N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_0 b_0\na_1 b_1\n:\na_{N - 2} b_{N - 2}\n\nOutput\n\nPrint the minumum value of K, the number of antennas, when the condition is satisfied.\n\nSample Input 1\n\n5\n0 1\n0 2\n0 3\n3 4\n\nSample Output 1\n\n2\n\nFor example, install an antenna on Vertex 1 and 3.\nThen, the following five vectors are distinct:\n\n(d(1, 0), d(3, 0)) = (1, 1)\n\n(d(1, 1), d(3, 1)) = (0, 2)\n\n(d(1, 2), d(3, 2)) = (2, 2)\n\n(d(1, 3), d(3, 3)) = (2, 0)\n\n(d(1, 4), d(3, 4)) = (3, 1)\n\nSample Input 2\n\n2\n0 1\n\nSample Output 2\n\n1\n\nFor example, install an antenna on Vertex 0.\n\nSample Input 3\n\n10\n2 8\n6 0\n4 1\n7 6\n2 3\n8 6\n6 9\n2 4\n5 8\n\nSample Output 3\n\n3\n\nFor example, install an antenna on Vertex 0, 4, 9.", "sample_input": "5\n0 1\n0 2\n0 3\n3 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03441", "source_text": "Score : 900 points\n\nProblem Statement\n\nWe have a tree with N vertices.\nThe vertices are numbered 0 through N - 1, and the i-th edge (0 ≤ i < N - 1) comnnects Vertex a_i and b_i.\nFor each pair of vertices u and v (0 ≤ u, v < N), we define the distance d(u, v) as the number of edges in the path u-v.\n\nIt is expected that one of the vertices will be invaded by aliens from outer space.\nSnuke wants to immediately identify that vertex when the invasion happens.\nTo do so, he has decided to install an antenna on some vertices.\n\nFirst, he decides the number of antennas, K (1 ≤ K ≤ N).\nThen, he chooses K different vertices, x_0, x_1, ..., x_{K - 1}, on which he installs Antenna 0, 1, ..., K - 1, respectively.\nIf Vertex v is invaded by aliens, Antenna k (0 ≤ k < K) will output the distance d(x_k, v).\nBased on these K outputs, Snuke will identify the vertex that is invaded.\nThus, in order to identify the invaded vertex no matter which one is invaded, the following condition must hold:\n\nFor each vertex u (0 ≤ u < N), consider the vector (d(x_0, u), ..., d(x_{K - 1}, u)). These N vectors are distinct.\n\nFind the minumum value of K, the number of antennas, when the condition is satisfied.\n\nConstraints\n\n2 ≤ N ≤ 10^5\n\n0 ≤ a_i, b_i < N\n\nThe given graph is a tree.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_0 b_0\na_1 b_1\n:\na_{N - 2} b_{N - 2}\n\nOutput\n\nPrint the minumum value of K, the number of antennas, when the condition is satisfied.\n\nSample Input 1\n\n5\n0 1\n0 2\n0 3\n3 4\n\nSample Output 1\n\n2\n\nFor example, install an antenna on Vertex 1 and 3.\nThen, the following five vectors are distinct:\n\n(d(1, 0), d(3, 0)) = (1, 1)\n\n(d(1, 1), d(3, 1)) = (0, 2)\n\n(d(1, 2), d(3, 2)) = (2, 2)\n\n(d(1, 3), d(3, 3)) = (2, 0)\n\n(d(1, 4), d(3, 4)) = (3, 1)\n\nSample Input 2\n\n2\n0 1\n\nSample Output 2\n\n1\n\nFor example, install an antenna on Vertex 0.\n\nSample Input 3\n\n10\n2 8\n6 0\n4 1\n7 6\n2 3\n8 6\n6 9\n2 4\n5 8\n\nSample Output 3\n\n3\n\nFor example, install an antenna on Vertex 0, 4, 9.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7192, "cpu_time_ms": 1232, "memory_kb": 37952}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s238254365", "group_id": "codeNet:p03447", "input_text": "(let ((a (read))\n (b (read))\n (c (read)))\n (princ (mod (- a b) c)))", "language": "Lisp", "metadata": {"date": 1545350030, "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/s238254365.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s238254365", "user_id": "u610490393"}, "prompt_components": {"gold_output": "84\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (c (read)))\n (princ (mod (- a b) c)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 24, "memory_kb": 4324}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s895004216", "group_id": "codeNet:p03447", "input_text": "(let* ((X (read))\n (A (read))\n (B (read))\n (budget (- X A)))\n (format t \"~A~%\" (mod budget B)))\n", "language": "Lisp", "metadata": {"date": 1518643770, "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/s895004216.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s895004216", "user_id": "u845061132"}, "prompt_components": {"gold_output": "84\n", "input_to_evaluate": "(let* ((X (read))\n (A (read))\n (B (read))\n (budget (- X A)))\n (format t \"~A~%\" (mod budget 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 125, "memory_kb": 12640}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s766339033", "group_id": "codeNet:p03449", "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 &aux (a-sum (comulative #'+ a)) (b-sum (reverse (comulative #'+ (reverse b)))))\n (loop for i in a-sum\n for j in b-sum\n maximize (+ i j)))\n\n(let ((n (read)))\n (princ (main (read-times n) (read-times n))))\n", "language": "Lisp", "metadata": {"date": 1589145359, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03449.html", "problem_id": "p03449", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03449/input.txt", "sample_output_relpath": "derived/input_output/data/p03449/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03449/Lisp/s766339033.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s766339033", "user_id": "u493610446"}, "prompt_components": {"gold_output": "14\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 &aux (a-sum (comulative #'+ a)) (b-sum (reverse (comulative #'+ (reverse b)))))\n (loop for i in a-sum\n for j in b-sum\n maximize (+ i j)))\n\n(let ((n (read)))\n (princ (main (read-times n) (read-times n))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have a 2 \\times N grid. We will denote the square at the i-th row and j-th column (1 \\leq i \\leq 2, 1 \\leq j \\leq N) as (i, j).\n\nYou are initially in the top-left square, (1, 1).\nYou will travel to the bottom-right square, (2, N), by repeatedly moving right or down.\n\nThe square (i, j) contains A_{i, j} candies.\nYou will collect all the candies you visit during the travel.\nThe top-left and bottom-right squares also contain candies, and you will also collect them.\n\nAt most how many candies can you collect when you choose the best way to travel?\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq A_{i, j} \\leq 100 (1 \\leq i \\leq 2, 1 \\leq j \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} ... A_{1, N}\nA_{2, 1} A_{2, 2} ... A_{2, N}\n\nOutput\n\nPrint the maximum number of candies that can be collected.\n\nSample Input 1\n\n5\n3 2 2 4 1\n1 2 2 2 1\n\nSample Output 1\n\n14\n\nThe number of collected candies will be maximized when you:\n\nmove right three times, then move down once, then move right once.\n\nSample Input 2\n\n4\n1 1 1 1\n1 1 1 1\n\nSample Output 2\n\n5\n\nYou will always collect the same number of candies, regardless of how you travel.\n\nSample Input 3\n\n7\n3 3 4 5 4 5 3\n5 3 4 4 2 3 2\n\nSample Output 3\n\n29\n\nSample Input 4\n\n1\n2\n3\n\nSample Output 4\n\n5", "sample_input": "5\n3 2 2 4 1\n1 2 2 2 1\n"}, "reference_outputs": ["14\n"], "source_document_id": "p03449", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have a 2 \\times N grid. We will denote the square at the i-th row and j-th column (1 \\leq i \\leq 2, 1 \\leq j \\leq N) as (i, j).\n\nYou are initially in the top-left square, (1, 1).\nYou will travel to the bottom-right square, (2, N), by repeatedly moving right or down.\n\nThe square (i, j) contains A_{i, j} candies.\nYou will collect all the candies you visit during the travel.\nThe top-left and bottom-right squares also contain candies, and you will also collect them.\n\nAt most how many candies can you collect when you choose the best way to travel?\n\nConstraints\n\n1 \\leq N \\leq 100\n\n1 \\leq A_{i, j} \\leq 100 (1 \\leq i \\leq 2, 1 \\leq j \\leq N)\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} ... A_{1, N}\nA_{2, 1} A_{2, 2} ... A_{2, N}\n\nOutput\n\nPrint the maximum number of candies that can be collected.\n\nSample Input 1\n\n5\n3 2 2 4 1\n1 2 2 2 1\n\nSample Output 1\n\n14\n\nThe number of collected candies will be maximized when you:\n\nmove right three times, then move down once, then move right once.\n\nSample Input 2\n\n4\n1 1 1 1\n1 1 1 1\n\nSample Output 2\n\n5\n\nYou will always collect the same number of candies, regardless of how you travel.\n\nSample Input 3\n\n7\n3 3 4 5 4 5 3\n5 3 4 4 2 3 2\n\nSample Output 3\n\n29\n\nSample Input 4\n\n1\n2\n3\n\nSample Output 4\n\n5", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2843, "cpu_time_ms": 56, "memory_kb": 13876}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s869484305", "group_id": "codeNet:p03456", "input_text": "(let ((a (write-to-string (read)))\n (b (write-to-string (read))))\n\n (format t \"~A~%\"\n (if (integerp (sqrt (parse-integer (concatenate 'string a b))))\n \"Yes\"\n \"No\")))\n", "language": "Lisp", "metadata": {"date": 1597963942, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s869484305.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s869484305", "user_id": "u336541610"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((a (write-to-string (read)))\n (b (write-to-string (read))))\n\n (format t \"~A~%\"\n (if (integerp (sqrt (parse-integer (concatenate 'string a b))))\n \"Yes\"\n \"No\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 21, "memory_kb": 24168}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s090602901", "group_id": "codeNet:p03456", "input_text": "(defun sqrtp (x)\n (equal 0.0 (rem (sqrt x) 1)))\n(defun joint (x y)\n (if (eq y 100)\n (+ (* x 1000) 100)\n (if (> y 9)\n (+ (* x 100) y)\n (+ (* x 10) y))))\n(defun yn (x)\n (if x \"Yes\" \"No\"))\n \n(format t (yn (sqrtp (joint (read) (read)))))", "language": "Lisp", "metadata": {"date": 1585855421, "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/s090602901.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s090602901", "user_id": "u123011403"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun sqrtp (x)\n (equal 0.0 (rem (sqrt x) 1)))\n(defun joint (x y)\n (if (eq y 100)\n (+ (* x 1000) 100)\n (if (> y 9)\n (+ (* x 100) y)\n (+ (* x 10) y))))\n(defun 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 264, "cpu_time_ms": 24, "memory_kb": 4960}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s469594975", "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 x y))))", "language": "Lisp", "metadata": {"date": 1585854650, "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/s469594975.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s469594975", "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 x y))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 192, "cpu_time_ms": 132, "memory_kb": 14304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s808756505", "group_id": "codeNet:p03456", "input_text": "(defun solver ()\n (let ((ab (parse-integer (format nil \"~a~a\" (read) (read)))))\n (loop for i from 0 to ab\n when (equalp (expt i 2) ab)\n return (format t \"Yes~%\")\n finally (format t \"No~%\"))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1520091508, "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/s808756505.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s808756505", "user_id": "u183015556"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun solver ()\n (let ((ab (parse-integer (format nil \"~a~a\" (read) (read)))))\n (loop for i from 0 to ab\n when (equalp (expt i 2) ab)\n return (format t \"Yes~%\")\n finally (format t \"No~%\"))))\n\n(solver)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 1158, "memory_kb": 13668}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s394189685", "group_id": "codeNet:p03456", "input_text": "(let* ((a (read))\n (b (read))\n (ab (parse-integer (format nil \"~A~A\" a b)))\n (sab (isqrt ab)))\n (format t (if (= (* sab sab) ab) \"Yes\" \"No\")))", "language": "Lisp", "metadata": {"date": 1517878240, "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/s394189685.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s394189685", "user_id": "u275710783"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((a (read))\n (b (read))\n (ab (parse-integer (format nil \"~A~A\" a b)))\n (sab (isqrt ab)))\n (format t (if (= (* sab sab) ab) \"Yes\" \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 124, "memory_kb": 11624}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s248431341", "group_id": "codeNet:p03460", "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 get-2dcumul))\n(defun get-2dcumul (table y0 x0 y1 x1)\n (+ (- (aref table y1 x1)\n (aref table y0 x1)\n (aref table y1 x0))\n (aref table y0 x0)))\n\n(declaim (inline fast-read-char))\n(defun fast-read-char (&optional (in *standard-input*))\n #-swank (declare (inline read-byte)\n (sb-kernel:ansi-stream in))\n #-swank (code-char (read-byte in))\n #+swank (read-char in))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (btable (make-array (list (+ 1 (* 3 k)) (+ 1 (* 3 k)))\n :element-type 'uint32 :initial-element 0))\n (wtable (make-array (list (+ 1 (* 3 k)) (+ 1 (* 3 k)))\n :element-type 'uint32 :initial-element 0)))\n (declare (uint32 n k))\n (dotimes (i n)\n (let* ((x (+ 1 (mod (read-fixnum) (* 2 k)))) ;; updated point\n (y (+ 1 (mod (read-fixnum) (* 2 k))))\n (table (if (char= (fast-read-char) #\\B) btable wtable)))\n (incf (aref table y x))\n (when (<= (+ x (* 2 k)) (* 3 k))\n (incf (aref table y (+ x (* 2 k))))\n (when (<= (+ y (* 2 k)) (* 3 k))\n (incf (aref table (+ y (* 2 k)) (+ x (* 2 k))))))\n (when (<= (+ y (* 2 k)) (* 3 k))\n (incf (aref table (+ y (* 2 k)) x)))))\n (dotimes (x (+ 1 (* 3 k)))\n (dotimes (y (* 3 k))\n (incf (aref btable (+ y 1) x) (aref btable y x))\n (incf (aref wtable (+ y 1) x) (aref wtable y x))))\n (dotimes (y (+ 1 (* 3 k)))\n (dotimes (x (* 3 k))\n (incf (aref btable y (+ x 1)) (aref btable y x))\n (incf (aref wtable y (+ x 1)) (aref wtable y x))))\n (let ((res 0))\n (declare (uint32 res))\n (dotimes (x k)\n (dotimes (y k)\n (let ((value (+ (get-2dcumul btable y x (+ y k) (+ x k))\n (get-2dcumul btable (+ y k) (+ x k) (+ y k k) (+ x k k))\n (get-2dcumul wtable y (+ x k) (+ y k) (+ x k k))\n (get-2dcumul wtable (+ y k) x (+ y k k) (+ x k)))))\n (setf res (max res value)))))\n (println res))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560593357, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03460.html", "problem_id": "p03460", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03460/input.txt", "sample_output_relpath": "derived/input_output/data/p03460/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03460/Lisp/s248431341.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s248431341", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\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 get-2dcumul))\n(defun get-2dcumul (table y0 x0 y1 x1)\n (+ (- (aref table y1 x1)\n (aref table y0 x1)\n (aref table y1 x0))\n (aref table y0 x0)))\n\n(declaim (inline fast-read-char))\n(defun fast-read-char (&optional (in *standard-input*))\n #-swank (declare (inline read-byte)\n (sb-kernel:ansi-stream in))\n #-swank (code-char (read-byte in))\n #+swank (read-char in))\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (btable (make-array (list (+ 1 (* 3 k)) (+ 1 (* 3 k)))\n :element-type 'uint32 :initial-element 0))\n (wtable (make-array (list (+ 1 (* 3 k)) (+ 1 (* 3 k)))\n :element-type 'uint32 :initial-element 0)))\n (declare (uint32 n k))\n (dotimes (i n)\n (let* ((x (+ 1 (mod (read-fixnum) (* 2 k)))) ;; updated point\n (y (+ 1 (mod (read-fixnum) (* 2 k))))\n (table (if (char= (fast-read-char) #\\B) btable wtable)))\n (incf (aref table y x))\n (when (<= (+ x (* 2 k)) (* 3 k))\n (incf (aref table y (+ x (* 2 k))))\n (when (<= (+ y (* 2 k)) (* 3 k))\n (incf (aref table (+ y (* 2 k)) (+ x (* 2 k))))))\n (when (<= (+ y (* 2 k)) (* 3 k))\n (incf (aref table (+ y (* 2 k)) x)))))\n (dotimes (x (+ 1 (* 3 k)))\n (dotimes (y (* 3 k))\n (incf (aref btable (+ y 1) x) (aref btable y x))\n (incf (aref wtable (+ y 1) x) (aref wtable y x))))\n (dotimes (y (+ 1 (* 3 k)))\n (dotimes (x (* 3 k))\n (incf (aref btable y (+ x 1)) (aref btable y x))\n (incf (aref wtable y (+ x 1)) (aref wtable y x))))\n (let ((res 0))\n (declare (uint32 res))\n (dotimes (x k)\n (dotimes (y k)\n (let ((value (+ (get-2dcumul btable y x (+ y k) (+ x k))\n (get-2dcumul btable (+ y k) (+ x k) (+ y k k) (+ x k k))\n (get-2dcumul wtable y (+ x k) (+ y k) (+ x k k))\n (get-2dcumul wtable (+ y k) x (+ y k k) (+ x k)))))\n (setf res (max res value)))))\n (println res))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nAtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K.\nHere, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square.\nBelow is an example of a checked pattern of side 3:\n\nAtCoDeer has N desires.\nThe i-th desire is represented by x_i, y_i and c_i.\nIf c_i is B, it means that he wants to paint the square (x_i,y_i) black; if c_i is W, he wants to paint the square (x_i,y_i) white.\nAt most how many desires can he satisfy at the same time?\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n1 ≤ K ≤ 1000\n\n0 ≤ x_i ≤ 10^9\n\n0 ≤ y_i ≤ 10^9\n\nIf i ≠ j, then (x_i,y_i) ≠ (x_j,y_j).\n\nc_i is B or W.\n\nN, K, x_i and y_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nx_1 y_1 c_1\nx_2 y_2 c_2\n:\nx_N y_N c_N\n\nOutput\n\nPrint the maximum number of desires that can be satisfied at the same time.\n\nSample Input 1\n\n4 3\n0 1 W\n1 2 W\n5 3 B\n5 4 B\n\nSample Output 1\n\n4\n\nHe can satisfy all his desires by painting as shown in the example above.\n\nSample Input 2\n\n2 1000\n0 0 B\n0 1 W\n\nSample Output 2\n\n2\n\nSample Input 3\n\n6 2\n1 2 B\n2 1 W\n2 2 B\n1 0 B\n0 6 W\n4 5 W\n\nSample Output 3\n\n4", "sample_input": "4 3\n0 1 W\n1 2 W\n5 3 B\n5 4 B\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03460", "source_text": "Score : 500 points\n\nProblem Statement\n\nAtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K.\nHere, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square.\nBelow is an example of a checked pattern of side 3:\n\nAtCoDeer has N desires.\nThe i-th desire is represented by x_i, y_i and c_i.\nIf c_i is B, it means that he wants to paint the square (x_i,y_i) black; if c_i is W, he wants to paint the square (x_i,y_i) white.\nAt most how many desires can he satisfy at the same time?\n\nConstraints\n\n1 ≤ N ≤ 10^5\n\n1 ≤ K ≤ 1000\n\n0 ≤ x_i ≤ 10^9\n\n0 ≤ y_i ≤ 10^9\n\nIf i ≠ j, then (x_i,y_i) ≠ (x_j,y_j).\n\nc_i is B or W.\n\nN, K, x_i and y_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN K\nx_1 y_1 c_1\nx_2 y_2 c_2\n:\nx_N y_N c_N\n\nOutput\n\nPrint the maximum number of desires that can be satisfied at the same time.\n\nSample Input 1\n\n4 3\n0 1 W\n1 2 W\n5 3 B\n5 4 B\n\nSample Output 1\n\n4\n\nHe can satisfy all his desires by painting as shown in the example above.\n\nSample Input 2\n\n2 1000\n0 0 B\n0 1 W\n\nSample Output 2\n\n2\n\nSample Input 3\n\n6 2\n1 2 B\n2 1 W\n2 2 B\n1 0 B\n0 6 W\n4 5 W\n\nSample Output 3\n\n4", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4487, "cpu_time_ms": 419, "memory_kb": 98792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s187022460", "group_id": "codeNet:p03469", "input_text": "(let* ((l (concatenate 'list (read-line))))\n\n (format t \"~A~%\"\n (concatenate 'string (append (concatenate 'list \"2018\") (subseq l 4)))))\n\n", "language": "Lisp", "metadata": {"date": 1597962631, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s187022460.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s187022460", "user_id": "u336541610"}, "prompt_components": {"gold_output": "2018/01/07\n", "input_to_evaluate": "(let* ((l (concatenate 'list (read-line))))\n\n (format t \"~A~%\"\n (concatenate 'string (append (concatenate 'list \"2018\") (subseq l 4)))))\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 148, "cpu_time_ms": 18, "memory_kb": 24168}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s250716146", "group_id": "codeNet:p03469", "input_text": "(let ((da (concatenate 'list (read-line))))\n (setf (nth 3 da) #\\8)\n (princ da))", "language": "Lisp", "metadata": {"date": 1542929956, "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/s250716146.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s250716146", "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 da))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 75, "memory_kb": 8416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s905156307", "group_id": "codeNet:p03469", "input_text": "(let ((str (read-line)))\n (setf (aref str 3) #\\8)\n (write-line str))\n", "language": "Lisp", "metadata": {"date": 1515413635, "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/s905156307.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s905156307", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2018/01/07\n", "input_to_evaluate": "(let ((str (read-line)))\n (setf (aref str 3) #\\8)\n (write-line str))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 84, "memory_kb": 8676}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s847949281", "group_id": "codeNet:p03473", "input_text": "(princ(- 48(read)))", "language": "Lisp", "metadata": {"date": 1545346486, "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/s847949281.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s847949281", "user_id": "u610490393"}, "prompt_components": {"gold_output": "27\n", "input_to_evaluate": "(princ(- 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 19, "cpu_time_ms": 5, "memory_kb": 2788}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s686436448", "group_id": "codeNet:p03473", "input_text": "(princ (- 48 (read)))\n(princ \"\n\")", "language": "Lisp", "metadata": {"date": 1529314098, "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/s686436448.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s686436448", "user_id": "u714587753"}, "prompt_components": {"gold_output": "27\n", "input_to_evaluate": "(princ (- 48 (read)))\n(princ \"\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 5, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s113058484", "group_id": "codeNet:p03473", "input_text": "(- 48 (read))", "language": "Lisp", "metadata": {"date": 1515359236, "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/s113058484.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s113058484", "user_id": "u648138491"}, "prompt_components": {"gold_output": "27\n", "input_to_evaluate": "(- 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13, "cpu_time_ms": 10, "memory_kb": 2916}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s657170945", "group_id": "codeNet:p03474", "input_text": "(let ((a (read))\n (b (read))\n (s (concatenate 'list (read-line))))\n\n (defun judge-hyphen (p lst)\n (if (char= (nth p lst) #\\-)\n t\n nil))\n\n (defun judge-length (q r lst)\n (if (= (length lst) (+ q r 1))\n t\n nil))\n\n (defun judge-unique (lst)\n (if (= (count #\\- lst) 1)\n t\n nil))\n\n (format t \"~A~%\"\n (if (and (judge-hyphen a s)\n (judge-length a b s)\n (judge-unique s))\n \"Yes\"\n \"No\")))\n", "language": "Lisp", "metadata": {"date": 1597883946, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s657170945.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s657170945", "user_id": "u336541610"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (s (concatenate 'list (read-line))))\n\n (defun judge-hyphen (p lst)\n (if (char= (nth p lst) #\\-)\n t\n nil))\n\n (defun judge-length (q r lst)\n (if (= (length lst) (+ q r 1))\n t\n nil))\n\n (defun judge-unique (lst)\n (if (= (count #\\- lst) 1)\n t\n nil))\n\n (format t \"~A~%\"\n (if (and (judge-hyphen a s)\n (judge-length a b s)\n (judge-unique s))\n \"Yes\"\n \"No\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 500, "cpu_time_ms": 21, "memory_kb": 23552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s867746625", "group_id": "codeNet:p03474", "input_text": "(let* ((a (read))\n (b (read))\n (s (read-line))\n (as (subseq s 0 a))\n (cs (subseq s a (1+ a)))\n (bs (subseq s (1+ a))))\n (if (and (every #'digit-char-p as)\n (equal cs \"-\")\n (every #'digit-char-p bs))\n (princ \"Yes\")\n (princ \"No\")))", "language": "Lisp", "metadata": {"date": 1591496876, "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/s867746625.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s867746625", "user_id": "u425762225"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((a (read))\n (b (read))\n (s (read-line))\n (as (subseq s 0 a))\n (cs (subseq s a (1+ a)))\n (bs (subseq s (1+ a))))\n (if (and (every #'digit-char-p as)\n (equal cs \"-\")\n (every #'digit-char-p bs))\n (princ \"Yes\")\n (princ \"No\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 310, "cpu_time_ms": 107, "memory_kb": 11748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s693069811", "group_id": "codeNet:p03479", "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 println (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n;; Hauptteil\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n\n(defun push-carton (carton rest candidate-rest)\n (if (null rest)\n (if candidate-rest\n (push carton (car candidate-rest))\n (push (list carton) *haystacks*))\n (let ((stack (car rest)))\n (if (and (<= carton (car stack))\n (or (null candidate-rest)\n (<= (car stack) (caar candidate-rest))))\n (push-carton carton (cdr rest) rest)\n (push-carton carton (cdr rest) candidate-rest)))))\n\n(defun main ()\n (let ((n (read))\n (*haystacks* nil))\n (declare (special *haystacks*))\n (dotimes (i n)\n (push-carton (read) *haystacks* nil))\n (println (length *haystacks*))))\n\n#-swank(main)\n\n", "language": "Lisp", "metadata": {"date": 1534480039, "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/s693069811.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s693069811", "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 println (obj &optional (stream '*standard-output*))\n `(prog1 (princ ,obj ,stream) (terpri ,stream)))\n\n;; Hauptteil\n\n(deftype uint nil `(integer 0 ,(expt 10 9)))\n\n(defun push-carton (carton rest candidate-rest)\n (if (null rest)\n (if candidate-rest\n (push carton (car candidate-rest))\n (push (list carton) *haystacks*))\n (let ((stack (car rest)))\n (if (and (<= carton (car stack))\n (or (null candidate-rest)\n (<= (car stack) (caar candidate-rest))))\n (push-carton carton (cdr rest) rest)\n (push-carton carton (cdr rest) candidate-rest)))))\n\n(defun main ()\n (let ((n (read))\n (*haystacks* nil))\n (declare (special *haystacks*))\n (dotimes (i n)\n (push-carton (read) *haystacks* nil))\n (println (length *haystacks*))))\n\n#-swank(main)\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1060, "cpu_time_ms": 20, "memory_kb": 6632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s885879017", "group_id": "codeNet:p03479", "input_text": "(defun f (x y)\n (labels ((inner (n rv)\n\t (if (<= n y)\n\t\t (inner (* n 2) (1+ rv))\n\t\t (1- rv))))\n (inner x 1)))\n\n(print (f (read) (read)))", "language": "Lisp", "metadata": {"date": 1514522874, "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/s885879017.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s885879017", "user_id": "u396817842"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun f (x y)\n (labels ((inner (n rv)\n\t (if (<= n y)\n\t\t (inner (* n 2) (1+ rv))\n\t\t (1- rv))))\n (inner x 1)))\n\n(print (f (read) (read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 144, "cpu_time_ms": 16, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s794670282", "group_id": "codeNet:p03480", "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 dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 ((c0 (aref s 0)))\n (loop for c across s\n while (char= c0 c)\n count t)))\n\n(defun main ()\n (let* ((s (read-line))\n (len (length s)))\n (println\n (max (count-consecutive-chars s)\n (count-consecutive-chars (nreverse s))\n (ceiling len 2)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1554883140, "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/s794670282.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s794670282", "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 dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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 ((c0 (aref s 0)))\n (loop for c across s\n while (char= c0 c)\n count t)))\n\n(defun main ()\n (let* ((s (read-line))\n (len (length s)))\n (println\n (max (count-consecutive-chars s)\n (count-consecutive-chars (nreverse 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1499, "cpu_time_ms": 69, "memory_kb": 10596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s704511768", "group_id": "codeNet:p03480", "input_text": "(defun f (s)\n (loop for ch across s\n until (eq ch #\\1)\n count ch))\n\n(let ((x (read-line)))\n (format t \"~A~%\"\n (- (length x) (f x))))", "language": "Lisp", "metadata": {"date": 1514085894, "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/s704511768.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s704511768", "user_id": "u275710783"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun f (s)\n (loop for ch across s\n until (eq ch #\\1)\n count ch))\n\n(let ((x (read-line)))\n (format t \"~A~%\"\n (- (length x) (f x))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 456, "memory_kb": 16096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s707522751", "group_id": "codeNet:p03481", "input_text": "(defun solve (X Y &optional (i 0))\n (if (> X Y) i\n (solve (* X 2) Y (1+ i))))\n(princ (solve (read) (read)))", "language": "Lisp", "metadata": {"date": 1584560118, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03481.html", "problem_id": "p03481", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03481/input.txt", "sample_output_relpath": "derived/input_output/data/p03481/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03481/Lisp/s707522751.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s707522751", "user_id": "u334552723"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun solve (X Y &optional (i 0))\n (if (> X Y) i\n (solve (* X 2) Y (1+ i))))\n(princ (solve (read) (read)))", "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": "p03481", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 104, "memory_kb": 10084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s518696517", "group_id": "codeNet:p03484", "input_text": "(define N (read))\n(define alledges (make-vector N '()))\n(map (lambda (NO-USE)\n (let [(u (- (read) 1))\n\t (v (- (read) 1))]\n\t (set! (vector-ref alledges u)\n\t (cons v (vector-ref alledges u)))\n\t (set! (vector-ref alledges v)\n\t (cons u (vector-ref alledges v)))))\n (make-list (- N 1)))\n(define (remove* ele lst)\n (cond [(null? lst) lst]\n\t[(= ele (car lst))\n\t (remove* ele (cdr lst))]\n\t[else\n\t (cons (car lst)\n\t (remove* ele (cdr lst)))]))\n(define (get-fewest-paths-sons sons pa)\n (if (null? sons)\n 0\n (+ (get-fewest-paths (car sons) pa)\n\t (get-fewest-paths-sons (cdr sons) pa))))\n(define (get-fewest-paths u pa)\n (let [(edges (remove* pa (vector-ref alledges u)))\n\t(deg (length (vector-ref alledges u)))]\n (set! (vector-ref alledges u) edges)\n (+ (if (odd? deg) 1/2 0)\n (get-fewest-paths-sons edges u))))\n(define (let-paired lst lim)\n (letrec [(vec\n\t (list->vector (sort lst >))\n\t ;; (list->vector lst)\n\t )\n\t (len (vector-length vec))\n\t (pairpos\n\t (lambda (lp rp stack sp)\n\t (cond\n\t [(= lp len) -1]\n\t [(and (< rp lp)\n\t\t (or (null? stack)\n\t\t\t (> (car stack) lp)))\n\t\t(pairpos (+ lp 1) rp stack sp)]\n\t [else\n\t\t(while (and (<= lp rp)\n\t\t\t (<= (+ (vector-ref vec lp)\n\t\t\t\t (vector-ref vec rp)\n\t\t\t\t 2)\n\t\t\t\tlim))\n\t\t (set! stack (cons rp stack))\n\t\t (set! rp (- rp 1)))\n\t\t(cond\n\t\t [(and\n\t\t (not (null? stack))\n\t\t (= lp (car stack))\n\t\t (null? (cdr stack)))\n\t\t (vector-ref vec lp)]\n\t\t [(null? stack)\n\t\t (if (and sp\n\t\t\t (<= (vector-ref vec lp) lim))\n\t\t (let [(con-ret (pairpos (+ lp 1) rp stack #f))]\n\t\t\t(cond\n\t\t\t [(not con-ret) #f]\n\t\t\t [(odd? len) (vector-ref vec lp)]\n\t\t\t [else con-ret]))\n\t\t #f)]\n\t\t [else\n\t\t (when (= lp (car stack))\n\t\t\t(set! stack (cdr stack)))\n\t\t (pairpos (+ lp 1) rp (cdr stack) sp)])])))\n\t (res\n\t (pairpos 0 (- len 1) '() #t))]\n res))\n(define (find* ele lst)\n (cond\n [(null? lst) #f]\n [(eq? ele (car lst)) #t]\n [else (find* ele (cdr lst))]))\n(define (check-OK? u pa lim)\n (let* [(edges (vector-ref alledges u))\n\t ;; (son-ret (map (lambda (v) (check-OK? v u lim))\n\t ;; \t edges))\n\t (son-ret '())]\n (while (and (not (null? edges))\n \t\t(or (null? son-ret)\n \t\t (car son-ret)))\n \t (set! son-ret\n \t\t (cons (check-OK? (car edges) u lim)\n \t\t son-ret))\n \t (set! edges (cdr edges)))\n (if (find* #f son-ret)\n \t#f\n \t(let [(pair-ret (let-paired son-ret lim))]\n \t (if pair-ret\n \t (+ pair-ret 1)\n \t #f)))))\n\n(define (check-OK?-lr lv rv)\n (if (= (+ lv 1) rv)\n lv\n (let* [(mid (quotient (+ lv rv) 2))\n\t ;; (NO-USE (print \"check-OK?-lr \" (- mid 1)))\n\t (check-res (check-OK? 0 -1 (- mid 1)))]\n\t(if (and check-res\n\t\t (<= check-res (- mid 1)))\n\t (check-OK?-lr lv mid)\n\t (check-OK?-lr mid rv)))))\n(print (get-fewest-paths 0 -1) \" \" (check-OK?-lr 0 (+ N 1)))\n", "language": "Lisp", "metadata": {"date": 1515386256, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03484.html", "problem_id": "p03484", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03484/input.txt", "sample_output_relpath": "derived/input_output/data/p03484/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03484/Lisp/s518696517.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s518696517", "user_id": "u035500741"}, "prompt_components": {"gold_output": "3 2\n", "input_to_evaluate": "(define N (read))\n(define alledges (make-vector N '()))\n(map (lambda (NO-USE)\n (let [(u (- (read) 1))\n\t (v (- (read) 1))]\n\t (set! (vector-ref alledges u)\n\t (cons v (vector-ref alledges u)))\n\t (set! (vector-ref alledges v)\n\t (cons u (vector-ref alledges v)))))\n (make-list (- N 1)))\n(define (remove* ele lst)\n (cond [(null? lst) lst]\n\t[(= ele (car lst))\n\t (remove* ele (cdr lst))]\n\t[else\n\t (cons (car lst)\n\t (remove* ele (cdr lst)))]))\n(define (get-fewest-paths-sons sons pa)\n (if (null? sons)\n 0\n (+ (get-fewest-paths (car sons) pa)\n\t (get-fewest-paths-sons (cdr sons) pa))))\n(define (get-fewest-paths u pa)\n (let [(edges (remove* pa (vector-ref alledges u)))\n\t(deg (length (vector-ref alledges u)))]\n (set! (vector-ref alledges u) edges)\n (+ (if (odd? deg) 1/2 0)\n (get-fewest-paths-sons edges u))))\n(define (let-paired lst lim)\n (letrec [(vec\n\t (list->vector (sort lst >))\n\t ;; (list->vector lst)\n\t )\n\t (len (vector-length vec))\n\t (pairpos\n\t (lambda (lp rp stack sp)\n\t (cond\n\t [(= lp len) -1]\n\t [(and (< rp lp)\n\t\t (or (null? stack)\n\t\t\t (> (car stack) lp)))\n\t\t(pairpos (+ lp 1) rp stack sp)]\n\t [else\n\t\t(while (and (<= lp rp)\n\t\t\t (<= (+ (vector-ref vec lp)\n\t\t\t\t (vector-ref vec rp)\n\t\t\t\t 2)\n\t\t\t\tlim))\n\t\t (set! stack (cons rp stack))\n\t\t (set! rp (- rp 1)))\n\t\t(cond\n\t\t [(and\n\t\t (not (null? stack))\n\t\t (= lp (car stack))\n\t\t (null? (cdr stack)))\n\t\t (vector-ref vec lp)]\n\t\t [(null? stack)\n\t\t (if (and sp\n\t\t\t (<= (vector-ref vec lp) lim))\n\t\t (let [(con-ret (pairpos (+ lp 1) rp stack #f))]\n\t\t\t(cond\n\t\t\t [(not con-ret) #f]\n\t\t\t [(odd? len) (vector-ref vec lp)]\n\t\t\t [else con-ret]))\n\t\t #f)]\n\t\t [else\n\t\t (when (= lp (car stack))\n\t\t\t(set! stack (cdr stack)))\n\t\t (pairpos (+ lp 1) rp (cdr stack) sp)])])))\n\t (res\n\t (pairpos 0 (- len 1) '() #t))]\n res))\n(define (find* ele lst)\n (cond\n [(null? lst) #f]\n [(eq? ele (car lst)) #t]\n [else (find* ele (cdr lst))]))\n(define (check-OK? u pa lim)\n (let* [(edges (vector-ref alledges u))\n\t ;; (son-ret (map (lambda (v) (check-OK? v u lim))\n\t ;; \t edges))\n\t (son-ret '())]\n (while (and (not (null? edges))\n \t\t(or (null? son-ret)\n \t\t (car son-ret)))\n \t (set! son-ret\n \t\t (cons (check-OK? (car edges) u lim)\n \t\t son-ret))\n \t (set! edges (cdr edges)))\n (if (find* #f son-ret)\n \t#f\n \t(let [(pair-ret (let-paired son-ret lim))]\n \t (if pair-ret\n \t (+ pair-ret 1)\n \t #f)))))\n\n(define (check-OK?-lr lv rv)\n (if (= (+ lv 1) rv)\n lv\n (let* [(mid (quotient (+ lv rv) 2))\n\t ;; (NO-USE (print \"check-OK?-lr \" (- mid 1)))\n\t (check-res (check-OK? 0 -1 (- mid 1)))]\n\t(if (and check-res\n\t\t (<= check-res (- mid 1)))\n\t (check-OK?-lr lv mid)\n\t (check-OK?-lr mid rv)))))\n(print (get-fewest-paths 0 -1) \" \" (check-OK?-lr 0 (+ N 1)))\n", "problem_context": "Score : 900 points\n\nProblem Statement\n\nTakahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc.\n\nA Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge (1\\leq i\\leq N-1) connects Vertex a_i and b_i.\n\nHe would like to make one as follows:\n\nSpecify two non-negative integers A and B.\n\nPrepare A Christmas Paths whose lengths are at most B. Here, a Christmas Path of length X is a graph with X+1 vertices and X edges such that, if we properly number the vertices 1 through X+1, the i-th edge (1\\leq i\\leq X) will connect Vertex i and i+1.\n\nRepeat the following operation until he has one connected tree:\n\nSelect two vertices x and y that belong to different connected components. Combine x and y into one vertex. More precisely, for each edge (p,y) incident to the vertex y, add the edge (p,x). Then, delete the vertex y and all the edges incident to y.\n\nProperly number the vertices in the tree.\n\nTakahashi would like to find the lexicographically smallest pair (A,B) such that he can make a Christmas Tree, that is, find the smallest A, and find the smallest B under the condition that A is minimized.\n\nSolve this problem for him.\n\nConstraints\n\n2 \\leq N \\leq 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 the lexicographically smallest (A,B), print A and B with a space in between.\n\nSample Input 1\n\n7\n1 2\n2 3\n2 4\n4 5\n4 6\n6 7\n\nSample Output 1\n\n3 2\n\nWe can make a Christmas Tree as shown in the figure below:\n\nSample Input 2\n\n8\n1 2\n2 3\n3 4\n4 5\n5 6\n5 7\n5 8\n\nSample Output 2\n\n2 5\n\nSample Input 3\n\n10\n1 2\n2 3\n3 4\n2 5\n6 5\n6 7\n7 8\n5 9\n10 5\n\nSample Output 3\n\n3 4", "sample_input": "7\n1 2\n2 3\n2 4\n4 5\n4 6\n6 7\n"}, "reference_outputs": ["3 2\n"], "source_document_id": "p03484", "source_text": "Score : 900 points\n\nProblem Statement\n\nTakahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc.\n\nA Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge (1\\leq i\\leq N-1) connects Vertex a_i and b_i.\n\nHe would like to make one as follows:\n\nSpecify two non-negative integers A and B.\n\nPrepare A Christmas Paths whose lengths are at most B. Here, a Christmas Path of length X is a graph with X+1 vertices and X edges such that, if we properly number the vertices 1 through X+1, the i-th edge (1\\leq i\\leq X) will connect Vertex i and i+1.\n\nRepeat the following operation until he has one connected tree:\n\nSelect two vertices x and y that belong to different connected components. Combine x and y into one vertex. More precisely, for each edge (p,y) incident to the vertex y, add the edge (p,x). Then, delete the vertex y and all the edges incident to y.\n\nProperly number the vertices in the tree.\n\nTakahashi would like to find the lexicographically smallest pair (A,B) such that he can make a Christmas Tree, that is, find the smallest A, and find the smallest B under the condition that A is minimized.\n\nSolve this problem for him.\n\nConstraints\n\n2 \\leq N \\leq 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 the lexicographically smallest (A,B), print A and B with a space in between.\n\nSample Input 1\n\n7\n1 2\n2 3\n2 4\n4 5\n4 6\n6 7\n\nSample Output 1\n\n3 2\n\nWe can make a Christmas Tree as shown in the figure below:\n\nSample Input 2\n\n8\n1 2\n2 3\n3 4\n4 5\n5 6\n5 7\n5 8\n\nSample Output 2\n\n2 5\n\nSample Input 3\n\n10\n1 2\n2 3\n3 4\n2 5\n6 5\n6 7\n7 8\n5 9\n10 5\n\nSample Output 3\n\n3 4", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2891, "cpu_time_ms": 124, "memory_kb": 10084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s848724619", "group_id": "codeNet:p03485", "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": 1579239852, "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/s848724619.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s848724619", "user_id": "u245103825"}, "prompt_components": {"gold_output": "2\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 : 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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:s970404111", "group_id": "codeNet:p03486", "input_text": "(defun check (a b)\n (cond ((and (null a) (null b)) nil)\n ((null a) t)\n ((null b) nil)\n ((char< (car a) (car b)) t)\n ((char= (car a) (car b)) (check (cdr a) (cdr b)))))\n\n(let* ((a (read-line))\n (b (read-line)))\n (if (check (concatenate 'list (sort a #'char<))\n (concatenate 'list (sort b #'char>)))\n (princ \"Yes\")\n (princ \"No\")))\n", "language": "Lisp", "metadata": {"date": 1579239348, "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/s970404111.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s970404111", "user_id": "u245103825"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun check (a b)\n (cond ((and (null a) (null b)) nil)\n ((null a) t)\n ((null b) nil)\n ((char< (car a) (car b)) t)\n ((char= (car a) (car b)) (check (cdr a) (cdr b)))))\n\n(let* ((a (read-line))\n (b (read-line)))\n (if (check (concatenate 'list (sort a #'char<))\n (concatenate 'list (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 10, "memory_kb": 3556}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s167643356", "group_id": "codeNet:p03486", "input_text": "(defun string-sort (k a)\n (map 'string #'code-char (sort (map 'vector #'char-code k) a)))\n(if (string< (string-sort (read-line) #'<) (string-sort (read-line) #'>))\n (princ \"Yes\") (princ \"No\"))", "language": "Lisp", "metadata": {"date": 1557755062, "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/s167643356.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s167643356", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun string-sort (k a)\n (map 'string #'code-char (sort (map 'vector #'char-code k) a)))\n(if (string< (string-sort (read-line) #'<) (string-sort (read-line) #'>))\n (princ \"Yes\") (princ \"No\"))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 144, "memory_kb": 13800}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s231729881", "group_id": "codeNet:p03486", "input_text": "(princ(if(string< #1=(sort(read-line)#'char<)(reverse #1#))\"Yes\"\"No\"))", "language": "Lisp", "metadata": {"date": 1534303840, "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/s231729881.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s231729881", "user_id": "u657913472"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(princ(if(string< #1=(sort(read-line)#'char<)(reverse #1#))\"Yes\"\"No\"))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 21, "memory_kb": 3936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s303614853", "group_id": "codeNet:p03486", "input_text": "(let ((a (read-line))\n (b (read-line)))\n (setf a (sort (copy-seq a) #'char<)\n b (sort (copy-seq b) #'char>))\n (format t \"~A~%\"\n (if (string< a b) \"Yes\" \"No\")))", "language": "Lisp", "metadata": {"date": 1513538235, "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/s303614853.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s303614853", "user_id": "u275710783"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((a (read-line))\n (b (read-line)))\n (setf a (sort (copy-seq a) #'char<)\n b (sort (copy-seq b) #'char>))\n (format t \"~A~%\"\n (if (string< a b) \"Yes\" \"No\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 78, "memory_kb": 10084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s635333168", "group_id": "codeNet:p03487", "input_text": "(let* ((a (read-line))\n (b (sort (read-from-string (concatenate 'string \"(\" (read-line) \")\")) #'<))\n (c (remove-duplicates b)))\n (if (null b)\n t\n (princ (apply #'+ (mapcar #'(lambda (x)\n (let ((co (count x b)))\n (cond ((plusp (- x co)) co)\n ((minusp (- x co)) (- co x))\n (t 0))))\n c)))))\n", "language": "Lisp", "metadata": {"date": 1579241172, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03487.html", "problem_id": "p03487", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03487/input.txt", "sample_output_relpath": "derived/input_output/data/p03487/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03487/Lisp/s635333168.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s635333168", "user_id": "u245103825"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((a (read-line))\n (b (sort (read-from-string (concatenate 'string \"(\" (read-line) \")\")) #'<))\n (c (remove-duplicates b)))\n (if (null b)\n t\n (princ (apply #'+ (mapcar #'(lambda (x)\n (let ((co (count x b)))\n (cond ((plusp (- x co)) co)\n ((minusp (- x co)) (- co x))\n (t 0))))\n c)))))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).\nYour objective is to remove some of the elements in a so that a will be a good sequence.\n\nHere, an sequence b is a good sequence when the following condition holds true:\n\nFor each element x in b, the value x occurs exactly x times in b.\n\nFor example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.\n\nFind the minimum number of elements that needs to be removed so that a will be a good sequence.\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 minimum number of elements that needs to be removed so that a will be a good sequence.\n\nSample Input 1\n\n4\n3 3 3 3\n\nSample Output 1\n\n1\n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence.\n\nSample Input 2\n\n5\n2 4 1 4 2\n\nSample Output 2\n\n2\n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good sequence.\n\nSample Input 3\n\n6\n1 2 2 3 3 3\n\nSample Output 3\n\n0\n\nSample Input 4\n\n1\n1000000000\n\nSample Output 4\n\n1\n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\nSample Input 5\n\n8\n2 7 1 8 2 8 1 8\n\nSample Output 5\n\n5", "sample_input": "4\n3 3 3 3\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03487", "source_text": "Score : 300 points\n\nProblem Statement\n\nYou are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).\nYour objective is to remove some of the elements in a so that a will be a good sequence.\n\nHere, an sequence b is a good sequence when the following condition holds true:\n\nFor each element x in b, the value x occurs exactly x times in b.\n\nFor example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.\n\nFind the minimum number of elements that needs to be removed so that a will be a good sequence.\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 minimum number of elements that needs to be removed so that a will be a good sequence.\n\nSample Input 1\n\n4\n3 3 3 3\n\nSample Output 1\n\n1\n\nWe can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence.\n\nSample Input 2\n\n5\n2 4 1 4 2\n\nSample Output 2\n\n2\n\nWe can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good sequence.\n\nSample Input 3\n\n6\n1 2 2 3 3 3\n\nSample Output 3\n\n0\n\nSample Input 4\n\n1\n1000000000\n\nSample Output 4\n\n1\n\nRemove one occurrence of 10^9. Then, () is a good sequence.\n\nSample Input 5\n\n8\n2 7 1 8 2 8 1 8\n\nSample Output 5\n\n5", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 465, "cpu_time_ms": 2104, "memory_kb": 49508}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s853778509", "group_id": "codeNet:p03488", "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 (declare #.OPT)\n (let* ((s (read-line))\n (len (length s))\n (x (read))\n (y (read))\n (hs (make-array len :element-type 'uint16 :fill-pointer 0))\n (vs (make-array len :element-type 'uint16 :fill-pointer 0)))\n (declare ((integer 1 8000) len)\n ((integer -8000 8000) x y))\n (loop with prev-t = -1\n with dest = hs\n for i below (length s)\n when (char= #\\T (char s i))\n do (vector-push (- i prev-t 1) dest)\n (setq prev-t i\n dest (if (eql dest hs) vs hs))\n finally (vector-push (- i prev-t 1) dest))\n (if\n (and\n (let ((dp1 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit))\n (dp2 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit)))\n (setf (aref dp1 (+ len (aref hs 0))) 1)\n (if (= 1 (length hs))\n (= (aref hs 0) x)\n (loop for h across (subseq hs 1)\n for dp = dp1 then (if (eql dp dp1) dp2 dp1)\n for dest-dp = dp2 then (if (eql dest-dp dp1) dp2 dp1)\n do (fill dest-dp 0)\n (loop for i of-type uint16 below (length dp)\n when (= 1 (aref dp i))\n do (setf (aref dest-dp (+ i h)) 1\n (aref dest-dp (- i h)) 1))\n finally (return (= 1 (aref dest-dp (+ len x)))))))\n (let ((dp1 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit))\n (dp2 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit)))\n (setf (aref dp1 len) 1)\n (if (zerop (length vs))\n (zerop y)\n (loop for v across vs\n for dp = dp1 then (if (eql dp dp1) dp2 dp1)\n for dest-dp = dp2 then (if (eql dest-dp dp1) dp2 dp1)\n do (fill dest-dp 0)\n (loop for i of-type uint16 below (length dp)\n when (= 1 (aref dp i))\n do (setf (aref dest-dp (+ i v)) 1\n (aref dest-dp (- i v)) 1))\n finally (return (= 1 (aref dest-dp (+ len y))))))))\n (write-line \"Yes\")\n (write-line \"No\"))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559278352, "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/s853778509.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s853778509", "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 (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 (declare #.OPT)\n (let* ((s (read-line))\n (len (length s))\n (x (read))\n (y (read))\n (hs (make-array len :element-type 'uint16 :fill-pointer 0))\n (vs (make-array len :element-type 'uint16 :fill-pointer 0)))\n (declare ((integer 1 8000) len)\n ((integer -8000 8000) x y))\n (loop with prev-t = -1\n with dest = hs\n for i below (length s)\n when (char= #\\T (char s i))\n do (vector-push (- i prev-t 1) dest)\n (setq prev-t i\n dest (if (eql dest hs) vs hs))\n finally (vector-push (- i prev-t 1) dest))\n (if\n (and\n (let ((dp1 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit))\n (dp2 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit)))\n (setf (aref dp1 (+ len (aref hs 0))) 1)\n (if (= 1 (length hs))\n (= (aref hs 0) x)\n (loop for h across (subseq hs 1)\n for dp = dp1 then (if (eql dp dp1) dp2 dp1)\n for dest-dp = dp2 then (if (eql dest-dp dp1) dp2 dp1)\n do (fill dest-dp 0)\n (loop for i of-type uint16 below (length dp)\n when (= 1 (aref dp i))\n do (setf (aref dest-dp (+ i h)) 1\n (aref dest-dp (- i h)) 1))\n finally (return (= 1 (aref dest-dp (+ len x)))))))\n (let ((dp1 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit))\n (dp2 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit)))\n (setf (aref dp1 len) 1)\n (if (zerop (length vs))\n (zerop y)\n (loop for v across vs\n for dp = dp1 then (if (eql dp dp1) dp2 dp1)\n for dest-dp = dp2 then (if (eql dest-dp dp1) dp2 dp1)\n do (fill dest-dp 0)\n (loop for i of-type uint16 below (length dp)\n when (= 1 (aref dp i))\n do (setf (aref dest-dp (+ i v)) 1\n (aref dest-dp (- i v)) 1))\n finally (return (= 1 (aref dest-dp (+ len y))))))))\n (write-line \"Yes\")\n (write-line \"No\"))))\n\n#-swank(main)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3496, "cpu_time_ms": 226, "memory_kb": 14824}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s192400388", "group_id": "codeNet:p03494", "input_text": "(let* ((n (read))\n (l (loop repeat n\n collect (read))))\n\n (defun divisible (p)\n (zerop (mod p 2)))\n\n (defun divided (q)\n (/ q 2))\n\n (defun recursive-d (lst &optional (cnt 0))\n (if (not (every #'identity (mapcar #'divisible lst)))\n cnt\n (recursive-d (mapcar #'divided lst) (1+ cnt))))\n\n (format t \"~A~%\"\n (recursive-d l)))\n", "language": "Lisp", "metadata": {"date": 1597441551, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s192400388.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s192400388", "user_id": "u336541610"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (l (loop repeat n\n collect (read))))\n\n (defun divisible (p)\n (zerop (mod p 2)))\n\n (defun divided (q)\n (/ q 2))\n\n (defun recursive-d (lst &optional (cnt 0))\n (if (not (every #'identity (mapcar #'divisible lst)))\n cnt\n (recursive-d (mapcar #'divided lst) (1+ cnt))))\n\n (format t \"~A~%\"\n (recursive-d l)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 379, "cpu_time_ms": 15, "memory_kb": 24708}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s620224238", "group_id": "codeNet:p03494", "input_text": "(defun fun ()\n (let ((n (read))\n\t(x 0)\n\t(ans 0))\n (dotimes (i n)\n (setf x (logior x (read))))\n (loop\n (if (eq (logand x 1) 1) (return))\n (setf ans (1+ ans))\n (setf x (ash x -1)))\n ans))\n\n(format t \"~A~%\" (fun))\n", "language": "Lisp", "metadata": {"date": 1576698697, "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/s620224238.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s620224238", "user_id": "u691380397"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun fun ()\n (let ((n (read))\n\t(x 0)\n\t(ans 0))\n (dotimes (i n)\n (setf x (logior x (read))))\n (loop\n (if (eq (logand x 1) 1) (return))\n (setf ans (1+ ans))\n (setf x (ash x -1)))\n ans))\n\n(format t \"~A~%\" (fun))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 179, "memory_kb": 12388}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s130419229", "group_id": "codeNet:p03494", "input_text": "(defun fun ()\n (let ((n (read))\n\t(x 0)\n\t(ans 0))\n (dotimes (i n)\n (setf x (logior x (read))))\n (dotimes (i n)\n (if (eq (logand x 1) 1) (return))\n (setf ans (1+ ans))\n (setf x (ash x -1)))\n ans))\n\n(format t \"~A~%\" (fun))\n", "language": "Lisp", "metadata": {"date": 1576698616, "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/s130419229.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s130419229", "user_id": "u691380397"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun fun ()\n (let ((n (read))\n\t(x 0)\n\t(ans 0))\n (dotimes (i n)\n (setf x (logior x (read))))\n (dotimes (i n)\n (if (eq (logand x 1) 1) (return))\n (setf ans (1+ ans))\n (setf x (ash x -1)))\n ans))\n\n(format t \"~A~%\" (fun))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 164, "memory_kb": 12648}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s467115501", "group_id": "codeNet:p03494", "input_text": "(defun fun (n a)\n (let ((flg nil)\n\t(res 0))\n (loop\n (dotimes (i n)\n\t (if (not (zerop (rem (aref a i) 2)))\n\t (setf flg t)))\n (if (eq flg t) (return))\n (setf res (+ res 1))\n (dotimes (i n)\n\t (setf (aref a i) (/ (aref a i) 2))))\n res))\n\t \n\t \n\n(defun input ()\n (let* ((n (read))\n\t (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) (input)\n (format t \"~A~%\" (fun n a)))\n", "language": "Lisp", "metadata": {"date": 1576697534, "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/s467115501.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s467115501", "user_id": "u691380397"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun fun (n a)\n (let ((flg nil)\n\t(res 0))\n (loop\n (dotimes (i n)\n\t (if (not (zerop (rem (aref a i) 2)))\n\t (setf flg t)))\n (if (eq flg t) (return))\n (setf res (+ res 1))\n (dotimes (i n)\n\t (setf (aref a i) (/ (aref a i) 2))))\n res))\n\t \n\t \n\n(defun input ()\n (let* ((n (read))\n\t (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) (input)\n (format t \"~A~%\" (fun n a)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 472, "cpu_time_ms": 26, "memory_kb": 6504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s431138305", "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 a i) (/ (nth a i) 2))))\n (incf res))\n res))\n\n\n(defun create-data ()\n (let* ((n (read))\n\t (a ;; (make-array `(,n)) \n\t (loop for i to 10 collect i)))\n (dotimes (i n)\n ;; (setf (aref a i) (read))\n (setf (nth a i) (read)))\n (values n a)))\n\n(multiple-value-bind (n a) (create-data)\n (format t \"~a~%\" (shift-only n a)))\n", "language": "Lisp", "metadata": {"date": 1556076147, "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/s431138305.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s431138305", "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 a i) (/ (nth a i) 2))))\n (incf res))\n res))\n\n\n(defun create-data ()\n (let* ((n (read))\n\t (a ;; (make-array `(,n)) \n\t (loop for i to 10 collect i)))\n (dotimes (i n)\n ;; (setf (aref a i) (read))\n (setf (nth a i) (read)))\n (values n a)))\n\n(multiple-value-bind (n a) (create-data)\n (format t \"~a~%\" (shift-only n a)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 713, "cpu_time_ms": 189, "memory_kb": 17896}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s938656364", "group_id": "codeNet:p03494", "input_text": "(defun count-div (v)\n (if (zerop v)\n 0\n (multiple-value-bind (q r)\n (truncate v 2)\n (if (= 0 r)\n (1+ (count-div q))\n 0))))\n\n(let* ((n (read))\n (a (make-array n)))\n (dotimes (i n)\n (setf (aref a i) (read)))\n (format t \"~A~%\"\n (loop for ai across a\n minimize (count-div ai))))", "language": "Lisp", "metadata": {"date": 1512958930, "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/s938656364.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s938656364", "user_id": "u275710783"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun count-div (v)\n (if (zerop v)\n 0\n (multiple-value-bind (q r)\n (truncate v 2)\n (if (= 0 r)\n (1+ (count-div q))\n 0))))\n\n(let* ((n (read))\n (a (make-array n)))\n (dotimes (i n)\n (setf (aref a i) (read)))\n (format t \"~A~%\"\n (loop for ai across a\n minimize (count-div ai))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 356, "cpu_time_ms": 435, "memory_kb": 16864}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s208449551", "group_id": "codeNet:p03494", "input_text": "(defun count-div (v)\n (if (zerop v)\n 0\n (multiple-value-bind (q r)\n (truncate v 2)\n (if (= 0 r)\n (1+ (count-div q))\n 0))))\n\n(let* ((n (read))\n (a (make-array n)))\n (dotimes (i n)\n (setf (aref a i) (read)))\n (format t \"~A~%\"\n (loop for ai across a\n with m = 0\n if (< m ai)\n do (setf m ai)\n and minimize\n (count-div ai))))", "language": "Lisp", "metadata": {"date": 1512958829, "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/s208449551.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s208449551", "user_id": "u275710783"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun count-div (v)\n (if (zerop v)\n 0\n (multiple-value-bind (q r)\n (truncate v 2)\n (if (= 0 r)\n (1+ (count-div q))\n 0))))\n\n(let* ((n (read))\n (a (make-array n)))\n (dotimes (i n)\n (setf (aref a i) (read)))\n (format t \"~A~%\"\n (loop for ai across a\n with m = 0\n if (< m ai)\n do (setf m ai)\n and minimize\n (count-div ai))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 352, "memory_kb": 16868}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s117535627", "group_id": "codeNet:p03495", "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 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 (inline alist-to-hash-table))\n(defun alist-to-hash-table (alist &key (test #'eql))\n (let ((table (make-hash-table :test test)))\n (dolist (pair alist table)\n (setf (gethash (car pair) table) (cdr pair)))))\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 (let* ((n (read))\n (k (read))\n (table (make-hash-table)))\n (dotimes (_ n)\n (let ((a (read-fixnum)))\n (if (gethash a table)\n (incf (gethash a table))\n (setf (gethash a table) 1))))\n (let ((alist (sort (hash-table-to-alist table) #'> :key #'cdr)))\n (println\n (reduce #'+\n (subseq alist (min (length alist) k))\n :key #'cdr)))))\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 2\n1 1 2 2 5\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4\n1 1 2 2\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 3\n5 1 3 2 4 1 1 2 3 4\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1578198907, "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/s117535627.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s117535627", "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 (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 (inline alist-to-hash-table))\n(defun alist-to-hash-table (alist &key (test #'eql))\n (let ((table (make-hash-table :test test)))\n (dolist (pair alist table)\n (setf (gethash (car pair) table) (cdr pair)))))\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 (let* ((n (read))\n (k (read))\n (table (make-hash-table)))\n (dotimes (_ n)\n (let ((a (read-fixnum)))\n (if (gethash a table)\n (incf (gethash a table))\n (setf (gethash a table) 1))))\n (let ((alist (sort (hash-table-to-alist table) #'> :key #'cdr)))\n (println\n (reduce #'+\n (subseq alist (min (length alist) k))\n :key #'cdr)))))\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 2\n1 1 2 2 5\n\"\n \"1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 4\n1 1 2 2\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 3\n5 1 3 2 4 1 1 2 3 4\n\"\n \"3\n\")))\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": "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6051, "cpu_time_ms": 222, "memory_kb": 43492}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s575543060", "group_id": "codeNet:p03502", "input_text": "(let((a 0)(b 0)(s(concatenate 'list(read-line))))(loop for c in s do(setq c(parse-integer(string c)))(setq a(+(* a 10)c))(incf b c))(princ(if(=(mod a b)0)\"Yes\"\"No\")))", "language": "Lisp", "metadata": {"date": 1534791156, "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/s575543060.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s575543060", "user_id": "u657913472"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let((a 0)(b 0)(s(concatenate 'list(read-line))))(loop for c in s do(setq c(parse-integer(string c)))(setq a(+(* a 10)c))(incf b c))(princ(if(=(mod a b)0)\"Yes\"\"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 166, "cpu_time_ms": 126, "memory_kb": 13028}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s226157173", "group_id": "codeNet:p03511", "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;;; 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;; not tested\n;; TODO: move to another file\n(declaim (inline mod-binomial))\n(defun mod-binomial (n k modulus)\n (declare ((integer 0 #.most-positive-fixnum) modulus))\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (let ((k (if (< k (- n k)) k (- n k)))\n (num 1)\n (denom 1))\n (declare ((integer 0) k num denom))\n (loop for x from n above (- n k)\n do (setq num (mod (* num x) modulus)))\n (loop for x from 1 to k\n do (setq denom (mod (* denom x) modulus)))\n (mod (* num (mod-inverse denom modulus)) modulus))))\n\n(declaim (ftype (function * (values (or null (integer 1 #.most-positive-fixnum)) &optional)) mod-log))\n\n(defun mod-log (x y modulus)\n \"Returns the smallest positive integer k that satiefies x^k ≡ y mod p.\nReturns NIL if it is infeasible.\"\n (declare (optimize (speed 3))\n (integer x y)\n ((integer 1 #.most-positive-fixnum) modulus))\n (let ((x (mod x modulus))\n (y (mod y modulus))\n (g (gcd x modulus)))\n (declare (optimize (safety 0))\n ((mod #.most-positive-fixnum) x y g))\n (if (= g 1)\n ;; coprime case\n (let* ((m (+ 1 (isqrt (- modulus 1)))) ; smallest integer equal to or\n ; larger than sqrt(p)\n (x^m (loop for i below m\n for res of-type (integer 0 #.most-positive-fixnum) = x\n then (mod (* res x) modulus)\n finally (return res)))\n (table (make-hash-table :size m :test 'eq)))\n ;; Constructs TABLE: yx^j |-> j (j = 0, ..., m-1)\n (loop for j from 0 below m\n for res of-type (integer 0 #.most-positive-fixnum) = y\n then (mod (* res x) modulus)\n do (setf (gethash res table) j))\n ;; Finds i and j that satisfy (x^m)^i = yx^j and returns m*i-j\n (loop for i from 1 to m\n for x^m^i of-type (integer 0 #.most-positive-fixnum) = x^m\n then (mod (* x^m^i x^m) modulus)\n for j = (gethash x^m^i table)\n when j\n do (locally\n (declare ((integer 0 #.most-positive-fixnum) j))\n (return (- (* i m) j)))\n finally (return nil)))\n ;; If x and p are not coprime, let g := gcd(x, p), x := gx', y := gy', p\n ;; := gp' and solve x^(k-1) ≡ y'x'^(-1) mod p' instead. See\n ;; https://math.stackexchange.com/questions/131127/ for the detail.\n (if (= x y)\n ;; This is tha special treatment for the case x ≡ y. Without this\n ;; (mod-log 4 0 4) returns not 1 but 2.\n 1\n (multiple-value-bind (y-prime rem) (floor y g)\n (if (zerop rem)\n (let* ((x-prime (floor x g))\n (p-prime (floor modulus g))\n (next-rhs (mod (* y-prime (mod-inverse x-prime p-prime)) p-prime))\n (res (mod-log x next-rhs p-prime)))\n (declare ((integer 0 #.most-positive-fixnum) x-prime p-prime next-rhs))\n (if res (+ 1 res) nil))\n nil))))))\n\n(declaim (inline %calc-min-factor))\n(defun %calc-min-factor (x alpha)\n \"Returns k, so that x+k*alpha is the smallest non-negative number.\"\n (if (plusp alpha)\n (ceiling (- x) alpha)\n (floor (- x) alpha)))\n\n(declaim (inline %calc-max-factor))\n(defun %calc-max-factor (x alpha)\n \"Returns k, so that x+k*alpha is the largest non-positive number.\"\n (if (plusp alpha)\n (floor (- x) alpha)\n (ceiling (- x) alpha)))\n\n(defun solve-bezout (a b c &optional min max)\n \"Returns an integer solution of a*x+b*y = c if it exists, otherwise\nreturns (VALUES NIL NIL).\n\nIf MIN is specified and MAX is null, the returned x is the smallest integer\nequal to or larger than MIN. If MAX is specified and MIN is null, x is the\nlargest integer equal to or smaller than MAX. If the both are specified, x is an\ninteger in [MIN, MAX]. This function returns NIL when no x that satisfies the\ngiven condition exists.\"\n (declare (fixnum a b c)\n ((or null fixnum) min max))\n (let ((gcd-ab (gcd a b)))\n (if (zerop (mod c gcd-ab))\n (multiple-value-bind (init-x init-y) (ext-gcd a b)\n (let* ((factor (floor c gcd-ab))\n ;; m*x0 + n*y0 = d\n (x0 (* init-x factor))\n (y0 (* init-y factor)))\n (if (and (null min) (null max))\n (values x0 y0)\n (let (;; general solution: x = x0 + kΔx, y = y0 - kΔy\n (deltax (floor b gcd-ab))\n (deltay (floor a gcd-ab)))\n (if min\n (let* ((k-min (%calc-min-factor (- x0 min) deltax))\n (x (+ x0 (* k-min deltax)))\n (y (- y0 (* k-min deltay))))\n (if (and max (> x max))\n (values nil nil)\n (values x y)))\n (let* ((k-max (%calc-max-factor (- x0 max) deltax))\n (x (+ x0 (* k-max deltax)))\n (y (- y0 (* k-max deltay))))\n (if (<= x max)\n (values x y)\n (values nil nil))))))))\n (values nil nil))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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* ((l (read))\n (ss (read-line))\n (len1 (length ss))\n (tt (read-line))\n (len2 (length tt))\n (x1 (solve-bezout len1 len2 l 0))\n (y1 (floor (- l (* len1 x1)) len2))\n (y2 (solve-bezout len2 len1 l 0))\n (x2 (floor (- l (* len2 y2)) len1))\n (res1 (make-string l :element-type 'base-char))\n (res2 (make-string l :element-type 'base-char))\n (res3 (make-string l :element-type 'base-char))\n (res4 (make-string l :element-type 'base-char)))\n (dbg x1 y1)\n (labels ((render (x ss y tt)\n (let ((res (make-string l :element-type 'base-char))\n (len1 (length ss))\n (len2 (length tt)))\n (dotimes (i x)\n (replace res ss :start1 (* i len1)))\n (dotimes (i y)\n (replace res tt :start1 (+ (* x len1) (* i len2))))\n res)))\n (let ((res (render x1 ss y1 tt)))\n (let ((s (render y1 tt x1 ss)))\n (when (string<= s res)\n (setq res s)))\n (let ((s (render x2 ss y2 tt)))\n (when (string<= s res)\n (setq res s)))\n (let ((s (render y2 tt x2 ss)))\n (when (string<= s res)\n (setq res s)))\n (write-line 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 \"6\nat\ncode\n\"\n \"atatat\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\ncoding\nfestival\n\"\n \"festival\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\nsame\nsame\n\"\n \"samesame\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\ncoin\nage\n\"\n \"ageagecoin\n\")))\n", "language": "Lisp", "metadata": {"date": 1583297104, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03511.html", "problem_id": "p03511", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03511/input.txt", "sample_output_relpath": "derived/input_output/data/p03511/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03511/Lisp/s226157173.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s226157173", "user_id": "u352600849"}, "prompt_components": {"gold_output": "atatat\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;;; 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;; not tested\n;; TODO: move to another file\n(declaim (inline mod-binomial))\n(defun mod-binomial (n k modulus)\n (declare ((integer 0 #.most-positive-fixnum) modulus))\n (if (or (< n k) (< n 0) (< k 0))\n 0\n (let ((k (if (< k (- n k)) k (- n k)))\n (num 1)\n (denom 1))\n (declare ((integer 0) k num denom))\n (loop for x from n above (- n k)\n do (setq num (mod (* num x) modulus)))\n (loop for x from 1 to k\n do (setq denom (mod (* denom x) modulus)))\n (mod (* num (mod-inverse denom modulus)) modulus))))\n\n(declaim (ftype (function * (values (or null (integer 1 #.most-positive-fixnum)) &optional)) mod-log))\n\n(defun mod-log (x y modulus)\n \"Returns the smallest positive integer k that satiefies x^k ≡ y mod p.\nReturns NIL if it is infeasible.\"\n (declare (optimize (speed 3))\n (integer x y)\n ((integer 1 #.most-positive-fixnum) modulus))\n (let ((x (mod x modulus))\n (y (mod y modulus))\n (g (gcd x modulus)))\n (declare (optimize (safety 0))\n ((mod #.most-positive-fixnum) x y g))\n (if (= g 1)\n ;; coprime case\n (let* ((m (+ 1 (isqrt (- modulus 1)))) ; smallest integer equal to or\n ; larger than sqrt(p)\n (x^m (loop for i below m\n for res of-type (integer 0 #.most-positive-fixnum) = x\n then (mod (* res x) modulus)\n finally (return res)))\n (table (make-hash-table :size m :test 'eq)))\n ;; Constructs TABLE: yx^j |-> j (j = 0, ..., m-1)\n (loop for j from 0 below m\n for res of-type (integer 0 #.most-positive-fixnum) = y\n then (mod (* res x) modulus)\n do (setf (gethash res table) j))\n ;; Finds i and j that satisfy (x^m)^i = yx^j and returns m*i-j\n (loop for i from 1 to m\n for x^m^i of-type (integer 0 #.most-positive-fixnum) = x^m\n then (mod (* x^m^i x^m) modulus)\n for j = (gethash x^m^i table)\n when j\n do (locally\n (declare ((integer 0 #.most-positive-fixnum) j))\n (return (- (* i m) j)))\n finally (return nil)))\n ;; If x and p are not coprime, let g := gcd(x, p), x := gx', y := gy', p\n ;; := gp' and solve x^(k-1) ≡ y'x'^(-1) mod p' instead. See\n ;; https://math.stackexchange.com/questions/131127/ for the detail.\n (if (= x y)\n ;; This is tha special treatment for the case x ≡ y. Without this\n ;; (mod-log 4 0 4) returns not 1 but 2.\n 1\n (multiple-value-bind (y-prime rem) (floor y g)\n (if (zerop rem)\n (let* ((x-prime (floor x g))\n (p-prime (floor modulus g))\n (next-rhs (mod (* y-prime (mod-inverse x-prime p-prime)) p-prime))\n (res (mod-log x next-rhs p-prime)))\n (declare ((integer 0 #.most-positive-fixnum) x-prime p-prime next-rhs))\n (if res (+ 1 res) nil))\n nil))))))\n\n(declaim (inline %calc-min-factor))\n(defun %calc-min-factor (x alpha)\n \"Returns k, so that x+k*alpha is the smallest non-negative number.\"\n (if (plusp alpha)\n (ceiling (- x) alpha)\n (floor (- x) alpha)))\n\n(declaim (inline %calc-max-factor))\n(defun %calc-max-factor (x alpha)\n \"Returns k, so that x+k*alpha is the largest non-positive number.\"\n (if (plusp alpha)\n (floor (- x) alpha)\n (ceiling (- x) alpha)))\n\n(defun solve-bezout (a b c &optional min max)\n \"Returns an integer solution of a*x+b*y = c if it exists, otherwise\nreturns (VALUES NIL NIL).\n\nIf MIN is specified and MAX is null, the returned x is the smallest integer\nequal to or larger than MIN. If MAX is specified and MIN is null, x is the\nlargest integer equal to or smaller than MAX. If the both are specified, x is an\ninteger in [MIN, MAX]. This function returns NIL when no x that satisfies the\ngiven condition exists.\"\n (declare (fixnum a b c)\n ((or null fixnum) min max))\n (let ((gcd-ab (gcd a b)))\n (if (zerop (mod c gcd-ab))\n (multiple-value-bind (init-x init-y) (ext-gcd a b)\n (let* ((factor (floor c gcd-ab))\n ;; m*x0 + n*y0 = d\n (x0 (* init-x factor))\n (y0 (* init-y factor)))\n (if (and (null min) (null max))\n (values x0 y0)\n (let (;; general solution: x = x0 + kΔx, y = y0 - kΔy\n (deltax (floor b gcd-ab))\n (deltay (floor a gcd-ab)))\n (if min\n (let* ((k-min (%calc-min-factor (- x0 min) deltax))\n (x (+ x0 (* k-min deltax)))\n (y (- y0 (* k-min deltay))))\n (if (and max (> x max))\n (values nil nil)\n (values x y)))\n (let* ((k-max (%calc-max-factor (- x0 max) deltax))\n (x (+ x0 (* k-max deltax)))\n (y (- y0 (* k-max deltay))))\n (if (<= x max)\n (values x y)\n (values nil nil))))))))\n (values nil nil))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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* ((l (read))\n (ss (read-line))\n (len1 (length ss))\n (tt (read-line))\n (len2 (length tt))\n (x1 (solve-bezout len1 len2 l 0))\n (y1 (floor (- l (* len1 x1)) len2))\n (y2 (solve-bezout len2 len1 l 0))\n (x2 (floor (- l (* len2 y2)) len1))\n (res1 (make-string l :element-type 'base-char))\n (res2 (make-string l :element-type 'base-char))\n (res3 (make-string l :element-type 'base-char))\n (res4 (make-string l :element-type 'base-char)))\n (dbg x1 y1)\n (labels ((render (x ss y tt)\n (let ((res (make-string l :element-type 'base-char))\n (len1 (length ss))\n (len2 (length tt)))\n (dotimes (i x)\n (replace res ss :start1 (* i len1)))\n (dotimes (i y)\n (replace res tt :start1 (+ (* x len1) (* i len2))))\n res)))\n (let ((res (render x1 ss y1 tt)))\n (let ((s (render y1 tt x1 ss)))\n (when (string<= s res)\n (setq res s)))\n (let ((s (render x2 ss y2 tt)))\n (when (string<= s res)\n (setq res s)))\n (let ((s (render y2 tt x2 ss)))\n (when (string<= s res)\n (setq res s)))\n (write-line 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 \"6\nat\ncode\n\"\n \"atatat\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\ncoding\nfestival\n\"\n \"festival\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\nsame\nsame\n\"\n \"samesame\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\ncoin\nage\n\"\n \"ageagecoin\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given two strings s and t consisting of lowercase English letters and an integer L.\n\nWe will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once.\n\nFor example, when s = at, t = code and L = 6, the strings atatat, atcode and codeat can be generated.\n\nAmong the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L.\n\nConstraints\n\n1 ≤ L ≤ 2 × 10^5\n\n1 ≤ |s|, |t| ≤ L\n\ns and t consist of lowercase English letters.\n\nIt is possible to generate a string of length L in the way described in Problem Statement.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 s_1\nx_2 s_2\n:\nx_N s_N\n\nOutput\n\nPrint the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement.\n\nSample Input 1\n\n6\nat\ncode\n\nSample Output 1\n\natatat\n\nThis input corresponds to the example shown in Problem Statement.\n\nSample Input 2\n\n8\ncoding\nfestival\n\nSample Output 2\n\nfestival\n\nIt is possible that either s or t cannot be used at all in generating a string of length L.\n\nSample Input 3\n\n8\nsame\nsame\n\nSample Output 3\n\nsamesame\n\nIt is also possible that s = t.\n\nSample Input 4\n\n10\ncoin\nage\n\nSample Output 4\n\nageagecoin", "sample_input": "6\nat\ncode\n"}, "reference_outputs": ["atatat\n"], "source_document_id": "p03511", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given two strings s and t consisting of lowercase English letters and an integer L.\n\nWe will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once.\n\nFor example, when s = at, t = code and L = 6, the strings atatat, atcode and codeat can be generated.\n\nAmong the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L.\n\nConstraints\n\n1 ≤ L ≤ 2 × 10^5\n\n1 ≤ |s|, |t| ≤ L\n\ns and t consist of lowercase English letters.\n\nIt is possible to generate a string of length L in the way described in Problem Statement.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nx_1 s_1\nx_2 s_2\n:\nx_N s_N\n\nOutput\n\nPrint the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement.\n\nSample Input 1\n\n6\nat\ncode\n\nSample Output 1\n\natatat\n\nThis input corresponds to the example shown in Problem Statement.\n\nSample Input 2\n\n8\ncoding\nfestival\n\nSample Output 2\n\nfestival\n\nIt is possible that either s or t cannot be used at all in generating a string of length L.\n\nSample Input 3\n\n8\nsame\nsame\n\nSample Output 3\n\nsamesame\n\nIt is also possible that s = t.\n\nSample Input 4\n\n10\ncoin\nage\n\nSample Output 4\n\nageagecoin", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13413, "cpu_time_ms": 311, "memory_kb": 42980}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s886687439", "group_id": "codeNet:p03526", "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))\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;;\n;; Basic usage:\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 corresponding\n;; value to a hash-table when evaluating (ADD A B) for the first time; ADD\n;; returns the stored value when it is called with the same arguments\n;; (w.r.t. EQUAL) again.\n;;\n;; The storage for the cache can be hash-table or array. Let's see an example\n;; for array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form caches 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 doesn't take.)\n;;\n;; If you want to ignore some arguments, you can use `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; => 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 debug the memoized function by :DEBUG option:\n;; (with-cache (:array (10 10) :initial-element -1 :debug 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(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY\"\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dimensions-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\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 (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 \"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 ((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 #+sbcl 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 (hs (make-array n :element-type 'uint32))\n (ps (make-array n :element-type 'uint32))\n (ords (make-array n :element-type 'uint32)))\n (declare (uint32 n)\n ((simple-array uint32 (*)) hs ps ords))\n (dotimes (i n)\n (setf (aref hs i) (read-fixnum)\n (aref ps i) (read-fixnum)\n (aref ords i) i))\n (setf ords (sort ords (lambda (x y)\n (< (+ (aref hs x) (aref ps x))\n (+ (aref hs y) (aref ps y))))))\n (gc)\n (with-cache (:array (5001 5001) :element-type 'fixnum :initial-element -1)\n (labels ((recur (x y)\n (cond ((zerop y) 0)\n ((< x y) most-positive-fixnum)\n (t (let* ((prev-height (recur (- x 1) (- y 1)))\n (ord (aref ords (- x 1)))\n (h (aref hs ord))\n (p (aref ps ord)))\n (declare (uint32 h p))\n (min (recur (- x 1) y)\n (if (>= h prev-height)\n (+ p (recur (- x 1) (- y 1)))\n most-positive-fixnum)))))))\n (loop for i from n downto 0\n when (< (recur n i) most-positive-fixnum)\n do (println i)\n (return))))))\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 \"3\n0 2\n1 3\n3 4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 4\n3 1\n4 1\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1 3\n8 4\n8 3\n9 1\n6 4\n2 3\n4 2\n9 2\n8 3\n0 1\n\"\n \"5\n\")))\n", "language": "Lisp", "metadata": {"date": 1579952786, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03526.html", "problem_id": "p03526", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03526/input.txt", "sample_output_relpath": "derived/input_output/data/p03526/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03526/Lisp/s886687439.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s886687439", "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))\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;;\n;; Basic usage:\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 corresponding\n;; value to a hash-table when evaluating (ADD A B) for the first time; ADD\n;; returns the stored value when it is called with the same arguments\n;; (w.r.t. EQUAL) again.\n;;\n;; The storage for the cache can be hash-table or array. Let's see an example\n;; for array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form caches 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 doesn't take.)\n;;\n;; If you want to ignore some arguments, you can use `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; => 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 debug the memoized function by :DEBUG option:\n;; (with-cache (:array (10 10) :initial-element -1 :debug 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(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY\"\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dimensions-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\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 (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 \"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 ((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 #+sbcl 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 (hs (make-array n :element-type 'uint32))\n (ps (make-array n :element-type 'uint32))\n (ords (make-array n :element-type 'uint32)))\n (declare (uint32 n)\n ((simple-array uint32 (*)) hs ps ords))\n (dotimes (i n)\n (setf (aref hs i) (read-fixnum)\n (aref ps i) (read-fixnum)\n (aref ords i) i))\n (setf ords (sort ords (lambda (x y)\n (< (+ (aref hs x) (aref ps x))\n (+ (aref hs y) (aref ps y))))))\n (gc)\n (with-cache (:array (5001 5001) :element-type 'fixnum :initial-element -1)\n (labels ((recur (x y)\n (cond ((zerop y) 0)\n ((< x y) most-positive-fixnum)\n (t (let* ((prev-height (recur (- x 1) (- y 1)))\n (ord (aref ords (- x 1)))\n (h (aref hs ord))\n (p (aref ps ord)))\n (declare (uint32 h p))\n (min (recur (- x 1) y)\n (if (>= h prev-height)\n (+ p (recur (- x 1) (- y 1)))\n most-positive-fixnum)))))))\n (loop for i from n downto 0\n when (< (recur n i) most-positive-fixnum)\n do (println i)\n (return))))))\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 \"3\n0 2\n1 3\n3 4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3\n2 4\n3 1\n4 1\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10\n1 3\n8 4\n8 3\n9 1\n6 4\n2 3\n4 2\n9 2\n8 3\n0 1\n\"\n \"5\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nIn the final of CODE FESTIVAL in some year, there are N participants.\nThe height and power of Participant i is H_i and P_i, respectively.\n\nRingo is hosting a game of stacking zabuton (cushions).\n\nThe participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton.\nInitially, the stack is empty.\nWhen it is Participant i's turn, if there are H_i or less zabuton already stacked, he/she will add exactly P_i zabuton to the stack. Otherwise, he/she will give up and do nothing.\n\nRingo wants to maximize the number of participants who can add zabuton to the stack.\nHow many participants can add zabuton to the stack in the optimal order of participants?\n\nConstraints\n\n1 \\leq N \\leq 5000\n\n0 \\leq H_i \\leq 10^9\n\n1 \\leq P_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nH_1 P_1\nH_2 P_2\n:\nH_N P_N\n\nOutput\n\nPrint the maximum number of participants who can add zabuton to the stack.\n\nSample Input 1\n\n3\n0 2\n1 3\n3 4\n\nSample Output 1\n\n2\n\nWhen the participants line up in the same order as the input, Participants 1 and 3 will be able to add zabuton.\n\nOn the other hand, there is no order such that all three participants can add zabuton. Thus, the answer is 2.\n\nSample Input 2\n\n3\n2 4\n3 1\n4 1\n\nSample Output 2\n\n3\n\nWhen the participants line up in the order 2, 3, 1, all of them will be able to add zabuton.\n\nSample Input 3\n\n10\n1 3\n8 4\n8 3\n9 1\n6 4\n2 3\n4 2\n9 2\n8 3\n0 1\n\nSample Output 3\n\n5", "sample_input": "3\n0 2\n1 3\n3 4\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03526", "source_text": "Score : 700 points\n\nProblem Statement\n\nIn the final of CODE FESTIVAL in some year, there are N participants.\nThe height and power of Participant i is H_i and P_i, respectively.\n\nRingo is hosting a game of stacking zabuton (cushions).\n\nThe participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton.\nInitially, the stack is empty.\nWhen it is Participant i's turn, if there are H_i or less zabuton already stacked, he/she will add exactly P_i zabuton to the stack. Otherwise, he/she will give up and do nothing.\n\nRingo wants to maximize the number of participants who can add zabuton to the stack.\nHow many participants can add zabuton to the stack in the optimal order of participants?\n\nConstraints\n\n1 \\leq N \\leq 5000\n\n0 \\leq H_i \\leq 10^9\n\n1 \\leq P_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nH_1 P_1\nH_2 P_2\n:\nH_N P_N\n\nOutput\n\nPrint the maximum number of participants who can add zabuton to the stack.\n\nSample Input 1\n\n3\n0 2\n1 3\n3 4\n\nSample Output 1\n\n2\n\nWhen the participants line up in the same order as the input, Participants 1 and 3 will be able to add zabuton.\n\nOn the other hand, there is no order such that all three participants can add zabuton. Thus, the answer is 2.\n\nSample Input 2\n\n3\n2 4\n3 1\n4 1\n\nSample Output 2\n\n3\n\nWhen the participants line up in the order 2, 3, 1, all of them will be able to add zabuton.\n\nSample Input 3\n\n10\n1 3\n8 4\n8 3\n9 1\n6 4\n2 3\n4 2\n9 2\n8 3\n0 1\n\nSample Output 3\n\n5", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14451, "cpu_time_ms": 589, "memory_kb": 248676}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s840188936", "group_id": "codeNet:p03543", "input_text": "(let ((n (read-line))\n (ans \"No\"))\n (if (eq (char n 1) (char n 2))\n (if (eq (char n 0) (char n 1))\n (setq ans \"Yes\")\n (if (eq (char n 1) (char n 3))\n (setq ans \"Yes\")\n )\n )\n \n )\n (format t \"~A~%\" ans)\n)", "language": "Lisp", "metadata": {"date": 1594039587, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03543.html", "problem_id": "p03543", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03543/input.txt", "sample_output_relpath": "derived/input_output/data/p03543/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03543/Lisp/s840188936.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s840188936", "user_id": "u136500538"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read-line))\n (ans \"No\"))\n (if (eq (char n 1) (char n 2))\n (if (eq (char n 0) (char n 1))\n (setq ans \"Yes\")\n (if (eq (char n 1) (char n 3))\n (setq ans \"Yes\")\n )\n )\n \n )\n (format t \"~A~%\" ans)\n)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nWe call a 4-digit integer with three or more consecutive same digits, such as 1118, good.\n\nYou are given a 4-digit integer N. Answer the question: Is N good?\n\nConstraints\n\n1000 ≤ N ≤ 9999\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 good, print Yes; otherwise, print No.\n\nSample Input 1\n\n1118\n\nSample Output 1\n\nYes\n\nN is good, since it contains three consecutive 1.\n\nSample Input 2\n\n7777\n\nSample Output 2\n\nYes\n\nAn integer is also good when all the digits are the same.\n\nSample Input 3\n\n1234\n\nSample Output 3\n\nNo", "sample_input": "1118\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03543", "source_text": "Score : 100 points\n\nProblem Statement\n\nWe call a 4-digit integer with three or more consecutive same digits, such as 1118, good.\n\nYou are given a 4-digit integer N. Answer the question: Is N good?\n\nConstraints\n\n1000 ≤ N ≤ 9999\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 good, print Yes; otherwise, print No.\n\nSample Input 1\n\n1118\n\nSample Output 1\n\nYes\n\nN is good, since it contains three consecutive 1.\n\nSample Input 2\n\n7777\n\nSample Output 2\n\nYes\n\nAn integer is also good when all the digits are the same.\n\nSample Input 3\n\n1234\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 21, "memory_kb": 23760}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s649401090", "group_id": "codeNet:p03544", "input_text": "(let ((lucas '(1 2))\n (n (read)))\n (defun lp ()\n (push (+ (first lucas) (second lucas)) lucas))\n (cond ((= 1 n) (princ 2))\n ((= 2 n) (princ 1))\n (t (loop :repeat (1- n) do(lp)) (princ (first lucas)))))", "language": "Lisp", "metadata": {"date": 1543623845, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03544.html", "problem_id": "p03544", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03544/input.txt", "sample_output_relpath": "derived/input_output/data/p03544/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03544/Lisp/s649401090.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s649401090", "user_id": "u610490393"}, "prompt_components": {"gold_output": "11\n", "input_to_evaluate": "(let ((lucas '(1 2))\n (n (read)))\n (defun lp ()\n (push (+ (first lucas) (second lucas)) lucas))\n (cond ((= 1 n) (princ 2))\n ((= 2 n) (princ 1))\n (t (loop :repeat (1- n) do(lp)) (princ (first lucas)))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIt is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.\n\nYou are given an integer N. Find the N-th Lucas number.\n\nHere, the i-th Lucas number L_i is defined as follows:\n\nL_0=2\n\nL_1=1\n\nL_i=L_{i-1}+L_{i-2} (i≥2)\n\nConstraints\n\n1≤N≤86\n\nIt is guaranteed that the answer is less than 10^{18}.\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 N-th Lucas number.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n11\n\nL_0=2\n\nL_1=1\n\nL_2=L_0+L_1=3\n\nL_3=L_1+L_2=4\n\nL_4=L_2+L_3=7\n\nL_5=L_3+L_4=11\n\nThus, the 5-th Lucas number is 11.\n\nSample Input 2\n\n86\n\nSample Output 2\n\n939587134549734843", "sample_input": "5\n"}, "reference_outputs": ["11\n"], "source_document_id": "p03544", "source_text": "Score : 200 points\n\nProblem Statement\n\nIt is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.\n\nYou are given an integer N. Find the N-th Lucas number.\n\nHere, the i-th Lucas number L_i is defined as follows:\n\nL_0=2\n\nL_1=1\n\nL_i=L_{i-1}+L_{i-2} (i≥2)\n\nConstraints\n\n1≤N≤86\n\nIt is guaranteed that the answer is less than 10^{18}.\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 N-th Lucas number.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n11\n\nL_0=2\n\nL_1=1\n\nL_2=L_0+L_1=3\n\nL_3=L_1+L_2=4\n\nL_4=L_2+L_3=7\n\nL_5=L_3+L_4=11\n\nThus, the 5-th Lucas number is 11.\n\nSample Input 2\n\n86\n\nSample Output 2\n\n939587134549734843", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 140, "memory_kb": 12264}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s397190256", "group_id": "codeNet:p03544", "input_text": "(setq a 2)(setq b(setq c 1))\n(dotimes(i(1-(read)))(setq b(setq c(+ a(setq a b))))))\n(princ c)", "language": "Lisp", "metadata": {"date": 1534791875, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03544.html", "problem_id": "p03544", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03544/input.txt", "sample_output_relpath": "derived/input_output/data/p03544/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03544/Lisp/s397190256.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s397190256", "user_id": "u657913472"}, "prompt_components": {"gold_output": "11\n", "input_to_evaluate": "(setq a 2)(setq b(setq c 1))\n(dotimes(i(1-(read)))(setq b(setq c(+ a(setq a b))))))\n(princ c)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIt is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.\n\nYou are given an integer N. Find the N-th Lucas number.\n\nHere, the i-th Lucas number L_i is defined as follows:\n\nL_0=2\n\nL_1=1\n\nL_i=L_{i-1}+L_{i-2} (i≥2)\n\nConstraints\n\n1≤N≤86\n\nIt is guaranteed that the answer is less than 10^{18}.\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 N-th Lucas number.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n11\n\nL_0=2\n\nL_1=1\n\nL_2=L_0+L_1=3\n\nL_3=L_1+L_2=4\n\nL_4=L_2+L_3=7\n\nL_5=L_3+L_4=11\n\nThus, the 5-th Lucas number is 11.\n\nSample Input 2\n\n86\n\nSample Output 2\n\n939587134549734843", "sample_input": "5\n"}, "reference_outputs": ["11\n"], "source_document_id": "p03544", "source_text": "Score : 200 points\n\nProblem Statement\n\nIt is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.\n\nYou are given an integer N. Find the N-th Lucas number.\n\nHere, the i-th Lucas number L_i is defined as follows:\n\nL_0=2\n\nL_1=1\n\nL_i=L_{i-1}+L_{i-2} (i≥2)\n\nConstraints\n\n1≤N≤86\n\nIt is guaranteed that the answer is less than 10^{18}.\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 N-th Lucas number.\n\nSample Input 1\n\n5\n\nSample Output 1\n\n11\n\nL_0=2\n\nL_1=1\n\nL_2=L_0+L_1=3\n\nL_3=L_1+L_2=4\n\nL_4=L_2+L_3=7\n\nL_5=L_3+L_4=11\n\nThus, the 5-th Lucas number is 11.\n\nSample Input 2\n\n86\n\nSample Output 2\n\n939587134549734843", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 171, "memory_kb": 15076}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s561866856", "group_id": "codeNet:p03545", "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(defun char-digit (c) (- (char-code c) 48))\n(deftype unum nil `(integer 0 ,(expt 10 9)))\n\n(defun get-ops (digits ops sum)\n (if (null digits)\n (if (= sum 7)\n\t (nreverse ops)\n\t nil)\n (or (get-ops (cdr digits) (cons #\\+ ops) (+ sum (car digits)))\n\t (get-ops (cdr digits) (cons #\\- ops) (- sum (car digits))))))\n\n(defun main ()\n (let* ((digits (map 'list #'char-digit (read-line)))\n\t (ops (get-ops (cdr digits) nil (car digits))))\n (loop initially (princ (car digits))\n for digit in (cdr digits)\n for op in ops\n do (format t \"~A~A\" op digit)\n finally (write-line \"=7\"))))\n\n#-swank(main)\n\n\n;; Für Test\n\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": 1521788683, "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/s561866856.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s561866856", "user_id": "u352600849"}, "prompt_components": {"gold_output": "1+2+2+2=7\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(defun char-digit (c) (- (char-code c) 48))\n(deftype unum nil `(integer 0 ,(expt 10 9)))\n\n(defun get-ops (digits ops sum)\n (if (null digits)\n (if (= sum 7)\n\t (nreverse ops)\n\t nil)\n (or (get-ops (cdr digits) (cons #\\+ ops) (+ sum (car digits)))\n\t (get-ops (cdr digits) (cons #\\- ops) (- sum (car digits))))))\n\n(defun main ()\n (let* ((digits (map 'list #'char-digit (read-line)))\n\t (ops (get-ops (cdr digits) nil (car digits))))\n (loop initially (princ (car digits))\n for digit in (cdr digits)\n for op in ops\n do (format t \"~A~A\" op digit)\n finally (write-line \"=7\"))))\n\n#-swank(main)\n\n\n;; Für Test\n\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 : 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1671, "cpu_time_ms": 32, "memory_kb": 7144}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s762542633", "group_id": "codeNet:p03547", "input_text": "(let ((X (read))\n (Y (read)))\n (princ (cond ((string< X Y) '\"<\")\n \t ((string> X Y) '\">\")\n ((string= X Y) '\"=\"))))", "language": "Lisp", "metadata": {"date": 1583845868, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03547.html", "problem_id": "p03547", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03547/input.txt", "sample_output_relpath": "derived/input_output/data/p03547/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03547/Lisp/s762542633.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s762542633", "user_id": "u606976120"}, "prompt_components": {"gold_output": "<\n", "input_to_evaluate": "(let ((X (read))\n (Y (read)))\n (princ (cond ((string< X Y) '\"<\")\n \t ((string> X Y) '\">\")\n ((string= X Y) '\"=\"))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nIn programming, hexadecimal notation is often used.\n\nIn hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters A, B, C, D, E and F are used to represent the values 10, 11, 12, 13, 14 and 15, respectively.\n\nIn this problem, you are given two letters X and Y. Each X and Y is A, B, C, D, E or F.\n\nWhen X and Y are seen as hexadecimal numbers, which is larger?\n\nConstraints\n\nEach X and Y is A, B, C, D, E or F.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf X is smaller, print <; if Y is smaller, print >; if they are equal, print =.\n\nSample Input 1\n\nA B\n\nSample Output 1\n\n<\n\n10 < 11.\n\nSample Input 2\n\nE C\n\nSample Output 2\n\n>\n\n14 > 12.\n\nSample Input 3\n\nF F\n\nSample Output 3\n\n=\n\n15 = 15.", "sample_input": "A B\n"}, "reference_outputs": ["<\n"], "source_document_id": "p03547", "source_text": "Score : 100 points\n\nProblem Statement\n\nIn programming, hexadecimal notation is often used.\n\nIn hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters A, B, C, D, E and F are used to represent the values 10, 11, 12, 13, 14 and 15, respectively.\n\nIn this problem, you are given two letters X and Y. Each X and Y is A, B, C, D, E or F.\n\nWhen X and Y are seen as hexadecimal numbers, which is larger?\n\nConstraints\n\nEach X and Y is A, B, C, D, E or F.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y\n\nOutput\n\nIf X is smaller, print <; if Y is smaller, print >; if they are equal, print =.\n\nSample Input 1\n\nA B\n\nSample Output 1\n\n<\n\n10 < 11.\n\nSample Input 2\n\nE C\n\nSample Output 2\n\n>\n\n14 > 12.\n\nSample Input 3\n\nF F\n\nSample Output 3\n\n=\n\n15 = 15.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 69, "memory_kb": 8936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s203196446", "group_id": "codeNet:p03548", "input_text": "(let ((x (read))\n (y (read))\n (z (read)))\n (let* ((a (- x z))\n (b (/ a (+ y z))))\n (format t \"~A~%\" (floor b))))", "language": "Lisp", "metadata": {"date": 1510959768, "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/s203196446.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s203196446", "user_id": "u275710783"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let ((x (read))\n (y (read))\n (z (read)))\n (let* ((a (- x z))\n (b (/ a (+ y z))))\n (format t \"~A~%\" (floor b))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 45, "memory_kb": 5992}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s327992652", "group_id": "codeNet:p03551", "input_text": "(defun solve (N M)\n (ash (+ (* N 100) (* 1800 M)) M) )\n\n(princ (solve (read) (read)))", "language": "Lisp", "metadata": {"date": 1584370964, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03551.html", "problem_id": "p03551", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03551/input.txt", "sample_output_relpath": "derived/input_output/data/p03551/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03551/Lisp/s327992652.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s327992652", "user_id": "u334552723"}, "prompt_components": {"gold_output": "3800\n", "input_to_evaluate": "(defun solve (N M)\n (ash (+ (* N 100) (* 1800 M)) M) )\n\n(princ (solve (read) (read)))", "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": "p03551", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 105, "memory_kb": 10724}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s142029342", "group_id": "codeNet:p03556", "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(defun binary-search (l r f)\n (if (eq l r)\n\tl\n (let ((m (ash (+ l r) -1)))\n\t(if (funcall f m)\n\t (binary-search (1+ m) r f)\n\t (binary-search l m f)))))\n\n(let ((n (read)))\n (princ (expt (1- (binary-search 1 n (lambda (x) (<= (* x x) n)))) 2)))\n", "language": "Lisp", "metadata": {"date": 1580001961, "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/s142029342.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s142029342", "user_id": "u493610446"}, "prompt_components": {"gold_output": "9\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(defun binary-search (l r f)\n (if (eq l r)\n\tl\n (let ((m (ash (+ l r) -1)))\n\t(if (funcall f m)\n\t (binary-search (1+ m) r f)\n\t (binary-search l m f)))))\n\n(let ((n (read)))\n (princ (expt (1- (binary-search 1 n (lambda (x) (<= (* x x) n)))) 2)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 629, "cpu_time_ms": 22, "memory_kb": 6840}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s212361848", "group_id": "codeNet:p03556", "input_text": "(let ((n (read)))\n (loop for i from 1 to n\n if (< n (expt (1+ i) 2)) do\n (format t \"~A~%\" (expt i 2))\n (return)))\n", "language": "Lisp", "metadata": {"date": 1525918367, "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/s212361848.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s212361848", "user_id": "u275710783"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(let ((n (read)))\n (loop for i from 1 to n\n if (< n (expt (1+ i) 2)) do\n (format t \"~A~%\" (expt i 2))\n (return)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 130, "memory_kb": 12128}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s513060363", "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 (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* (expt 10 10))\n\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 (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\n (princ (solve a b c))\n (fresh-line))\n\n", "language": "Lisp", "metadata": {"date": 1596551218, "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/s513060363.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s513060363", "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 (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* (expt 10 10))\n\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 (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\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1335, "cpu_time_ms": 628, "memory_kb": 78776}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s345303306", "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 (sb-int:with-progressive-timeout (remaining-time :seconds 1.89)\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": 1562444325, "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/s345303306.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s345303306", "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 (sb-int:with-progressive-timeout (remaining-time :seconds 1.89)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4047, "cpu_time_ms": 1983, "memory_kb": 31848}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s599253536", "group_id": "codeNet:p03564", "input_text": "(setq N (read))\n(setq K (read))\n(setq ans 1)\n(dotimes (i N)\n (if (< ans K)\n (setq ans (*\n ans \n 2\n ))\n (setq ans (+\n ans\n K\n ))\n )\n )\n(format t \"~D~%\"\n ans\n )\n", "language": "Lisp", "metadata": {"date": 1558282713, "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/s599253536.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s599253536", "user_id": "u493610446"}, "prompt_components": {"gold_output": "10\n", "input_to_evaluate": "(setq N (read))\n(setq K (read))\n(setq ans 1)\n(dotimes (i N)\n (if (< ans K)\n (setq ans (*\n ans \n 2\n ))\n (setq ans (+\n ans\n K\n ))\n )\n )\n(format t \"~D~%\"\n ans\n )\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 21, "memory_kb": 4452}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s289802595", "group_id": "codeNet:p03569", "input_text": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main(){\n string input;\n cin >> input;\n list list_char((int)input.size());\n copy(input.begin(), input.end(), list_char.begin());\n list::iterator forw = list_char.begin(), backw = list_char.end();\n int sum = 0;\n backw--;\n for(int i = 0; i < (list_char.size() + 1) / 2; i++){\n if(*forw == *backw){\n forw++;\n backw--;\n continue;\n }else if(*backw == 'x'){\n forw = list_char.insert(forw, 'x');\n }else if(*forw == 'x'){\n backw = list_char.insert(next(backw), 'x');\n }else{\n cout << -1 << endl;\n return 0;\n }\n sum++;\n forw++;\n backw--;\n }\n \n //for_each(list_char.begin(), list_char.end(), [](char x){ cout << x; });\n //cout << endl;\n //cout << list_char.size() << endl;\n cout << sum << endl;\n return 0;\n}\n", "language": "Lisp", "metadata": {"date": 1524608022, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03569.html", "problem_id": "p03569", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03569/input.txt", "sample_output_relpath": "derived/input_output/data/p03569/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03569/Lisp/s289802595.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s289802595", "user_id": "u605917063"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main(){\n string input;\n cin >> input;\n list list_char((int)input.size());\n copy(input.begin(), input.end(), list_char.begin());\n list::iterator forw = list_char.begin(), backw = list_char.end();\n int sum = 0;\n backw--;\n for(int i = 0; i < (list_char.size() + 1) / 2; i++){\n if(*forw == *backw){\n forw++;\n backw--;\n continue;\n }else if(*backw == 'x'){\n forw = list_char.insert(forw, 'x');\n }else if(*forw == 'x'){\n backw = list_char.insert(next(backw), 'x');\n }else{\n cout << -1 << endl;\n return 0;\n }\n sum++;\n forw++;\n backw--;\n }\n \n //for_each(list_char.begin(), list_char.end(), [](char x){ cout << x; });\n //cout << endl;\n //cout << list_char.size() << endl;\n cout << sum << endl;\n return 0;\n}\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a string s consisting of lowercase English letters.\nSnuke can perform the following operation repeatedly:\n\nInsert a letter x to any position in s of his choice, including the beginning and end of s.\n\nSnuke's objective is to turn s into a palindrome.\nDetermine whether the objective is achievable. If it is achievable, find the minimum number of operations required.\n\nNotes\n\nA palindrome is a string that reads the same forward and backward.\nFor example, a, aa, abba and abcba are palindromes, while ab, abab and abcda are not.\n\nConstraints\n\n1 \\leq |s| \\leq 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 the objective is achievable, print the number of operations required.\nIf it is not, print -1 instead.\n\nSample Input 1\n\nxabxa\n\nSample Output 1\n\n2\n\nOne solution is as follows (newly inserted x are shown in bold):\n\nxabxa → xaxbxa → xaxbxax\n\nSample Input 2\n\nab\n\nSample Output 2\n\n-1\n\nNo sequence of operations can turn s into a palindrome.\n\nSample Input 3\n\na\n\nSample Output 3\n\n0\n\ns is a palindrome already at the beginning.\n\nSample Input 4\n\noxxx\n\nSample Output 4\n\n3\n\nOne solution is as follows:\n\noxxx → xoxxx → xxoxxx → xxxoxxx", "sample_input": "xabxa\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03569", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a string s consisting of lowercase English letters.\nSnuke can perform the following operation repeatedly:\n\nInsert a letter x to any position in s of his choice, including the beginning and end of s.\n\nSnuke's objective is to turn s into a palindrome.\nDetermine whether the objective is achievable. If it is achievable, find the minimum number of operations required.\n\nNotes\n\nA palindrome is a string that reads the same forward and backward.\nFor example, a, aa, abba and abcba are palindromes, while ab, abab and abcda are not.\n\nConstraints\n\n1 \\leq |s| \\leq 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 the objective is achievable, print the number of operations required.\nIf it is not, print -1 instead.\n\nSample Input 1\n\nxabxa\n\nSample Output 1\n\n2\n\nOne solution is as follows (newly inserted x are shown in bold):\n\nxabxa → xaxbxa → xaxbxax\n\nSample Input 2\n\nab\n\nSample Output 2\n\n-1\n\nNo sequence of operations can turn s into a palindrome.\n\nSample Input 3\n\na\n\nSample Output 3\n\n0\n\ns is a palindrome already at the beginning.\n\nSample Input 4\n\noxxx\n\nSample Output 4\n\n3\n\nOne solution is as follows:\n\noxxx → xoxxx → xxoxxx → xxxoxxx", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 989, "cpu_time_ms": 92, "memory_kb": 9704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s973970490", "group_id": "codeNet:p03572", "input_text": "#include \n \nusing namespace std;\n \n#define sim template < class c\n#define ris return * this\n#define dor > debug & operator <<\n#define eni(x) sim > typename \\\n enable_if(0) x 1, debug&>::type operator<<(c i) {\nsim > struct rge { c b, e; };\nsim > rge range(c i, c j) { return rge{i, j}; }\nsim > auto dud(c* x) -> decltype(cerr << *x, 0);\nsim > char dud(...);\nstruct debug {\n#ifdef LOCAL\n~debug() { cerr << endl; }\neni(!=) cerr << boolalpha << i; ris; }\neni(==) ris << range(begin(i), end(i)); }\nsim, class b dor(pair < b, c > d) {\n ris << \"(\" << d.first << \", \" << d.second << \")\";\n}\nsim dor(rge d) {\n *this << \"[\";\n for (auto it = d.b; it != d.e; ++it)\n *this << \", \" + 2 * (it == d.b) << *it;\n ris << \"]\";\n}\n#else\nsim dor(const c&) { ris; }\n#endif\n};\n#define imie(...) \" [\" << #__VA_ARGS__ \": \" << (__VA_ARGS__) << \"] \"\n \nusing ll = long long;\nusing ld = long double;\n \nconstexpr int nax = 405;\nconstexpr int infty = 1000 * 1000 * 1000 + 5;\nconstexpr int mod = 1000 * 1000 * 1000 + 7;\n \ninline ll Dodaj(ll a, ll b) {\n a += b;\n if (a >= mod) a -= mod;\n return a;\n}\n \ninline ll Mnoz(ll a, ll b) {\n return (a * b) % mod;\n}\n \nint n;\nint a[nax], b[nax];\nll sil[nax];\nbitset zbiora[nax], zbiorb[nax];\n \nll Dp(int pa, int pb, int ps);\nll Dp_(int pa, int pb, int ps) {\n auto Or = zbiora[pa - 1] | zbiorb[pb - 1];\n const int or_size = Or.count();\n const int ht = or_size + ps;\n assert(ht % 3 == 0);\n const int y = n - (or_size + ps);\n if (ht == n) {\n assert(y == 0);\n return sil[ps];\n }\n assert(0 <= y and y <= n);\n const int c = a[pa];\n const int d = b[pb];\n if (zbiorb[pb - 1][c]) return Dp(pa + 1, pb, ps);\n if (zbiora[pa - 1][d]) return Dp(pa, pb + 1, ps);\n const ll wybor_1 = y - 1;\n const ll wybor_2 = Mnoz(y - 1, y - 2);\n debug() << imie(pa) imie(pb) imie(ps) imie(y) imie(ht) imie(or_size) imie(c) imie(d) imie(wybor_1) imie(wybor_2);\n ll wynik = 0;\n if (c != d) {\n wynik = Mnoz(Dp(pa + 1, pb + 1, ps + 1), wybor_2);\n }\n if (ps > 0) {\n if (c == d) {\n wynik = Dodaj(wynik, Mnoz(Dp(pa + 1, pb + 1, ps - 1), ps));\n } else {\n wynik = Dodaj(wynik, Mnoz(Dp(pa + 1, pb, ps - 1), ps));\n wynik = Dodaj(wynik, Mnoz(Dp(pa, pb + 1, ps - 1), ps));\n }\n }\n return wynik;\n}\n \nint Encode(int pa, int pb, int ps) {\n return pa | (pb << 9) | (ps << 18);\n}\n \nll Dp(int pa, int pb, int ps) {\n static map m;\n const int e = Encode(pa, pb, ps);\n auto it = m.find(e);\n if (it == m.end()) {\n const ll res = Dp_(pa, pb, ps);\n debug() << \"Dp(\" imie(pa) imie(pb) imie(ps) \") = \" << res;\n return m[e] = res;\n }\n return it->second;\n}\n \nint main() {\n sil[0] = 1;\n for (int i = 1; i < nax; i++) {\n sil[i] = Mnoz(sil[i - 1], i);\n }\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cin >> n;\n for (int i = 1; i <= n; i++) {\n cin >> a[i];\n zbiora[i] = zbiora[i - 1];\n zbiora[i][a[i]] = 1;\n }\n for (int i = 1; i <= n; i++) {\n cin >> b[i];\n zbiorb[i] = zbiorb[i - 1];\n zbiorb[i][b[i]] = 1;\n }\n cout << Dp(1, 1, 0) << endl;\n return 0;\n}\n", "language": "Lisp", "metadata": {"date": 1515933881, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03572.html", "problem_id": "p03572", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03572/input.txt", "sample_output_relpath": "derived/input_output/data/p03572/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03572/Lisp/s973970490.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s973970490", "user_id": "u394551978"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "#include \n \nusing namespace std;\n \n#define sim template < class c\n#define ris return * this\n#define dor > debug & operator <<\n#define eni(x) sim > typename \\\n enable_if(0) x 1, debug&>::type operator<<(c i) {\nsim > struct rge { c b, e; };\nsim > rge range(c i, c j) { return rge{i, j}; }\nsim > auto dud(c* x) -> decltype(cerr << *x, 0);\nsim > char dud(...);\nstruct debug {\n#ifdef LOCAL\n~debug() { cerr << endl; }\neni(!=) cerr << boolalpha << i; ris; }\neni(==) ris << range(begin(i), end(i)); }\nsim, class b dor(pair < b, c > d) {\n ris << \"(\" << d.first << \", \" << d.second << \")\";\n}\nsim dor(rge d) {\n *this << \"[\";\n for (auto it = d.b; it != d.e; ++it)\n *this << \", \" + 2 * (it == d.b) << *it;\n ris << \"]\";\n}\n#else\nsim dor(const c&) { ris; }\n#endif\n};\n#define imie(...) \" [\" << #__VA_ARGS__ \": \" << (__VA_ARGS__) << \"] \"\n \nusing ll = long long;\nusing ld = long double;\n \nconstexpr int nax = 405;\nconstexpr int infty = 1000 * 1000 * 1000 + 5;\nconstexpr int mod = 1000 * 1000 * 1000 + 7;\n \ninline ll Dodaj(ll a, ll b) {\n a += b;\n if (a >= mod) a -= mod;\n return a;\n}\n \ninline ll Mnoz(ll a, ll b) {\n return (a * b) % mod;\n}\n \nint n;\nint a[nax], b[nax];\nll sil[nax];\nbitset zbiora[nax], zbiorb[nax];\n \nll Dp(int pa, int pb, int ps);\nll Dp_(int pa, int pb, int ps) {\n auto Or = zbiora[pa - 1] | zbiorb[pb - 1];\n const int or_size = Or.count();\n const int ht = or_size + ps;\n assert(ht % 3 == 0);\n const int y = n - (or_size + ps);\n if (ht == n) {\n assert(y == 0);\n return sil[ps];\n }\n assert(0 <= y and y <= n);\n const int c = a[pa];\n const int d = b[pb];\n if (zbiorb[pb - 1][c]) return Dp(pa + 1, pb, ps);\n if (zbiora[pa - 1][d]) return Dp(pa, pb + 1, ps);\n const ll wybor_1 = y - 1;\n const ll wybor_2 = Mnoz(y - 1, y - 2);\n debug() << imie(pa) imie(pb) imie(ps) imie(y) imie(ht) imie(or_size) imie(c) imie(d) imie(wybor_1) imie(wybor_2);\n ll wynik = 0;\n if (c != d) {\n wynik = Mnoz(Dp(pa + 1, pb + 1, ps + 1), wybor_2);\n }\n if (ps > 0) {\n if (c == d) {\n wynik = Dodaj(wynik, Mnoz(Dp(pa + 1, pb + 1, ps - 1), ps));\n } else {\n wynik = Dodaj(wynik, Mnoz(Dp(pa + 1, pb, ps - 1), ps));\n wynik = Dodaj(wynik, Mnoz(Dp(pa, pb + 1, ps - 1), ps));\n }\n }\n return wynik;\n}\n \nint Encode(int pa, int pb, int ps) {\n return pa | (pb << 9) | (ps << 18);\n}\n \nll Dp(int pa, int pb, int ps) {\n static map m;\n const int e = Encode(pa, pb, ps);\n auto it = m.find(e);\n if (it == m.end()) {\n const ll res = Dp_(pa, pb, ps);\n debug() << \"Dp(\" imie(pa) imie(pb) imie(ps) \") = \" << res;\n return m[e] = res;\n }\n return it->second;\n}\n \nint main() {\n sil[0] = 1;\n for (int i = 1; i < nax; i++) {\n sil[i] = Mnoz(sil[i - 1], i);\n }\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cin >> n;\n for (int i = 1; i <= n; i++) {\n cin >> a[i];\n zbiora[i] = zbiora[i - 1];\n zbiora[i][a[i]] = 1;\n }\n for (int i = 1; i <= n; i++) {\n cin >> b[i];\n zbiorb[i] = zbiorb[i - 1];\n zbiorb[i][b[i]] = 1;\n }\n cout << Dp(1, 1, 0) << endl;\n return 0;\n}\n", "problem_context": "Score : 1800 points\n\nProblem Statement\n\nThree men, A, B and C, are eating sushi together.\nInitially, there are N pieces of sushi, numbered 1 through N.\nHere, N is a multiple of 3.\n\nEach of the three has likes and dislikes in sushi.\nA's preference is represented by (a_1,\\ ...,\\ a_N), a permutation of integers from 1 to N.\nFor each i (1 \\leq i \\leq N), A's i-th favorite sushi is Sushi a_i.\nSimilarly, B's and C's preferences are represented by (b_1,\\ ...,\\ b_N) and (c_1,\\ ...,\\ c_N), permutations of integers from 1 to N.\n\nThe three repeats the following action until all pieces of sushi are consumed or a fight brakes out (described later):\n\nEach of the three A, B and C finds his most favorite piece of sushi among the remaining pieces. Let these pieces be Sushi x, y and z, respectively. If x, y and z are all different, A, B and C eats Sushi x, y and z, respectively. Otherwise, a fight brakes out.\n\nYou are given A's and B's preferences, (a_1,\\ ...,\\ a_N) and (b_1,\\ ...,\\ b_N).\nHow many preferences of C, (c_1,\\ ...,\\ c_N), leads to all the pieces of sushi being consumed without a fight?\nFind the count modulo 10^9+7.\n\nConstraints\n\n3 \\leq N \\leq 399\n\nN is a multiple of 3.\n\n(a_1,\\ ...,\\ a_N) and (b_1,\\ ...,\\ b_N) are permutations of integers from 1 to N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 ... a_N\nb_1 ... b_N\n\nOutput\n\nPrint the number of the preferences of C that leads to all the pieces of sushi being consumed without a fight, modulo 10^9+7.\n\nSample Input 1\n\n3\n1 2 3\n2 3 1\n\nSample Output 1\n\n2\n\nThe answer is two, (c_1,\\ c_2,\\ c_3) = (3,\\ 1,\\ 2),\\ (3,\\ 2,\\ 1).\nIn both cases, A, B and C will eat Sushi 1, 2 and 3, respectively, and there will be no more sushi.\n\nSample Input 2\n\n3\n1 2 3\n1 2 3\n\nSample Output 2\n\n0\n\nRegardless of what permutation (c_1,\\ c_2,\\ c_3) is, A and B will try to eat Sushi 1, resulting in a fight.\n\nSample Input 3\n\n6\n1 2 3 4 5 6\n2 1 4 3 6 5\n\nSample Output 3\n\n80\n\nFor example, if (c_1,\\ c_2,\\ c_3,\\ c_4,\\ c_5,\\ c_6) = (5,\\ 1,\\ 2,\\ 6,\\ 3,\\ 4), A, B and C will first eat Sushi 1, 2 and 5, respectively, then they will eat Sushi 3, 4 and 6, respectively, and there will be no more sushi.\n\nSample Input 4\n\n6\n1 2 3 4 5 6\n6 5 4 3 2 1\n\nSample Output 4\n\n160\n\nSample Input 5\n\n9\n4 5 6 7 8 9 1 2 3\n7 8 9 1 2 3 4 5 6\n\nSample Output 5\n\n33600", "sample_input": "3\n1 2 3\n2 3 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03572", "source_text": "Score : 1800 points\n\nProblem Statement\n\nThree men, A, B and C, are eating sushi together.\nInitially, there are N pieces of sushi, numbered 1 through N.\nHere, N is a multiple of 3.\n\nEach of the three has likes and dislikes in sushi.\nA's preference is represented by (a_1,\\ ...,\\ a_N), a permutation of integers from 1 to N.\nFor each i (1 \\leq i \\leq N), A's i-th favorite sushi is Sushi a_i.\nSimilarly, B's and C's preferences are represented by (b_1,\\ ...,\\ b_N) and (c_1,\\ ...,\\ c_N), permutations of integers from 1 to N.\n\nThe three repeats the following action until all pieces of sushi are consumed or a fight brakes out (described later):\n\nEach of the three A, B and C finds his most favorite piece of sushi among the remaining pieces. Let these pieces be Sushi x, y and z, respectively. If x, y and z are all different, A, B and C eats Sushi x, y and z, respectively. Otherwise, a fight brakes out.\n\nYou are given A's and B's preferences, (a_1,\\ ...,\\ a_N) and (b_1,\\ ...,\\ b_N).\nHow many preferences of C, (c_1,\\ ...,\\ c_N), leads to all the pieces of sushi being consumed without a fight?\nFind the count modulo 10^9+7.\n\nConstraints\n\n3 \\leq N \\leq 399\n\nN is a multiple of 3.\n\n(a_1,\\ ...,\\ a_N) and (b_1,\\ ...,\\ b_N) are permutations of integers from 1 to N.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\na_1 ... a_N\nb_1 ... b_N\n\nOutput\n\nPrint the number of the preferences of C that leads to all the pieces of sushi being consumed without a fight, modulo 10^9+7.\n\nSample Input 1\n\n3\n1 2 3\n2 3 1\n\nSample Output 1\n\n2\n\nThe answer is two, (c_1,\\ c_2,\\ c_3) = (3,\\ 1,\\ 2),\\ (3,\\ 2,\\ 1).\nIn both cases, A, B and C will eat Sushi 1, 2 and 3, respectively, and there will be no more sushi.\n\nSample Input 2\n\n3\n1 2 3\n1 2 3\n\nSample Output 2\n\n0\n\nRegardless of what permutation (c_1,\\ c_2,\\ c_3) is, A and B will try to eat Sushi 1, resulting in a fight.\n\nSample Input 3\n\n6\n1 2 3 4 5 6\n2 1 4 3 6 5\n\nSample Output 3\n\n80\n\nFor example, if (c_1,\\ c_2,\\ c_3,\\ c_4,\\ c_5,\\ c_6) = (5,\\ 1,\\ 2,\\ 6,\\ 3,\\ 4), A, B and C will first eat Sushi 1, 2 and 5, respectively, then they will eat Sushi 3, 4 and 6, respectively, and there will be no more sushi.\n\nSample Input 4\n\n6\n1 2 3 4 5 6\n6 5 4 3 2 1\n\nSample Output 4\n\n160\n\nSample Input 5\n\n9\n4 5 6 7 8 9 1 2 3\n7 8 9 1 2 3 4 5 6\n\nSample Output 5\n\n33600", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3059, "cpu_time_ms": 105, "memory_kb": 9700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s469908667", "group_id": "codeNet:p03573", "input_text": "pr", "language": "Lisp", "metadata": {"date": 1554002844, "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/s469908667.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s469908667", "user_id": "u994767958"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "pr", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2, "cpu_time_ms": 83, "memory_kb": 8036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s133352857", "group_id": "codeNet:p03575", "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(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(let (parents)\n (defun uf-print ()\n (princ parents))\n\n (defun uf-init (size)\n (setf parents (make-array size :initial-element -1)))\n\n \n (defun uf-find (x)\n (if (minusp (aref parents x))\n x\n (setf (aref parents x) (uf-find (aref parents x)))))\n\n (defun uf-unite (x y)\n (let ((x (uf-find x))\n (y (uf-find y)))\n (when (> x y)\n (rotatef x y))\n (unless (= x y)\n (incf (aref parents x) (aref parents y))\n (setf (aref parents y) x))))\n\n (defun uf-count-trees ()\n (length\n (remove-duplicates\n (mapcar (lambda (x)\n (uf-find x))\n (loop for i below (length parents) collect i)))))\n )\n\n\n\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (ans 0)\n (edges (loop repeat m collect (cons (1- (read))\n (1- (read))))))\n (assert (= (length edges) m))\n (loop for edge in edges do\n (let ((edges-1 (remove edge edges\n :test #'equalp)))\n (uf-init n)\n (loop for e in edges-1 do\n (uf-unite (first e)\n (rest e)))\n (if (/= (uf-count-trees)\n 1)\n (incf ans)))\n finally\n (format t \"~a~&\" ans))))\n\n\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1599162226, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03575.html", "problem_id": "p03575", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03575/input.txt", "sample_output_relpath": "derived/input_output/data/p03575/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03575/Lisp/s133352857.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s133352857", "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(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(let (parents)\n (defun uf-print ()\n (princ parents))\n\n (defun uf-init (size)\n (setf parents (make-array size :initial-element -1)))\n\n \n (defun uf-find (x)\n (if (minusp (aref parents x))\n x\n (setf (aref parents x) (uf-find (aref parents x)))))\n\n (defun uf-unite (x y)\n (let ((x (uf-find x))\n (y (uf-find y)))\n (when (> x y)\n (rotatef x y))\n (unless (= x y)\n (incf (aref parents x) (aref parents y))\n (setf (aref parents y) x))))\n\n (defun uf-count-trees ()\n (length\n (remove-duplicates\n (mapcar (lambda (x)\n (uf-find x))\n (loop for i below (length parents) collect i)))))\n )\n\n\n\n\n(defun main ()\n (let* ((n (read))\n (m (read))\n (ans 0)\n (edges (loop repeat m collect (cons (1- (read))\n (1- (read))))))\n (assert (= (length edges) m))\n (loop for edge in edges do\n (let ((edges-1 (remove edge edges\n :test #'equalp)))\n (uf-init n)\n (loop for e in edges-1 do\n (uf-unite (first e)\n (rest e)))\n (if (/= (uf-count-trees)\n 1)\n (incf ans)))\n finally\n (format t \"~a~&\" ans))))\n\n\n\n(main)\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nYou are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.\n\nThe i-th edge (1 \\leq i \\leq M) connects Vertex a_i and Vertex b_i.\n\nAn edge whose removal disconnects the graph is called a bridge.\n\nFind the number of the edges that are bridges among the M edges.\n\nNotes\n\nA self-loop is an edge i such that a_i=b_i (1 \\leq i \\leq M).\n\nDouble edges are a pair of edges i,j such that a_i=a_j and b_i=b_j (1 \\leq i (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 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.\"\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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *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 (xs (make-array n :element-type 'int32))\n (ys (make-array n :element-type 'int32))\n (ord-xs (make-array n :element-type 'uint8))\n (ord-ys (make-array n :element-type 'uint8))\n (cumul (make-array (list (+ n 1) (+ n 1)) :element-type 'uint8 :initial-element 0))\n (res most-positive-fixnum))\n (declare (uint8 n k) (uint62 res))\n (dotimes (i n)\n (setf (aref xs i) (read))\n (setf (aref ys i) (read))\n (setf (aref ord-xs i) i)\n (setf (aref ord-ys i) i))\n (setf ord-xs (sort ord-xs (lambda (i j) (< (aref xs i) (aref xs j)))))\n (setf ord-ys (sort ord-ys (lambda (i j) (< (aref ys i) (aref ys j)))))\n (dotimes (i n)\n (let ((ord-x (the uint8 (position i ord-xs)))\n (ord-y (position i ord-ys)))\n (incf (aref cumul (+ ord-y 1) (+ ord-x 1)))))\n (dotimes (y (+ n 1))\n (dotimes (x n)\n (incf (aref cumul y (+ x 1)) (aref cumul y x))))\n (dotimes (x (+ n 1))\n (dotimes (y n)\n (incf (aref cumul (+ y 1) x) (aref cumul y x))))\n (dotimes (y1-ord n)\n (dotimes (x1-ord n)\n (loop for y2-ord from (+ 1 y1-ord) below n\n do (loop for x2-ord from (+ 1 x1-ord) below n\n when (<= k (get-2dcumul cumul y1-ord x1-ord (+ 1 y2-ord) (+ 1 x2-ord)))\n do (let ((y1 (aref ys (aref ord-ys y1-ord)))\n (x1 (aref xs (aref ord-xs x1-ord)))\n (y2 (aref ys (aref ord-ys y2-ord)))\n (x2 (aref xs (aref ord-xs x2-ord))))\n (setf res (min res (the fixnum (* (- y2 y1) (- x2 x1))))))))))\n (println res)))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1560554479, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03576.html", "problem_id": "p03576", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03576/input.txt", "sample_output_relpath": "derived/input_output/data/p03576/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03576/Lisp/s859321808.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s859321808", "user_id": "u352600849"}, "prompt_components": {"gold_output": "21\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 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.\"\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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *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 (xs (make-array n :element-type 'int32))\n (ys (make-array n :element-type 'int32))\n (ord-xs (make-array n :element-type 'uint8))\n (ord-ys (make-array n :element-type 'uint8))\n (cumul (make-array (list (+ n 1) (+ n 1)) :element-type 'uint8 :initial-element 0))\n (res most-positive-fixnum))\n (declare (uint8 n k) (uint62 res))\n (dotimes (i n)\n (setf (aref xs i) (read))\n (setf (aref ys i) (read))\n (setf (aref ord-xs i) i)\n (setf (aref ord-ys i) i))\n (setf ord-xs (sort ord-xs (lambda (i j) (< (aref xs i) (aref xs j)))))\n (setf ord-ys (sort ord-ys (lambda (i j) (< (aref ys i) (aref ys j)))))\n (dotimes (i n)\n (let ((ord-x (the uint8 (position i ord-xs)))\n (ord-y (position i ord-ys)))\n (incf (aref cumul (+ ord-y 1) (+ ord-x 1)))))\n (dotimes (y (+ n 1))\n (dotimes (x n)\n (incf (aref cumul y (+ x 1)) (aref cumul y x))))\n (dotimes (x (+ n 1))\n (dotimes (y n)\n (incf (aref cumul (+ y 1) x) (aref cumul y x))))\n (dotimes (y1-ord n)\n (dotimes (x1-ord n)\n (loop for y2-ord from (+ 1 y1-ord) below n\n do (loop for x2-ord from (+ 1 x1-ord) below n\n when (<= k (get-2dcumul cumul y1-ord x1-ord (+ 1 y2-ord) (+ 1 x2-ord)))\n do (let ((y1 (aref ys (aref ord-ys y1-ord)))\n (x1 (aref xs (aref ord-xs x1-ord)))\n (y2 (aref ys (aref ord-ys y2-ord)))\n (x2 (aref xs (aref ord-xs x2-ord))))\n (setf res (min res (the fixnum (* (- y2 y1) (- x2 x1))))))))))\n (println res)))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N points in a two-dimensional plane.\n\nThe coordinates of the i-th point (1 \\leq i \\leq N) are (x_i,y_i).\n\nLet us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior.\n\nHere, points on the sides of the rectangle are considered to be in the interior.\n\nFind the minimum possible area of such a rectangle.\n\nConstraints\n\n2 \\leq K \\leq N \\leq 50\n\n-10^9 \\leq x_i,y_i \\leq 10^9 (1 \\leq i \\leq N)\n\nx_i≠x_j (1 \\leq i= d (- k 1))\n do (setf ret (min ret (* (- (aref vec d) (aref vec u)) (- (car (aref pos j)) (car (aref pos i))))))\n end\n do (incf u)\n do (incf d)))))\n ret))\n\n(let* ((n (read))\n (k (read))\n (pos (make-array n :element-type 'cons)))\n (loop for i below n\n do (setf (aref pos i) (cons (read) (read))))\n (princ (solve n k (sort pos #'< :key #'car))))", "language": "Lisp", "metadata": {"date": 1525224232, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03576.html", "problem_id": "p03576", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03576/input.txt", "sample_output_relpath": "derived/input_output/data/p03576/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03576/Lisp/s067834181.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s067834181", "user_id": "u672956630"}, "prompt_components": {"gold_output": "21\n", "input_to_evaluate": "(defun solve (n k pos)\n (let ((ret 10000000000000000000000000000000000000000000000000))\n (loop for i below n\n do (let ((vec (make-array 0 :fill-pointer t :adjustable t)))\n (loop for j from i below n\n for u = 0 for d = (- k 1)\n do (progn (vector-push-extend (cdr (aref pos j)) vec)\n (sort vec #'<))\n do (loop while (< d (length vec))\n if (>= d (- k 1))\n do (setf ret (min ret (* (- (aref vec d) (aref vec u)) (- (car (aref pos j)) (car (aref pos i))))))\n end\n do (incf u)\n do (incf d)))))\n ret))\n\n(let* ((n (read))\n (k (read))\n (pos (make-array n :element-type 'cons)))\n (loop for i below n\n do (setf (aref pos i) (cons (read) (read))))\n (princ (solve n k (sort pos #'< :key #'car))))", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have N points in a two-dimensional plane.\n\nThe coordinates of the i-th point (1 \\leq i \\leq N) are (x_i,y_i).\n\nLet us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior.\n\nHere, points on the sides of the rectangle are considered to be in the interior.\n\nFind the minimum possible area of such a rectangle.\n\nConstraints\n\n2 \\leq K \\leq N \\leq 50\n\n-10^9 \\leq x_i,y_i \\leq 10^9 (1 \\leq i \\leq N)\n\nx_i≠x_j (1 \\leq i (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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (len (integer-length k))\n (as (make-array n :element-type 'uint32))\n (bs (make-array n :element-type 'uint32)))\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (println\n (max (loop for pos below len\n when (logbitp pos k)\n maximize\n (let ((mask (dpb (ldb (byte pos 0) -1)\n (byte (+ pos 1) 0)\n k)))\n (loop for i below n\n when (= mask (logior mask (aref as i)))\n sum (aref bs i) of-type uint62)))\n (loop for i below n\n when (= k (logior k (aref as i)))\n sum (aref bs i) of-type uint62)))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1568917632, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03584.html", "problem_id": "p03584", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03584/input.txt", "sample_output_relpath": "derived/input_output/data/p03584/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03584/Lisp/s041784448.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s041784448", "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 #\\# #\\> (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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (len (integer-length k))\n (as (make-array n :element-type 'uint32))\n (bs (make-array n :element-type 'uint32)))\n (declare (uint31 n k))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (println\n (max (loop for pos below len\n when (logbitp pos k)\n maximize\n (let ((mask (dpb (ldb (byte pos 0) -1)\n (byte (+ pos 1) 0)\n k)))\n (loop for i below n\n when (= mask (logior mask (aref as i)))\n sum (aref bs i) of-type uint62)))\n (loop for i below n\n when (= k (logior k (aref as i)))\n sum (aref bs i) of-type uint62)))))\n\n#-swank (main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nSeisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i.\nThere may be multiple equal integers with different utilities.\n\nTakahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.\n\nFind the maximum possible sum of utilities of purchased integers.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n0 \\leq K < 2^{30}\n\n0 \\leq A_i < 2^{30}(1\\leq i\\leq N)\n\n1 \\leq B_i \\leq 10^9(1\\leq i\\leq N)\n\nAll input values are integers.\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 B_1\n:\nA_N B_N\n\nOutputs\n\nPrint the maximum possible sum of utilities of purchased integers.\n\nSample Input 1\n\n3 5\n3 3\n4 4\n2 5\n\nSample Output 1\n\n8\n\nBuy 2 and 3 to achieve the maximum possible total utility, 8.\n\nSample Input 2\n\n3 6\n3 3\n4 4\n2 5\n\nSample Output 2\n\n9\n\nBuy 2 and 4 to achieve the maximum possible total utility, 9.\n\nSample Input 3\n\n7 14\n10 5\n7 4\n11 4\n9 8\n3 6\n6 2\n8 9\n\nSample Output 3\n\n32", "sample_input": "3 5\n3 3\n4 4\n2 5\n"}, "reference_outputs": ["8\n"], "source_document_id": "p03584", "source_text": "Score : 500 points\n\nProblem Statement\n\nSeisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i.\nThere may be multiple equal integers with different utilities.\n\nTakahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.\n\nFind the maximum possible sum of utilities of purchased integers.\n\nConstraints\n\n1 \\leq N \\leq 10^5\n\n0 \\leq K < 2^{30}\n\n0 \\leq A_i < 2^{30}(1\\leq i\\leq N)\n\n1 \\leq B_i \\leq 10^9(1\\leq i\\leq N)\n\nAll input values are integers.\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN K\nA_1 B_1\n:\nA_N B_N\n\nOutputs\n\nPrint the maximum possible sum of utilities of purchased integers.\n\nSample Input 1\n\n3 5\n3 3\n4 4\n2 5\n\nSample Output 1\n\n8\n\nBuy 2 and 3 to achieve the maximum possible total utility, 8.\n\nSample Input 2\n\n3 6\n3 3\n4 4\n2 5\n\nSample Output 2\n\n9\n\nBuy 2 and 4 to achieve the maximum possible total utility, 9.\n\nSample Input 3\n\n7 14\n10 5\n7 4\n11 4\n9 8\n3 6\n6 2\n8 9\n\nSample Output 3\n\n32", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3356, "cpu_time_ms": 342, "memory_kb": 24808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s972787834", "group_id": "codeNet:p03587", "input_text": "(apply #'+ (map 'list #'digit-char-p (read-line)))", "language": "Lisp", "metadata": {"date": 1506961396, "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/s972787834.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s972787834", "user_id": "u688109525"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(apply #'+ (map 'list #'digit-char-p (read-line)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 20, "memory_kb": 4196}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s897741362", "group_id": "codeNet:p03592", "input_text": ";;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;;unnamed-block\n(defun block-reader (stream char)\n (declare (ignore char))\n `(progn ,@(read-delimited-list #\\} stream t)))\n(set-macro-character #\\{ #'block-reader)\n(set-macro-character #\\} (get-macro-character #\\)))\n;;\n\n(let ((n (read))\n (m (read))\n (k (read))\n (ans \"No\"))\n 🌀 (for r to n\n :for black = 0)\n 🌀 (for l to m)\n {(incf black (* l n))\n (incf black (* r m))\n (decf black (* 2 l r))\n (when (= black k) (setf ans \"Yes\")) }\n (format t \"~A~%\" ans))", "language": "Lisp", "metadata": {"date": 1506217320, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03592.html", "problem_id": "p03592", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03592/input.txt", "sample_output_relpath": "derived/input_output/data/p03592/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03592/Lisp/s897741362.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s897741362", "user_id": "u140665374"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": ";;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;;unnamed-block\n(defun block-reader (stream char)\n (declare (ignore char))\n `(progn ,@(read-delimited-list #\\} stream t)))\n(set-macro-character #\\{ #'block-reader)\n(set-macro-character #\\} (get-macro-character #\\)))\n;;\n\n(let ((n (read))\n (m (read))\n (k (read))\n (ans \"No\"))\n 🌀 (for r to n\n :for black = 0)\n 🌀 (for l to m)\n {(incf black (* l n))\n (incf black (* r m))\n (decf black (* 2 l r))\n (when (= black k) (setf ans \"Yes\")) }\n (format t \"~A~%\" ans))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nWe have a grid with N rows and M columns of squares. Initially, all the squares are white.\n\nThere is a button attached to each row and each column.\nWhen a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa.\nWhen a button attached to a column is pressed, the colors of all the squares in that column are inverted.\n\nTakahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.\n\nConstraints\n\n1 \\leq N,M \\leq 1000\n\n0 \\leq K \\leq NM\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M K\n\nOutput\n\nIf Takahashi can have exactly K black squares in the grid, print Yes; otherwise, print No.\n\nSample Input 1\n\n2 2 2\n\nSample Output 1\n\nYes\n\nPress the buttons in the order of the first row, the first column.\n\nSample Input 2\n\n2 2 1\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n3 5 8\n\nSample Output 3\n\nYes\n\nPress the buttons in the order of the first column, third column, second row, fifth column.\n\nSample Input 4\n\n7 9 20\n\nSample Output 4\n\nNo", "sample_input": "2 2 2\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03592", "source_text": "Score : 200 points\n\nProblem Statement\n\nWe have a grid with N rows and M columns of squares. Initially, all the squares are white.\n\nThere is a button attached to each row and each column.\nWhen a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa.\nWhen a button attached to a column is pressed, the colors of all the squares in that column are inverted.\n\nTakahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.\n\nConstraints\n\n1 \\leq N,M \\leq 1000\n\n0 \\leq K \\leq NM\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN M K\n\nOutput\n\nIf Takahashi can have exactly K black squares in the grid, print Yes; otherwise, print No.\n\nSample Input 1\n\n2 2 2\n\nSample Output 1\n\nYes\n\nPress the buttons in the order of the first row, the first column.\n\nSample Input 2\n\n2 2 1\n\nSample Output 2\n\nNo\n\nSample Input 3\n\n3 5 8\n\nSample Output 3\n\nYes\n\nPress the buttons in the order of the first column, third column, second row, fifth column.\n\nSample Input 4\n\n7 9 20\n\nSample Output 4\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 688, "cpu_time_ms": 511, "memory_kb": 14948}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s436234424", "group_id": "codeNet:p03597", "input_text": "(princ(-(expt(read)2)(read)))", "language": "Lisp", "metadata": {"date": 1528425343, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s436234424.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s436234424", "user_id": "u657913472"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(princ(-(expt(read)2)(read)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 29, "cpu_time_ms": 5, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s761918116", "group_id": "codeNet:p03598", "input_text": "(let((n(read))(k(read)))(princ(loop for i from 1 to n sum(*(min(setq a(read))(- k a))2))))", "language": "Lisp", "metadata": {"date": 1534834334, "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/s761918116.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s761918116", "user_id": "u657913472"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(let((n(read))(k(read)))(princ(loop for i from 1 to n sum(*(min(setq a(read))(- k a))2))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 90, "cpu_time_ms": 18, "memory_kb": 4320}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s396689897", "group_id": "codeNet:p03600", "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 (mat (make-array (list n n) :element-type 'uint32))\n (res (make-array (list n n) :element-type 'uint32)))\n (dotimes (i n)\n (dotimes (j n)\n (setf (aref res i j) (setf (aref mat i j) (read-fixnum)))))\n (dotimes (k n)\n (dotimes (i n)\n (dotimes (j n)\n (unless (or (= i k) (= j k))\n (let ((new-dist (+ (aref mat i k) (aref mat k j))))\n (when (> (aref mat i j) new-dist)\n (println -1)\n (return-from main))\n (when (= (aref mat i j) new-dist)\n (setf (aref res i j) 0)))))))\n (println (floor (reduce #'+ (array-storage-vector res)) 2))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1561775907, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03600.html", "problem_id": "p03600", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03600/input.txt", "sample_output_relpath": "derived/input_output/data/p03600/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03600/Lisp/s396689897.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s396689897", "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 (mat (make-array (list n n) :element-type 'uint32))\n (res (make-array (list n n) :element-type 'uint32)))\n (dotimes (i n)\n (dotimes (j n)\n (setf (aref res i j) (setf (aref mat i j) (read-fixnum)))))\n (dotimes (k n)\n (dotimes (i n)\n (dotimes (j n)\n (unless (or (= i k) (= j k))\n (let ((new-dist (+ (aref mat i k) (aref mat k j))))\n (when (> (aref mat i j) new-dist)\n (println -1)\n (return-from main))\n (when (= (aref mat i j) new-dist)\n (setf (aref res i j) 0)))))))\n (println (floor (reduce #'+ (array-storage-vector res)) 2))))\n\n#-swank(main)\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nIn Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads.\nThe following are known about the road network:\n\nPeople traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.\n\nDifferent roads may have had different lengths, but all the lengths were positive integers.\n\nSnuke the archeologist found a table with N rows and N columns, A, in the ruin of Takahashi Kingdom.\nHe thought that it represented the shortest distances between the cities along the roads in the kingdom.\n\nDetermine whether there exists a road network such that for each u and v, the integer A_{u, v} at the u-th row and v-th column of A is equal to the length of the shortest path from City u to City v.\nIf such a network exist, find the shortest possible total length of the roads.\n\nConstraints\n\n1 \\leq N \\leq 300\n\nIf i ≠ j, 1 \\leq A_{i, j} = A_{j, i} \\leq 10^9.\n\nA_{i, i} = 0\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} ... A_{1, N}\nA_{2, 1} A_{2, 2} ... A_{2, N}\n...\nA_{N, 1} A_{N, 2} ... A_{N, N}\n\nOutputs\n\nIf there exists no network that satisfies the condition, print -1.\nIf it exists, print the shortest possible total length of the roads.\n\nSample Input 1\n\n3\n0 1 3\n1 0 2\n3 2 0\n\nSample Output 1\n\n3\n\nThe network below satisfies the condition:\n\nCity 1 and City 2 is connected by a road of length 1.\n\nCity 2 and City 3 is connected by a road of length 2.\n\nCity 3 and City 1 is not connected by a road.\n\nSample Input 2\n\n3\n0 1 3\n1 0 1\n3 1 0\n\nSample Output 2\n\n-1\n\nAs there is a path of length 1 from City 1 to City 2 and City 2 to City 3, there is a path of length 2 from City 1 to City 3.\nHowever, according to the table, the shortest distance between City 1 and City 3 must be 3.\n\nThus, we conclude that there exists no network that satisfies the condition.\n\nSample Input 3\n\n5\n0 21 18 11 28\n21 0 13 10 26\n18 13 0 23 13\n11 10 23 0 17\n28 26 13 17 0\n\nSample Output 3\n\n82\n\nSample Input 4\n\n3\n0 1000000000 1000000000\n1000000000 0 1000000000\n1000000000 1000000000 0\n\nSample Output 4\n\n3000000000", "sample_input": "3\n0 1 3\n1 0 2\n3 2 0\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03600", "source_text": "Score : 500 points\n\nProblem Statement\n\nIn Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads.\nThe following are known about the road network:\n\nPeople traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.\n\nDifferent roads may have had different lengths, but all the lengths were positive integers.\n\nSnuke the archeologist found a table with N rows and N columns, A, in the ruin of Takahashi Kingdom.\nHe thought that it represented the shortest distances between the cities along the roads in the kingdom.\n\nDetermine whether there exists a road network such that for each u and v, the integer A_{u, v} at the u-th row and v-th column of A is equal to the length of the shortest path from City u to City v.\nIf such a network exist, find the shortest possible total length of the roads.\n\nConstraints\n\n1 \\leq N \\leq 300\n\nIf i ≠ j, 1 \\leq A_{i, j} = A_{j, i} \\leq 10^9.\n\nA_{i, i} = 0\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} ... A_{1, N}\nA_{2, 1} A_{2, 2} ... A_{2, N}\n...\nA_{N, 1} A_{N, 2} ... A_{N, N}\n\nOutputs\n\nIf there exists no network that satisfies the condition, print -1.\nIf it exists, print the shortest possible total length of the roads.\n\nSample Input 1\n\n3\n0 1 3\n1 0 2\n3 2 0\n\nSample Output 1\n\n3\n\nThe network below satisfies the condition:\n\nCity 1 and City 2 is connected by a road of length 1.\n\nCity 2 and City 3 is connected by a road of length 2.\n\nCity 3 and City 1 is not connected by a road.\n\nSample Input 2\n\n3\n0 1 3\n1 0 1\n3 1 0\n\nSample Output 2\n\n-1\n\nAs there is a path of length 1 from City 1 to City 2 and City 2 to City 3, there is a path of length 2 from City 1 to City 3.\nHowever, according to the table, the shortest distance between City 1 and City 3 must be 3.\n\nThus, we conclude that there exists no network that satisfies the condition.\n\nSample Input 3\n\n5\n0 21 18 11 28\n21 0 13 10 26\n18 13 0 23 13\n11 10 23 0 17\n28 26 13 17 0\n\nSample Output 3\n\n82\n\nSample Input 4\n\n3\n0 1000000000 1000000000\n1000000000 0 1000000000\n1000000000 1000000000 0\n\nSample Output 4\n\n3000000000", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3137, "cpu_time_ms": 512, "memory_kb": 17376}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s616589254", "group_id": "codeNet:p03600", "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 (declare #.OPT)\n (let* ((n (read))\n (mat (make-array (list n n) :element-type 'uint32))\n (res (make-array (list n n) :element-type 'uint32)))\n (dotimes (i n)\n (dotimes (j n)\n (setf (aref res i j) (setf (aref mat i j) (read-fixnum)))))\n (dotimes (k n)\n (dotimes (i n)\n (dotimes (j n)\n (let ((new-dist (+ (aref mat i k) (aref mat k j))))\n (when (> (aref mat i j) new-dist)\n (println -1)\n (return-from main))\n (when (and (= (aref mat i j) new-dist)\n (/= i k)\n (/= k j))\n (setf (aref res i j) 0))))))\n (println (floor (reduce #'+ (array-storage-vector res)) 2))))\n\n#-swank(main)\n\n", "language": "Lisp", "metadata": {"date": 1561775790, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03600.html", "problem_id": "p03600", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03600/input.txt", "sample_output_relpath": "derived/input_output/data/p03600/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03600/Lisp/s616589254.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s616589254", "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 (declare #.OPT)\n (let* ((n (read))\n (mat (make-array (list n n) :element-type 'uint32))\n (res (make-array (list n n) :element-type 'uint32)))\n (dotimes (i n)\n (dotimes (j n)\n (setf (aref res i j) (setf (aref mat i j) (read-fixnum)))))\n (dotimes (k n)\n (dotimes (i n)\n (dotimes (j n)\n (let ((new-dist (+ (aref mat i k) (aref mat k j))))\n (when (> (aref mat i j) new-dist)\n (println -1)\n (return-from main))\n (when (and (= (aref mat i j) new-dist)\n (/= i k)\n (/= k j))\n (setf (aref res i j) 0))))))\n (println (floor (reduce #'+ (array-storage-vector res)) 2))))\n\n#-swank(main)\n\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nIn Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads.\nThe following are known about the road network:\n\nPeople traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.\n\nDifferent roads may have had different lengths, but all the lengths were positive integers.\n\nSnuke the archeologist found a table with N rows and N columns, A, in the ruin of Takahashi Kingdom.\nHe thought that it represented the shortest distances between the cities along the roads in the kingdom.\n\nDetermine whether there exists a road network such that for each u and v, the integer A_{u, v} at the u-th row and v-th column of A is equal to the length of the shortest path from City u to City v.\nIf such a network exist, find the shortest possible total length of the roads.\n\nConstraints\n\n1 \\leq N \\leq 300\n\nIf i ≠ j, 1 \\leq A_{i, j} = A_{j, i} \\leq 10^9.\n\nA_{i, i} = 0\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} ... A_{1, N}\nA_{2, 1} A_{2, 2} ... A_{2, N}\n...\nA_{N, 1} A_{N, 2} ... A_{N, N}\n\nOutputs\n\nIf there exists no network that satisfies the condition, print -1.\nIf it exists, print the shortest possible total length of the roads.\n\nSample Input 1\n\n3\n0 1 3\n1 0 2\n3 2 0\n\nSample Output 1\n\n3\n\nThe network below satisfies the condition:\n\nCity 1 and City 2 is connected by a road of length 1.\n\nCity 2 and City 3 is connected by a road of length 2.\n\nCity 3 and City 1 is not connected by a road.\n\nSample Input 2\n\n3\n0 1 3\n1 0 1\n3 1 0\n\nSample Output 2\n\n-1\n\nAs there is a path of length 1 from City 1 to City 2 and City 2 to City 3, there is a path of length 2 from City 1 to City 3.\nHowever, according to the table, the shortest distance between City 1 and City 3 must be 3.\n\nThus, we conclude that there exists no network that satisfies the condition.\n\nSample Input 3\n\n5\n0 21 18 11 28\n21 0 13 10 26\n18 13 0 23 13\n11 10 23 0 17\n28 26 13 17 0\n\nSample Output 3\n\n82\n\nSample Input 4\n\n3\n0 1000000000 1000000000\n1000000000 0 1000000000\n1000000000 1000000000 0\n\nSample Output 4\n\n3000000000", "sample_input": "3\n0 1 3\n1 0 2\n3 2 0\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03600", "source_text": "Score : 500 points\n\nProblem Statement\n\nIn Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads.\nThe following are known about the road network:\n\nPeople traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.\n\nDifferent roads may have had different lengths, but all the lengths were positive integers.\n\nSnuke the archeologist found a table with N rows and N columns, A, in the ruin of Takahashi Kingdom.\nHe thought that it represented the shortest distances between the cities along the roads in the kingdom.\n\nDetermine whether there exists a road network such that for each u and v, the integer A_{u, v} at the u-th row and v-th column of A is equal to the length of the shortest path from City u to City v.\nIf such a network exist, find the shortest possible total length of the roads.\n\nConstraints\n\n1 \\leq N \\leq 300\n\nIf i ≠ j, 1 \\leq A_{i, j} = A_{j, i} \\leq 10^9.\n\nA_{i, i} = 0\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nA_{1, 1} A_{1, 2} ... A_{1, N}\nA_{2, 1} A_{2, 2} ... A_{2, N}\n...\nA_{N, 1} A_{N, 2} ... A_{N, N}\n\nOutputs\n\nIf there exists no network that satisfies the condition, print -1.\nIf it exists, print the shortest possible total length of the roads.\n\nSample Input 1\n\n3\n0 1 3\n1 0 2\n3 2 0\n\nSample Output 1\n\n3\n\nThe network below satisfies the condition:\n\nCity 1 and City 2 is connected by a road of length 1.\n\nCity 2 and City 3 is connected by a road of length 2.\n\nCity 3 and City 1 is not connected by a road.\n\nSample Input 2\n\n3\n0 1 3\n1 0 1\n3 1 0\n\nSample Output 2\n\n-1\n\nAs there is a path of length 1 from City 1 to City 2 and City 2 to City 3, there is a path of length 2 from City 1 to City 3.\nHowever, according to the table, the shortest distance between City 1 and City 3 must be 3.\n\nThus, we conclude that there exists no network that satisfies the condition.\n\nSample Input 3\n\n5\n0 21 18 11 28\n21 0 13 10 26\n18 13 0 23 13\n11 10 23 0 17\n28 26 13 17 0\n\nSample Output 3\n\n82\n\nSample Input 4\n\n3\n0 1000000000 1000000000\n1000000000 0 1000000000\n1000000000 1000000000 0\n\nSample Output 4\n\n3000000000", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3138, "cpu_time_ms": 577, "memory_kb": 37480}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s738059370", "group_id": "codeNet:p03603", "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;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\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 corresponding\n;; value to a hash-table when evaluating (ADD A B) for the first time; ADD\n;; returns the stored value when it is called with the same arguments\n;; (w.r.t. EQUAL) again.\n;;\n;; The storage for the cache can be hash-table or array. Let's see an example\n;; for array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form caches 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 doesn't take.)\n;;\n;; If you want to ignore some arguments, you can use `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; => 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 debug the memoized function by :DEBUG option:\n;; (with-cache (:array (10 10) :initial-element -1 :debug 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(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY\"\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dimensions-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\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 (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 \"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 ((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 #+sbcl 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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\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(define-modify-macro minf (new-value)\n (lambda (x y) (min x y)))\n\n(defconstant +inf+ #x7fffffff)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (xs (make-array n :element-type 'uint32)))\n (declare ((simple-array list (*)) graph))\n (loop for i from 1 below n\n do (push i (aref graph (- (read-fixnum) 1))))\n (dotimes (i n)\n (setf (aref xs i) (read-fixnum)))\n (with-cache (:array (1001) :element-type 'int32 :initial-element -1)\n (labels ((dfs (v)\n (declare (values uint32))\n (let ((k (length (aref graph v))) ; the number of children\n (adjs (coerce (aref graph v) '(simple-array uint32 (*)))))\n (declare (uint32 k))\n (with-cache (:array ((+ k 1) 5001) :element-type 'int32 :initial-element -1)\n (sb-int:named-let recur ((y k) (z (aref xs v)))\n (if (zerop y)\n 0\n (let ((vertex (aref adjs (- y 1)))\n (res +inf+))\n (declare (uint32 res))\n (when (<= (aref xs vertex) z)\n (minf res (+ (recur (- y 1) (- z (aref xs vertex)))\n (dfs vertex))))\n (when (<= (dfs vertex) z)\n (minf res (+ (recur (- y 1) (- z (dfs vertex)))\n (aref xs vertex))))\n res)))))))\n (write-line (if (= +inf+ (dfs 0))\n \"IMPOSSIBLE\"\n \"POSSIBLE\"))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565336605, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03603.html", "problem_id": "p03603", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03603/input.txt", "sample_output_relpath": "derived/input_output/data/p03603/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03603/Lisp/s738059370.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s738059370", "user_id": "u352600849"}, "prompt_components": {"gold_output": "POSSIBLE\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;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\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 corresponding\n;; value to a hash-table when evaluating (ADD A B) for the first time; ADD\n;; returns the stored value when it is called with the same arguments\n;; (w.r.t. EQUAL) again.\n;;\n;; The storage for the cache can be hash-table or array. Let's see an example\n;; for array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form caches 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 doesn't take.)\n;;\n;; If you want to ignore some arguments, you can use `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; => 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 debug the memoized function by :DEBUG option:\n;; (with-cache (:array (10 10) :initial-element -1 :debug 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(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY\"\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dimensions-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\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 (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 \"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 ((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 #+sbcl 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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (let* ((minus nil)\n (result (loop (let ((byte (%read-byte)))\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(define-modify-macro minf (new-value)\n (lambda (x y) (min x y)))\n\n(defconstant +inf+ #x7fffffff)\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (xs (make-array n :element-type 'uint32)))\n (declare ((simple-array list (*)) graph))\n (loop for i from 1 below n\n do (push i (aref graph (- (read-fixnum) 1))))\n (dotimes (i n)\n (setf (aref xs i) (read-fixnum)))\n (with-cache (:array (1001) :element-type 'int32 :initial-element -1)\n (labels ((dfs (v)\n (declare (values uint32))\n (let ((k (length (aref graph v))) ; the number of children\n (adjs (coerce (aref graph v) '(simple-array uint32 (*)))))\n (declare (uint32 k))\n (with-cache (:array ((+ k 1) 5001) :element-type 'int32 :initial-element -1)\n (sb-int:named-let recur ((y k) (z (aref xs v)))\n (if (zerop y)\n 0\n (let ((vertex (aref adjs (- y 1)))\n (res +inf+))\n (declare (uint32 res))\n (when (<= (aref xs vertex) z)\n (minf res (+ (recur (- y 1) (- z (aref xs vertex)))\n (dfs vertex))))\n (when (<= (dfs vertex) z)\n (minf res (+ (recur (- y 1) (- z (dfs vertex)))\n (aref xs vertex))))\n res)))))))\n (write-line (if (= +inf+ (dfs 0))\n \"IMPOSSIBLE\"\n \"POSSIBLE\"))))))\n\n#-swank (main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nWe have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \\leq i \\leq N) is Vertex P_i.\n\nTo each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.\n\nSnuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to allocate colors and weights so that the following condition is satisfied for all v.\n\nThe total weight of the vertices with the same color as v among the vertices contained in the subtree whose root is v, is X_v.\n\nHere, the subtree whose root is v is the tree consisting of Vertex v and all of its descendants.\n\nDetermine whether it is possible to allocate colors and weights in this way.\n\nConstraints\n\n1 \\leq N \\leq 1 000\n\n1 \\leq P_i \\leq i - 1\n\n0 \\leq X_i \\leq 5 000\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nP_2 P_3 ... P_N\nX_1 X_2 ... X_N\n\nOutputs\n\nIf it is possible to allocate colors and weights to the vertices so that the condition is satisfied, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3\n1 1\n4 3 2\n\nSample Output 1\n\nPOSSIBLE\n\nFor example, the following allocation satisfies the condition:\n\nSet the color of Vertex 1 to white and its weight to 2.\n\nSet the color of Vertex 2 to black and its weight to 3.\n\nSet the color of Vertex 3 to white and its weight to 2.\n\nThere are also other possible allocations.\n\nSample Input 2\n\n3\n1 2\n1 2 3\n\nSample Output 2\n\nIMPOSSIBLE\n\nIf the same color is allocated to Vertex 2 and Vertex 3, Vertex 2 cannot be allocated a non-negative weight.\n\nIf different colors are allocated to Vertex 2 and 3, no matter which color is allocated to Vertex 1, it cannot be allocated a non-negative weight.\n\nThus, there exists no allocation of colors and weights that satisfies the condition.\n\nSample Input 3\n\n8\n1 1 1 3 4 5 5\n4 1 6 2 2 1 3 3\n\nSample Output 3\n\nPOSSIBLE\n\nSample Input 4\n\n1\n\n0\n\nSample Output 4\n\nPOSSIBLE", "sample_input": "3\n1 1\n4 3 2\n"}, "reference_outputs": ["POSSIBLE\n"], "source_document_id": "p03603", "source_text": "Score : 700 points\n\nProblem Statement\n\nWe have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \\leq i \\leq N) is Vertex P_i.\n\nTo each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.\n\nSnuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to allocate colors and weights so that the following condition is satisfied for all v.\n\nThe total weight of the vertices with the same color as v among the vertices contained in the subtree whose root is v, is X_v.\n\nHere, the subtree whose root is v is the tree consisting of Vertex v and all of its descendants.\n\nDetermine whether it is possible to allocate colors and weights in this way.\n\nConstraints\n\n1 \\leq N \\leq 1 000\n\n1 \\leq P_i \\leq i - 1\n\n0 \\leq X_i \\leq 5 000\n\nInputs\n\nInput is given from Standard Input in the following format:\n\nN\nP_2 P_3 ... P_N\nX_1 X_2 ... X_N\n\nOutputs\n\nIf it is possible to allocate colors and weights to the vertices so that the condition is satisfied, print POSSIBLE; otherwise, print IMPOSSIBLE.\n\nSample Input 1\n\n3\n1 1\n4 3 2\n\nSample Output 1\n\nPOSSIBLE\n\nFor example, the following allocation satisfies the condition:\n\nSet the color of Vertex 1 to white and its weight to 2.\n\nSet the color of Vertex 2 to black and its weight to 3.\n\nSet the color of Vertex 3 to white and its weight to 2.\n\nThere are also other possible allocations.\n\nSample Input 2\n\n3\n1 2\n1 2 3\n\nSample Output 2\n\nIMPOSSIBLE\n\nIf the same color is allocated to Vertex 2 and Vertex 3, Vertex 2 cannot be allocated a non-negative weight.\n\nIf different colors are allocated to Vertex 2 and 3, no matter which color is allocated to Vertex 1, it cannot be allocated a non-negative weight.\n\nThus, there exists no allocation of colors and weights that satisfies the condition.\n\nSample Input 3\n\n8\n1 1 1 3 4 5 5\n4 1 6 2 2 1 3 3\n\nSample Output 3\n\nPOSSIBLE\n\nSample Input 4\n\n1\n\n0\n\nSample Output 4\n\nPOSSIBLE", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 12483, "cpu_time_ms": 303, "memory_kb": 84964}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s071521401", "group_id": "codeNet:p03607", "input_text": "(let* ((n (read))\n (lst (sort (loop :repeat n :collect (read)) #'<))\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": 1573577047, "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/s071521401.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s071521401", "user_id": "u610490393"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (lst (sort (loop :repeat n :collect (read)) #'<))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 360, "cpu_time_ms": 401, "memory_kb": 69988}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s080754913", "group_id": "codeNet:p03607", "input_text": "(let ((lst (loop repeat (read) collect (read))))\n (do ((l (sort lst #'<) (cdr l))\n (n 0)\n (count 0))\n ((null l) 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 0)))))", "language": "Lisp", "metadata": {"date": 1505211229, "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/s080754913.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s080754913", "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 0)\n (count 0))\n ((null l) 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 0)))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 316, "memory_kb": 61280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s484846447", "group_id": "codeNet:p03610", "input_text": "(let ((s (concatenate 'list (read-line))))\n\n (defun solve (lst &optional flag ans)\n (cond\n ((null lst) (concatenate 'string (reverse ans)))\n ((null flag) (solve (cdr lst) t (cons (car lst) ans)))\n (t (solve (cdr lst) nil ans))))\n\n (format t \"~A~%\"\n (solve s)))\n", "language": "Lisp", "metadata": {"date": 1595193987, "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/s484846447.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s484846447", "user_id": "u336541610"}, "prompt_components": {"gold_output": "acdr\n", "input_to_evaluate": "(let ((s (concatenate 'list (read-line))))\n\n (defun solve (lst &optional flag ans)\n (cond\n ((null lst) (concatenate 'string (reverse ans)))\n ((null flag) (solve (cdr lst) t (cons (car lst) ans)))\n (t (solve (cdr lst) nil ans))))\n\n (format t \"~A~%\"\n (solve s)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 30, "memory_kb": 29036}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s137449118", "group_id": "codeNet:p03610", "input_text": "(defun solve (s &optional flag ans)\n (cond\n ((null s) (concatenate 'string (reverse ans)))\n ((null flag) (solve (rest s) t (cons (first s) ans)))\n (t (solve (rest s) nil ans))))\n\n(let ((s (concatenate 'list (read-line))))\n (princ (solve s)))", "language": "Lisp", "metadata": {"date": 1594881642, "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/s137449118.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s137449118", "user_id": "u425762225"}, "prompt_components": {"gold_output": "acdr\n", "input_to_evaluate": "(defun solve (s &optional flag ans)\n (cond\n ((null s) (concatenate 'string (reverse ans)))\n ((null flag) (solve (rest s) t (cons (first s) ans)))\n (t (solve (rest s) nil ans))))\n\n(let ((s (concatenate 'list (read-line))))\n (princ (solve s)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 31, "memory_kb": 28996}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s699801134", "group_id": "codeNet:p03611", "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 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 main (lst)\n (let ((group (sort (group (append (list -100000000 -1000000) lst)) #'< :key #'car)))\n (loop for i in group\n for j in (cdr group)\n for k in (cddr group)\n maximize (+ (length j)\n (if (= (- (car j) (car i)) 1) (length i) 0)\n (if (= (- (car k) (car j)) 1) (length k) 0)))))\n\n(princ (main (read-times (read))))\n", "language": "Lisp", "metadata": {"date": 1589155704, "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/s699801134.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s699801134", "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(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 main (lst)\n (let ((group (sort (group (append (list -100000000 -1000000) lst)) #'< :key #'car)))\n (loop for i in group\n for j in (cdr group)\n for k in (cddr group)\n maximize (+ (length j)\n (if (= (- (car j) (car i)) 1) (length i) 0)\n (if (= (- (car k) (car j)) 1) (length k) 0)))))\n\n(princ (main (read-times (read))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4227, "cpu_time_ms": 282, "memory_kb": 62524}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s426937910", "group_id": "codeNet:p03612", "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(defun read-fixnum ()\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char *standard-input* nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte *standard-input* nil #.(char-code #\\Nul) nil))))\n (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 ((= 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 `(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 (ps (make-array n :element-type 'uint32))\n (res 0))\n (declare (uint32 res))\n (dotimes (i n) (setf (aref ps i) (- (the fixnum (read-fixnum)) 1)))\n (dotimes (i n (println res))\n (when (and (= (aref ps i) i))\n (if (= i (- n 1))\n (rotatef (aref ps i) (aref ps (- i 1)))\n (rotatef (aref ps i) (aref ps (+ i 1))))\n (incf res)))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1553603968, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03612.html", "problem_id": "p03612", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03612/input.txt", "sample_output_relpath": "derived/input_output/data/p03612/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03612/Lisp/s426937910.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s426937910", "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(defun read-fixnum ()\n (declare #.OPT)\n (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char *standard-input* nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte *standard-input* nil #.(char-code #\\Nul) nil))))\n (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 ((= 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 `(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 (ps (make-array n :element-type 'uint32))\n (res 0))\n (declare (uint32 res))\n (dotimes (i n) (setf (aref ps i) (- (the fixnum (read-fixnum)) 1)))\n (dotimes (i n (println res))\n (when (and (= (aref ps i) i))\n (if (= i (- n 1))\n (rotatef (aref ps i) (aref ps (- i 1)))\n (rotatef (aref ps i) (aref ps (+ i 1))))\n (incf res)))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N.\nYou can perform the following operation any number of times (possibly zero):\n\nOperation: Swap two adjacent elements in the permutation.\n\nYou want to have p_i ≠ i for all 1≤i≤N.\nFind the minimum required number of operations to achieve this.\n\nConstraints\n\n2≤N≤10^5\n\np_1,p_2,..,p_N is a permutation of 1,2,..,N.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\np_1 p_2 .. p_N\n\nOutput\n\nPrint the minimum required number of operations\n\nSample Input 1\n\n5\n1 4 3 5 2\n\nSample Output 1\n\n2\n\nSwap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the condition.\nThis is the minimum possible number, so the answer is 2.\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n1\n\nSwapping 1 and 2 satisfies the condition.\n\nSample Input 3\n\n2\n2 1\n\nSample Output 3\n\n0\n\nThe condition is already satisfied initially.\n\nSample Input 4\n\n9\n1 2 4 9 5 8 7 3 6\n\nSample Output 4\n\n3", "sample_input": "5\n1 4 3 5 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03612", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N.\nYou can perform the following operation any number of times (possibly zero):\n\nOperation: Swap two adjacent elements in the permutation.\n\nYou want to have p_i ≠ i for all 1≤i≤N.\nFind the minimum required number of operations to achieve this.\n\nConstraints\n\n2≤N≤10^5\n\np_1,p_2,..,p_N is a permutation of 1,2,..,N.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\np_1 p_2 .. p_N\n\nOutput\n\nPrint the minimum required number of operations\n\nSample Input 1\n\n5\n1 4 3 5 2\n\nSample Output 1\n\n2\n\nSwap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the condition.\nThis is the minimum possible number, so the answer is 2.\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n1\n\nSwapping 1 and 2 satisfies the condition.\n\nSample Input 3\n\n2\n2 1\n\nSample Output 3\n\n0\n\nThe condition is already satisfied initially.\n\nSample Input 4\n\n9\n1 2 4 9 5 8 7 3 6\n\nSample Output 4\n\n3", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2542, "cpu_time_ms": 192, "memory_kb": 21988}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s679474542", "group_id": "codeNet:p03617", "input_text": "(defun solve (q h s d n &optional (ans 0))\n (setq s (min (* 4 q)\n (* 2 h)\n s))\n (setq ans (* (floor n 2) (min (* s 2) d)))\n (when (oddp n)\n (setq ans (+ ans s)))\n (floor ans))\n\n(defun main ()\n (let ((q (read))\n (h (read))\n (s (read))\n (d (read))\n (n (read)))\n (princ (solve q h s d n))\n (fresh-line)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1594254286, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s679474542.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s679474542", "user_id": "u425762225"}, "prompt_components": {"gold_output": "150\n", "input_to_evaluate": "(defun solve (q h s d n &optional (ans 0))\n (setq s (min (* 4 q)\n (* 2 h)\n s))\n (setq ans (* (floor n 2) (min (* s 2) d)))\n (when (oddp n)\n (setq ans (+ ans s)))\n (floor ans))\n\n(defun main ()\n (let ((q (read))\n (h (read))\n (s (read))\n (d (read))\n (n (read)))\n (princ (solve q h s d n))\n (fresh-line)))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 380, "cpu_time_ms": 20, "memory_kb": 24380}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s407504099", "group_id": "codeNet:p03623", "input_text": "(let((x(read))(a(read))(b(read)))(format t\"~a~&\"(if(<(abs(- x a))(abs(- x b))) \"A\" \"B\")))", "language": "Lisp", "metadata": {"date": 1599545516, "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/s407504099.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s407504099", "user_id": "u425762225"}, "prompt_components": {"gold_output": "B\n", "input_to_evaluate": "(let((x(read))(a(read))(b(read)))(format t\"~a~&\"(if(<(abs(- x a))(abs(- x b))) \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 19, "memory_kb": 24004}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s883428428", "group_id": "codeNet:p03626", "input_text": "(defun f (a b n i acc pred)\n (if (= i n)\n acc\n (let ((x (aref a i))\n (y (aref b i)))\n (if (eq x y)\n (f a b n (1+ i)\n (mod (* acc (case pred ('first 3) ('tate 2) ('yoko 1)))\n 1000000007)\n 'tate)\n (f a b n (+ i 2)\n (mod (* acc (case pred ('first 6) ('tate 2) ('yoko 3)))\n 1000000007)\n 'yoko)))))\n\n(let* ((n (read))\n (a (read-line))\n (b (read-line)))\n (princ (f a b n 0 1 'first))\n (terpri))\n\n", "language": "Lisp", "metadata": {"date": 1503282877, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03626.html", "problem_id": "p03626", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03626/input.txt", "sample_output_relpath": "derived/input_output/data/p03626/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03626/Lisp/s883428428.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s883428428", "user_id": "u188771036"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defun f (a b n i acc pred)\n (if (= i n)\n acc\n (let ((x (aref a i))\n (y (aref b i)))\n (if (eq x y)\n (f a b n (1+ i)\n (mod (* acc (case pred ('first 3) ('tate 2) ('yoko 1)))\n 1000000007)\n 'tate)\n (f a b n (+ i 2)\n (mod (* acc (case pred ('first 6) ('tate 2) ('yoko 3)))\n 1000000007)\n 'yoko)))))\n\n(let* ((n (read))\n (a (read-line))\n (b (read-line)))\n (princ (f a b n 0 1 'first))\n (terpri))\n\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a board with a 2 \\times N grid.\nSnuke covered the board with N dominoes without overlaps.\nHere, a domino can cover a 1 \\times 2 or 2 \\times 1 square.\n\nThen, Snuke decided to paint these dominoes using three colors: red, cyan and green.\nTwo dominoes that are adjacent by side should be painted by different colors.\nHere, it is not always necessary to use all three colors.\n\nFind the number of such ways to paint the dominoes, modulo 1000000007.\n\nThe arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner:\n\nEach domino is represented by a different English letter (lowercase or uppercase).\n\nThe j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.\n\nConstraints\n\n1 \\leq N \\leq 52\n\n|S_1| = |S_2| = N\n\nS_1 and S_2 consist of lowercase and uppercase English letters.\n\nS_1 and S_2 represent a valid arrangement of dominoes.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\nS_2\n\nOutput\n\nPrint the number of such ways to paint the dominoes, modulo 1000000007.\n\nSample Input 1\n\n3\naab\nccb\n\nSample Output 1\n\n6\n\nThere are six ways as shown below:\n\nSample Input 2\n\n1\nZ\nZ\n\nSample Output 2\n\n3\n\nNote that it is not always necessary to use all the colors.\n\nSample Input 3\n\n52\nRvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\nRLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn\n\nSample Output 3\n\n958681902", "sample_input": "3\naab\nccb\n"}, "reference_outputs": ["6\n"], "source_document_id": "p03626", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a board with a 2 \\times N grid.\nSnuke covered the board with N dominoes without overlaps.\nHere, a domino can cover a 1 \\times 2 or 2 \\times 1 square.\n\nThen, Snuke decided to paint these dominoes using three colors: red, cyan and green.\nTwo dominoes that are adjacent by side should be painted by different colors.\nHere, it is not always necessary to use all three colors.\n\nFind the number of such ways to paint the dominoes, modulo 1000000007.\n\nThe arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner:\n\nEach domino is represented by a different English letter (lowercase or uppercase).\n\nThe j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.\n\nConstraints\n\n1 \\leq N \\leq 52\n\n|S_1| = |S_2| = N\n\nS_1 and S_2 consist of lowercase and uppercase English letters.\n\nS_1 and S_2 represent a valid arrangement of dominoes.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\nS_1\nS_2\n\nOutput\n\nPrint the number of such ways to paint the dominoes, modulo 1000000007.\n\nSample Input 1\n\n3\naab\nccb\n\nSample Output 1\n\n6\n\nThere are six ways as shown below:\n\nSample Input 2\n\n1\nZ\nZ\n\nSample Output 2\n\n3\n\nNote that it is not always necessary to use all the colors.\n\nSample Input 3\n\n52\nRvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\nRLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn\n\nSample Output 3\n\n958681902", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 153, "memory_kb": 15976}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s716288423", "group_id": "codeNet:p03629", "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 (declare #.OPT)\n (let* ((s (read-line))\n (n (length s))\n (nexts (make-array (list n 26) :element-type 'uint32))\n (dp (make-array (+ n 1) :element-type 'uint32))\n (seqs (make-array (+ n 1) :element-type 'list)))\n (declare ((simple-array character (*)) s)\n (uint31 n))\n (let ((table (make-array 26 :element-type 'uint32 :initial-element n)))\n (loop for i from (- n 1) downto 0\n do (setf (aref table (- (char-code (aref s i)) 97)) i)\n (dotimes (c 26)\n (setf (aref nexts i c) (aref table c)))))\n (setf (aref dp n) 1)\n (setf (aref seqs n) (list #\\a))\n (loop for i from (- n 1) downto 0\n for res = #xffffffff\n do (dotimes (c 26)\n (if (= n (aref nexts i c))\n (when (< 1 res)\n (setf res 1)\n (setf (aref seqs i) (list (code-char (+ c 97)))))\n (let ((new-value (+ 1 (aref dp (+ 1 (aref nexts i c))))))\n (when (< new-value res)\n (setf res new-value)\n (setf (aref seqs i)\n (cons (code-char (+ c 97))\n (aref seqs (+ 1 (aref nexts i c)))))))))\n (setf (aref dp i) res))\n (dolist (c (aref seqs 0))\n (write-char c))\n (terpri)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563913273, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03629.html", "problem_id": "p03629", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03629/input.txt", "sample_output_relpath": "derived/input_output/data/p03629/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03629/Lisp/s716288423.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s716288423", "user_id": "u352600849"}, "prompt_components": {"gold_output": "b\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 (declare #.OPT)\n (let* ((s (read-line))\n (n (length s))\n (nexts (make-array (list n 26) :element-type 'uint32))\n (dp (make-array (+ n 1) :element-type 'uint32))\n (seqs (make-array (+ n 1) :element-type 'list)))\n (declare ((simple-array character (*)) s)\n (uint31 n))\n (let ((table (make-array 26 :element-type 'uint32 :initial-element n)))\n (loop for i from (- n 1) downto 0\n do (setf (aref table (- (char-code (aref s i)) 97)) i)\n (dotimes (c 26)\n (setf (aref nexts i c) (aref table c)))))\n (setf (aref dp n) 1)\n (setf (aref seqs n) (list #\\a))\n (loop for i from (- n 1) downto 0\n for res = #xffffffff\n do (dotimes (c 26)\n (if (= n (aref nexts i c))\n (when (< 1 res)\n (setf res 1)\n (setf (aref seqs i) (list (code-char (+ c 97)))))\n (let ((new-value (+ 1 (aref dp (+ 1 (aref nexts i c))))))\n (when (< new-value res)\n (setf res new-value)\n (setf (aref seqs i)\n (cons (code-char (+ c 97))\n (aref seqs (+ 1 (aref nexts i c)))))))))\n (setf (aref dp i) res))\n (dolist (c (aref seqs 0))\n (write-char c))\n (terpri)))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nA subsequence of a string S is a string that can be obtained by deleting zero or more characters from S without changing the order of the remaining characters.\nFor example, arc, artistic and (an empty string) are all subsequences of artistic; abc and ci are not.\n\nYou are given a string A consisting of lowercase English letters.\nFind the shortest string among the strings consisting of lowercase English letters that are not subsequences of A.\nIf there are more than one such string, find the lexicographically smallest one among them.\n\nConstraints\n\n1 \\leq |A| \\leq 2 \\times 10^5\n\nA consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\n\nOutput\n\nPrint the lexicographically smallest string among the shortest strings consisting of lowercase English letters that are not subsequences of A.\n\nSample Input 1\n\natcoderregularcontest\n\nSample Output 1\n\nb\n\nThe string atcoderregularcontest contains a as a subsequence, but not b.\n\nSample Input 2\n\nabcdefghijklmnopqrstuvwxyz\n\nSample Output 2\n\naa\n\nSample Input 3\n\nfrqnvhydscshfcgdemurlfrutcpzhopfotpifgepnqjxupnskapziurswqazdwnwbgdhyktfyhqqxpoidfhjdakoxraiedxskywuepzfniuyskxiyjpjlxuqnfgmnjcvtlpnclfkpervxmdbvrbrdn\n\nSample Output 3\n\naca", "sample_input": "atcoderregularcontest\n"}, "reference_outputs": ["b\n"], "source_document_id": "p03629", "source_text": "Score : 600 points\n\nProblem Statement\n\nA subsequence of a string S is a string that can be obtained by deleting zero or more characters from S without changing the order of the remaining characters.\nFor example, arc, artistic and (an empty string) are all subsequences of artistic; abc and ci are not.\n\nYou are given a string A consisting of lowercase English letters.\nFind the shortest string among the strings consisting of lowercase English letters that are not subsequences of A.\nIf there are more than one such string, find the lexicographically smallest one among them.\n\nConstraints\n\n1 \\leq |A| \\leq 2 \\times 10^5\n\nA consists of lowercase English letters.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\n\nOutput\n\nPrint the lexicographically smallest string among the shortest strings consisting of lowercase English letters that are not subsequences of A.\n\nSample Input 1\n\natcoderregularcontest\n\nSample Output 1\n\nb\n\nThe string atcoderregularcontest contains a as a subsequence, but not b.\n\nSample Input 2\n\nabcdefghijklmnopqrstuvwxyz\n\nSample Output 2\n\naa\n\nSample Input 3\n\nfrqnvhydscshfcgdemurlfrutcpzhopfotpifgepnqjxupnskapziurswqazdwnwbgdhyktfyhqqxpoidfhjdakoxraiedxskywuepzfniuyskxiyjpjlxuqnfgmnjcvtlpnclfkpervxmdbvrbrdn\n\nSample Output 3\n\naca", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2680, "cpu_time_ms": 354, "memory_kb": 43492}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s534398506", "group_id": "codeNet:p03631", "input_text": "(let ((n (read-line)))\n (format t \"~a~%\"\n (if (string= n (reverse n))\n \"Yes\" \"No\")))", "language": "Lisp", "metadata": {"date": 1525917971, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03631.html", "problem_id": "p03631", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03631/input.txt", "sample_output_relpath": "derived/input_output/data/p03631/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03631/Lisp/s534398506.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s534398506", "user_id": "u275710783"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((n (read-line)))\n (format t \"~a~%\"\n (if (string= n (reverse n))\n \"Yes\" \"No\")))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a three-digit positive integer N.\n\nDetermine whether N is a palindromic number.\n\nHere, a palindromic number is an integer that reads the same backward as forward in decimal notation.\n\nConstraints\n\n100≤N≤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 N is a palindromic number, print Yes; otherwise, print No.\n\nSample Input 1\n\n575\n\nSample Output 1\n\nYes\n\nN=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.\n\nSample Input 2\n\n123\n\nSample Output 2\n\nNo\n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.\n\nSample Input 3\n\n812\n\nSample Output 3\n\nNo", "sample_input": "575\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03631", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a three-digit positive integer N.\n\nDetermine whether N is a palindromic number.\n\nHere, a palindromic number is an integer that reads the same backward as forward in decimal notation.\n\nConstraints\n\n100≤N≤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 N is a palindromic number, print Yes; otherwise, print No.\n\nSample Input 1\n\n575\n\nSample Output 1\n\nYes\n\nN=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.\n\nSample Input 2\n\n123\n\nSample Output 2\n\nNo\n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.\n\nSample Input 3\n\n812\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 96, "memory_kb": 10340}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s332683384", "group_id": "codeNet:p03631", "input_text": "(setq a (read-line))\n(if (equal a (reverse a)) (format t \"Yes\") (format t \"No\"))", "language": "Lisp", "metadata": {"date": 1515362551, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03631.html", "problem_id": "p03631", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03631/input.txt", "sample_output_relpath": "derived/input_output/data/p03631/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03631/Lisp/s332683384.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s332683384", "user_id": "u648138491"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(setq a (read-line))\n(if (equal a (reverse a)) (format t \"Yes\") (format t \"No\"))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a three-digit positive integer N.\n\nDetermine whether N is a palindromic number.\n\nHere, a palindromic number is an integer that reads the same backward as forward in decimal notation.\n\nConstraints\n\n100≤N≤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 N is a palindromic number, print Yes; otherwise, print No.\n\nSample Input 1\n\n575\n\nSample Output 1\n\nYes\n\nN=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.\n\nSample Input 2\n\n123\n\nSample Output 2\n\nNo\n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.\n\nSample Input 3\n\n812\n\nSample Output 3\n\nNo", "sample_input": "575\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03631", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a three-digit positive integer N.\n\nDetermine whether N is a palindromic number.\n\nHere, a palindromic number is an integer that reads the same backward as forward in decimal notation.\n\nConstraints\n\n100≤N≤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 N is a palindromic number, print Yes; otherwise, print No.\n\nSample Input 1\n\n575\n\nSample Output 1\n\nYes\n\nN=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.\n\nSample Input 2\n\n123\n\nSample Output 2\n\nNo\n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.\n\nSample Input 3\n\n812\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 9, "memory_kb": 3172}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s554362529", "group_id": "codeNet:p03631", "input_text": "(defun te (x)\n (setq x (- x 101))\n )\n(defun main ()\n (setq a (read))\n (setq i (loop for i from 1 do (te a) when (> a 99) return i)) \n (setq a (- a (* i 101))) \n (if (= 0 (/ a 10))\n (princ \"Yes\")\n (princ \"No\")\n )\n )\n(main)", "language": "Lisp", "metadata": {"date": 1502590004, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03631.html", "problem_id": "p03631", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03631/input.txt", "sample_output_relpath": "derived/input_output/data/p03631/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03631/Lisp/s554362529.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s554362529", "user_id": "u610490393"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun te (x)\n (setq x (- x 101))\n )\n(defun main ()\n (setq a (read))\n (setq i (loop for i from 1 do (te a) when (> a 99) return i)) \n (setq a (- a (* i 101))) \n (if (= 0 (/ a 10))\n (princ \"Yes\")\n (princ \"No\")\n )\n )\n(main)", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given a three-digit positive integer N.\n\nDetermine whether N is a palindromic number.\n\nHere, a palindromic number is an integer that reads the same backward as forward in decimal notation.\n\nConstraints\n\n100≤N≤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 N is a palindromic number, print Yes; otherwise, print No.\n\nSample Input 1\n\n575\n\nSample Output 1\n\nYes\n\nN=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.\n\nSample Input 2\n\n123\n\nSample Output 2\n\nNo\n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.\n\nSample Input 3\n\n812\n\nSample Output 3\n\nNo", "sample_input": "575\n"}, "reference_outputs": ["Yes\n"], "source_document_id": "p03631", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given a three-digit positive integer N.\n\nDetermine whether N is a palindromic number.\n\nHere, a palindromic number is an integer that reads the same backward as forward in decimal notation.\n\nConstraints\n\n100≤N≤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 N is a palindromic number, print Yes; otherwise, print No.\n\nSample Input 1\n\n575\n\nSample Output 1\n\nYes\n\nN=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.\n\nSample Input 2\n\n123\n\nSample Output 2\n\nNo\n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.\n\nSample Input 3\n\n812\n\nSample Output 3\n\nNo", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 147, "memory_kb": 13160}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s572248940", "group_id": "codeNet:p03632", "input_text": "(let* ((a (list (cons (read) (read)) (cons (read) (read)))))\n (princ (if (plusp (- (cdar (sort a #'< :key #'cdr)) (caar (sort a #'> :key #'car))))\n (- (cdar (sort a #'< :key #'cdr)) (caar (sort a #'> :key #'car)))\n 0)))", "language": "Lisp", "metadata": {"date": 1553541992, "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/s572248940.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s572248940", "user_id": "u610490393"}, "prompt_components": {"gold_output": "50\n", "input_to_evaluate": "(let* ((a (list (cons (read) (read)) (cons (read) (read)))))\n (princ (if (plusp (- (cdar (sort a #'< :key #'cdr)) (caar (sort a #'> :key #'car))))\n (- (cdar (sort a #'< :key #'cdr)) (caar (sort a #'> :key #'car)))\n 0)))", "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 (- end start) 0)\n (- end start)\n 0)))", "language": "Lisp", "metadata": {"date": 1504150859, "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/s078475972.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s078475972", "user_id": "u140665374"}, "prompt_components": {"gold_output": "50\n", "input_to_evaluate": "(let* ((A (read))\n (B (read))\n (start (max (read) A))\n (end (min (read) B)))\n (format t \"~A~%\" (if (> (- end start) 0)\n (- end start)\n 0)))", "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 (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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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;;;\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;;;\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 (declare ((simple-array uint32 (*)) vector))\n (let* ((n (length vector))\n (height (max 1 (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 &optional identity)\n \"Queries the interval [LEFT, RIGHT). Returns IDENTITY for a null interval [x,\nx).\"\n (declare ((integer 0 #.most-positive-fixnum) left right)\n ((simple-array * (* *)) table))\n (when (>= left right)\n (assert (= left right))\n (return-from dst-query identity))\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 dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(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;; min l . r\n(define-binary-heap heap\n :order (lambda (node1 node2)\n (< (the fixnum (car node1))\n (the fixnum (car node2))))\n :element-type list)\n\n(defconstant +inf+ #xffffffff)\n\n(defun main ()\n (let* ((n (read))\n (ps (make-array n :element-type 'uint32 :initial-element 0))\n (invs (make-array n :element-type 'uint32 :initial-element 0))\n (odd-ps (make-array n :element-type 'uint32 :initial-element 0))\n (even-ps (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (let ((p (- (read-fixnum) 1)))\n (setf (aref ps i) p\n (aref invs p) i\n (aref even-ps i) (if (evenp i) p +inf+)\n (aref odd-ps i) (if (oddp i) p +inf+))))\n (let ((odd-table (make-disjoint-sparse-table odd-ps #'min))\n (even-table (make-disjoint-sparse-table even-ps #'min))\n (min-table (make-disjoint-sparse-table ps #'min))\n (que (make-heap n))\n res)\n #>invs\n (heap-push (list* (dst-query even-table #'min 0 (- n 1)) 0 n) que)\n (loop until (heap-empty-p que)\n for (min1 l . r) = (heap-pop que)\n for min1-pos = (aref invs min1)\n for min2 = (if (evenp min1-pos)\n (dst-query odd-table #'min (+ 1 min1-pos) r)\n (dst-query even-table #'min (+ 1 min1-pos) r))\n for min2-pos = (aref invs min2)\n do (push (+ min1 1) res)\n (push (+ min2 1) res)\n (dbg l r min1 min1-pos min2 min2-pos)\n (assert (and (<= l min1-pos)\n (< min1-pos min2-pos)\n (< min2-pos r)))\n (when (< l min1-pos)\n (assert (evenp (- min1-pos l)))\n (dbg l min1-pos)\n (heap-push (list* (dst-query min-table #'min l (- min1-pos 1))\n l min1-pos)\n que))\n (when (< (+ min1-pos 1) min2-pos)\n (assert (evenp (- min2-pos (+ min1-pos 1))))\n (dbg (+ min1-pos 1) min2-pos)\n (heap-push (list* (dst-query min-table #'min (+ min1-pos 1) (- min2-pos 1))\n (+ min1-pos 1) min2-pos)\n que))\n (when (< (+ min2-pos 1) r)\n (assert (evenp (- r (+ min2-pos 1))))\n (dbg (+ min2-pos 1) r)\n (heap-push (list* (dst-query min-table #'min (+ min2-pos 1) (- r 1))\n (+ min2-pos 1) r)\n que)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (format t \"~{~D~^ ~}~%\" (reverse 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\n3 2 4 1\n\"\n \"3 1 2 4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n\"\n \"1 2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n4 6 3 2 8 5 7 1\n\"\n \"3 1 2 7 4 6 8 5\n\")))\n", "language": "Lisp", "metadata": {"date": 1587617888, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03641.html", "problem_id": "p03641", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03641/input.txt", "sample_output_relpath": "derived/input_output/data/p03641/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03641/Lisp/s561767989.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s561767989", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3 1 2 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#-swank (disable-debugger) ; for CS Academy\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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;;;\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;;;\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 (declare ((simple-array uint32 (*)) vector))\n (let* ((n (length vector))\n (height (max 1 (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 &optional identity)\n \"Queries the interval [LEFT, RIGHT). Returns IDENTITY for a null interval [x,\nx).\"\n (declare ((integer 0 #.most-positive-fixnum) left right)\n ((simple-array * (* *)) table))\n (when (>= left right)\n (assert (= left right))\n (return-from dst-query identity))\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 dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(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;; min l . r\n(define-binary-heap heap\n :order (lambda (node1 node2)\n (< (the fixnum (car node1))\n (the fixnum (car node2))))\n :element-type list)\n\n(defconstant +inf+ #xffffffff)\n\n(defun main ()\n (let* ((n (read))\n (ps (make-array n :element-type 'uint32 :initial-element 0))\n (invs (make-array n :element-type 'uint32 :initial-element 0))\n (odd-ps (make-array n :element-type 'uint32 :initial-element 0))\n (even-ps (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (let ((p (- (read-fixnum) 1)))\n (setf (aref ps i) p\n (aref invs p) i\n (aref even-ps i) (if (evenp i) p +inf+)\n (aref odd-ps i) (if (oddp i) p +inf+))))\n (let ((odd-table (make-disjoint-sparse-table odd-ps #'min))\n (even-table (make-disjoint-sparse-table even-ps #'min))\n (min-table (make-disjoint-sparse-table ps #'min))\n (que (make-heap n))\n res)\n #>invs\n (heap-push (list* (dst-query even-table #'min 0 (- n 1)) 0 n) que)\n (loop until (heap-empty-p que)\n for (min1 l . r) = (heap-pop que)\n for min1-pos = (aref invs min1)\n for min2 = (if (evenp min1-pos)\n (dst-query odd-table #'min (+ 1 min1-pos) r)\n (dst-query even-table #'min (+ 1 min1-pos) r))\n for min2-pos = (aref invs min2)\n do (push (+ min1 1) res)\n (push (+ min2 1) res)\n (dbg l r min1 min1-pos min2 min2-pos)\n (assert (and (<= l min1-pos)\n (< min1-pos min2-pos)\n (< min2-pos r)))\n (when (< l min1-pos)\n (assert (evenp (- min1-pos l)))\n (dbg l min1-pos)\n (heap-push (list* (dst-query min-table #'min l (- min1-pos 1))\n l min1-pos)\n que))\n (when (< (+ min1-pos 1) min2-pos)\n (assert (evenp (- min2-pos (+ min1-pos 1))))\n (dbg (+ min1-pos 1) min2-pos)\n (heap-push (list* (dst-query min-table #'min (+ min1-pos 1) (- min2-pos 1))\n (+ min1-pos 1) min2-pos)\n que))\n (when (< (+ min2-pos 1) r)\n (assert (evenp (- r (+ min2-pos 1))))\n (dbg (+ min2-pos 1) r)\n (heap-push (list* (dst-query min-table #'min (+ min2-pos 1) (- r 1))\n (+ min2-pos 1) r)\n que)))\n (write-string\n (with-output-to-string (*standard-output* nil :element-type 'base-char)\n (format t \"~{~D~^ ~}~%\" (reverse 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\n3 2 4 1\n\"\n \"3 1 2 4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2\n1 2\n\"\n \"1 2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n4 6 3 2 8 5 7 1\n\"\n \"3 1 2 7 4 6 8 5\n\")))\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nLet N be a positive even number.\n\nWe have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N).\nSnuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below.\n\nFirst, let q be an empty sequence.\nThen, perform the following operation until p becomes empty:\n\nSelect two adjacent elements in p, and call them x and y in order. Remove x and y from p (reducing the length of p by 2), and insert x and y, preserving the original order, at the beginning of q.\n\nWhen p becomes empty, q will be a permutation of (1, 2, ..., N).\n\nFind the lexicographically smallest permutation that can be obtained as q.\n\nConstraints\n\nN is an even number.\n\n2 ≤ N ≤ 2 × 10^5\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 lexicographically smallest permutation, with spaces in between.\n\nSample Input 1\n\n4\n3 2 4 1\n\nSample Output 1\n\n3 1 2 4\n\nThe solution above is obtained as follows:\n\np\n\nq\n\n(3, 2, 4, 1)\n\n()\n\n↓\n\n↓\n\n(3, 1)\n\n(2, 4)\n\n↓\n\n↓\n\n()\n\n(3, 1, 2, 4)\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n1 2\n\nSample Input 3\n\n8\n4 6 3 2 8 5 7 1\n\nSample Output 3\n\n3 1 2 7 4 6 8 5\n\nThe solution above is obtained as follows:\n\np\n\nq\n\n(4, 6, 3, 2, 8, 5, 7, 1)\n\n()\n\n↓\n\n↓\n\n(4, 6, 3, 2, 7, 1)\n\n(8, 5)\n\n↓\n\n↓\n\n(3, 2, 7, 1)\n\n(4, 6, 8, 5)\n\n↓\n\n↓\n\n(3, 1)\n\n(2, 7, 4, 6, 8, 5)\n\n↓\n\n↓\n\n()\n\n(3, 1, 2, 7, 4, 6, 8, 5)", "sample_input": "4\n3 2 4 1\n"}, "reference_outputs": ["3 1 2 4\n"], "source_document_id": "p03641", "source_text": "Score : 800 points\n\nProblem Statement\n\nLet N be a positive even number.\n\nWe have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N).\nSnuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below.\n\nFirst, let q be an empty sequence.\nThen, perform the following operation until p becomes empty:\n\nSelect two adjacent elements in p, and call them x and y in order. Remove x and y from p (reducing the length of p by 2), and insert x and y, preserving the original order, at the beginning of q.\n\nWhen p becomes empty, q will be a permutation of (1, 2, ..., N).\n\nFind the lexicographically smallest permutation that can be obtained as q.\n\nConstraints\n\nN is an even number.\n\n2 ≤ N ≤ 2 × 10^5\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 lexicographically smallest permutation, with spaces in between.\n\nSample Input 1\n\n4\n3 2 4 1\n\nSample Output 1\n\n3 1 2 4\n\nThe solution above is obtained as follows:\n\np\n\nq\n\n(3, 2, 4, 1)\n\n()\n\n↓\n\n↓\n\n(3, 1)\n\n(2, 4)\n\n↓\n\n↓\n\n()\n\n(3, 1, 2, 4)\n\nSample Input 2\n\n2\n1 2\n\nSample Output 2\n\n1 2\n\nSample Input 3\n\n8\n4 6 3 2 8 5 7 1\n\nSample Output 3\n\n3 1 2 7 4 6 8 5\n\nThe solution above is obtained as follows:\n\np\n\nq\n\n(4, 6, 3, 2, 8, 5, 7, 1)\n\n()\n\n↓\n\n↓\n\n(4, 6, 3, 2, 7, 1)\n\n(8, 5)\n\n↓\n\n↓\n\n(3, 2, 7, 1)\n\n(4, 6, 8, 5)\n\n↓\n\n↓\n\n(3, 1)\n\n(2, 7, 4, 6, 8, 5)\n\n↓\n\n↓\n\n()\n\n(3, 1, 2, 7, 4, 6, 8, 5)", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 15746, "cpu_time_ms": 541, "memory_kb": 90084}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s745890439", "group_id": "codeNet:p03643", "input_text": "(format t \"~A~%\"\n (concatenate 'string \"ABC\" (read-line)))\n", "language": "Lisp", "metadata": {"date": 1595026126, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03643.html", "problem_id": "p03643", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03643/input.txt", "sample_output_relpath": "derived/input_output/data/p03643/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03643/Lisp/s745890439.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s745890439", "user_id": "u336541610"}, "prompt_components": {"gold_output": "ABC100\n", "input_to_evaluate": "(format t \"~A~%\"\n (concatenate 'string \"ABC\" (read-line)))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThis contest, AtCoder Beginner Contest, is abbreviated as ABC.\n\nWhen we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.\n\nWhat is the abbreviation for the N-th round of ABC? Write a program to output the answer.\n\nConstraints\n\n100 ≤ N ≤ 999\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the abbreviation for the N-th round of ABC.\n\nSample Input 1\n\n100\n\nSample Output 1\n\nABC100\n\nThe 100th round of ABC is ABC100.\n\nSample Input 2\n\n425\n\nSample Output 2\n\nABC425\n\nSample Input 3\n\n999\n\nSample Output 3\n\nABC999", "sample_input": "100\n"}, "reference_outputs": ["ABC100\n"], "source_document_id": "p03643", "source_text": "Score : 100 points\n\nProblem Statement\n\nThis contest, AtCoder Beginner Contest, is abbreviated as ABC.\n\nWhen we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.\n\nWhat is the abbreviation for the N-th round of ABC? Write a program to output the answer.\n\nConstraints\n\n100 ≤ N ≤ 999\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the abbreviation for the N-th round of ABC.\n\nSample Input 1\n\n100\n\nSample Output 1\n\nABC100\n\nThe 100th round of ABC is ABC100.\n\nSample Input 2\n\n425\n\nSample Output 2\n\nABC425\n\nSample Input 3\n\n999\n\nSample Output 3\n\nABC999", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 24348}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s816359220", "group_id": "codeNet:p03643", "input_text": "(defvar in)\n\n(setq in (read))\n\n(print (concatenate 'string \"ABC\" (princ-to-string in)))", "language": "Lisp", "metadata": {"date": 1501620035, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03643.html", "problem_id": "p03643", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03643/input.txt", "sample_output_relpath": "derived/input_output/data/p03643/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03643/Lisp/s816359220.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s816359220", "user_id": "u681734201"}, "prompt_components": {"gold_output": "ABC100\n", "input_to_evaluate": "(defvar in)\n\n(setq in (read))\n\n(print (concatenate 'string \"ABC\" (princ-to-string in)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThis contest, AtCoder Beginner Contest, is abbreviated as ABC.\n\nWhen we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.\n\nWhat is the abbreviation for the N-th round of ABC? Write a program to output the answer.\n\nConstraints\n\n100 ≤ N ≤ 999\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the abbreviation for the N-th round of ABC.\n\nSample Input 1\n\n100\n\nSample Output 1\n\nABC100\n\nThe 100th round of ABC is ABC100.\n\nSample Input 2\n\n425\n\nSample Output 2\n\nABC425\n\nSample Input 3\n\n999\n\nSample Output 3\n\nABC999", "sample_input": "100\n"}, "reference_outputs": ["ABC100\n"], "source_document_id": "p03643", "source_text": "Score : 100 points\n\nProblem Statement\n\nThis contest, AtCoder Beginner Contest, is abbreviated as ABC.\n\nWhen we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.\n\nWhat is the abbreviation for the N-th round of ABC? Write a program to output the answer.\n\nConstraints\n\n100 ≤ N ≤ 999\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the abbreviation for the N-th round of ABC.\n\nSample Input 1\n\n100\n\nSample Output 1\n\nABC100\n\nThe 100th round of ABC is ABC100.\n\nSample Input 2\n\n425\n\nSample Output 2\n\nABC425\n\nSample Input 3\n\n999\n\nSample Output 3\n\nABC999", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 6, "memory_kb": 2920}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s214645110", "group_id": "codeNet:p03643", "input_text": "(setq in (input))\n(print (concatenate '\"ABC\" in))", "language": "Lisp", "metadata": {"date": 1501619772, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03643.html", "problem_id": "p03643", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03643/input.txt", "sample_output_relpath": "derived/input_output/data/p03643/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03643/Lisp/s214645110.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s214645110", "user_id": "u681734201"}, "prompt_components": {"gold_output": "ABC100\n", "input_to_evaluate": "(setq in (input))\n(print (concatenate '\"ABC\" in))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nThis contest, AtCoder Beginner Contest, is abbreviated as ABC.\n\nWhen we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.\n\nWhat is the abbreviation for the N-th round of ABC? Write a program to output the answer.\n\nConstraints\n\n100 ≤ N ≤ 999\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the abbreviation for the N-th round of ABC.\n\nSample Input 1\n\n100\n\nSample Output 1\n\nABC100\n\nThe 100th round of ABC is ABC100.\n\nSample Input 2\n\n425\n\nSample Output 2\n\nABC425\n\nSample Input 3\n\n999\n\nSample Output 3\n\nABC999", "sample_input": "100\n"}, "reference_outputs": ["ABC100\n"], "source_document_id": "p03643", "source_text": "Score : 100 points\n\nProblem Statement\n\nThis contest, AtCoder Beginner Contest, is abbreviated as ABC.\n\nWhen we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.\n\nWhat is the abbreviation for the N-th round of ABC? Write a program to output the answer.\n\nConstraints\n\n100 ≤ N ≤ 999\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the abbreviation for the N-th round of ABC.\n\nSample Input 1\n\n100\n\nSample Output 1\n\nABC100\n\nThe 100th round of ABC is ABC100.\n\nSample Input 2\n\n425\n\nSample Output 2\n\nABC425\n\nSample Input 3\n\n999\n\nSample Output 3\n\nABC999", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 11, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s333564215", "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) 1) (= (aref arr 1 k) 1)))\n (princ \"IMPOSSIBLE\")\n (princ \"POSSIBLE\")))", "language": "Lisp", "metadata": {"date": 1573281082, "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/s333564215.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s333564215", "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) 1) (= (aref arr 1 k) 1)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 473, "cpu_time_ms": 770, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s041857686", "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": 1573280955, "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/s041857686.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s041857686", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 770, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s490223663", "group_id": "codeNet:p03645", "input_text": "(let* ((a (read))\n (b (read))\n (lst (loop :repeat b :collect (cons (read) (read))))\n (a1 nil)\n (a2 nil))\n (setf a1 (remove 1 lst :test-not #'= :key #'car))\n (setf a2 (remove a lst :test-not #'= :key #'cdr))\n (if (loop :for x :in a1 :never (find (car x) a2 :key #'cdr))\n (princ \"POSSIBLE\")\n (princ \"INPOSSIBLE\")))\n", "language": "Lisp", "metadata": {"date": 1545018853, "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/s490223663.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s490223663", "user_id": "u610490393"}, "prompt_components": {"gold_output": "POSSIBLE\n", "input_to_evaluate": "(let* ((a (read))\n (b (read))\n (lst (loop :repeat b :collect (cons (read) (read))))\n (a1 nil)\n (a2 nil))\n (setf a1 (remove 1 lst :test-not #'= :key #'car))\n (setf a2 (remove a lst :test-not #'= :key #'cdr))\n (if (loop :for x :in a1 :never (find (car x) a2 :key #'cdr))\n (princ \"POSSIBLE\")\n (princ \"INPOSSIBLE\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2105, "memory_kb": 63816}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s536471681", "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 (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 (find-if (lambda (x)\n (find-if (lambda (y)\n (= x y))\n nn))\n n1)\n 'POSSIBLE\n 'IMPOSSIBLE)))", "language": "Lisp", "metadata": {"date": 1504281300, "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/s536471681.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s536471681", "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 (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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 887, "cpu_time_ms": 2105, "memory_kb": 64232}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s274129925", "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 #>indices\n #>marked\n #>table\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 (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 (* 2 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": 1563317686, "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/s274129925.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s274129925", "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 #>indices\n #>marked\n #>table\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 (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 (* 2 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4035, "cpu_time_ms": 233, "memory_kb": 26596}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s026711757", "group_id": "codeNet:p03653", "input_text": "(let ((xyz (make-array 3)))\n (dotimes (i 3)\n (setf (aref xyz i) (read)))\n (let* ((n (+ (aref xyz 0) (aref xyz 1) (aref xyz 2)))\n (data (make-array (* n 3)))\n (gots (make-array n :initial-element t))\n (total 0))\n (dotimes (i n)\n (setf (aref data (* i 3)) (list (read) i 0)\n (aref data (+ 1 (* i 3))) (list (read) i 1)\n (aref data (+ 2 (* i 3))) (list (read) i 2)))\n (setf data (sort (copy-seq data) #'> :key #'first))\n (loop for i from 0 below (* n 3)\n for (v row col) = (aref data i)\n with cnts = (make-array 3 :initial-element 0)\n with flags = (make-array 3 :initial-element t)\n until (every #'null flags) do\n (if (and (aref gots row)\n (aref flags col))\n (setf (aref gots row) nil\n total (+ total v)\n (aref cnts col) (1+ (aref cnts col))))\n (if (= (aref cnts col) (aref xyz col))\n (setf (aref flags col) nil)))\n (format t \"~A~%\" total)))", "language": "Lisp", "metadata": {"date": 1512579509, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03653.html", "problem_id": "p03653", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03653/input.txt", "sample_output_relpath": "derived/input_output/data/p03653/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03653/Lisp/s026711757.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s026711757", "user_id": "u275710783"}, "prompt_components": {"gold_output": "18\n", "input_to_evaluate": "(let ((xyz (make-array 3)))\n (dotimes (i 3)\n (setf (aref xyz i) (read)))\n (let* ((n (+ (aref xyz 0) (aref xyz 1) (aref xyz 2)))\n (data (make-array (* n 3)))\n (gots (make-array n :initial-element t))\n (total 0))\n (dotimes (i n)\n (setf (aref data (* i 3)) (list (read) i 0)\n (aref data (+ 1 (* i 3))) (list (read) i 1)\n (aref data (+ 2 (* i 3))) (list (read) i 2)))\n (setf data (sort (copy-seq data) #'> :key #'first))\n (loop for i from 0 below (* n 3)\n for (v row col) = (aref data i)\n with cnts = (make-array 3 :initial-element 0)\n with flags = (make-array 3 :initial-element t)\n until (every #'null flags) do\n (if (and (aref gots row)\n (aref flags col))\n (setf (aref gots row) nil\n total (+ total v)\n (aref cnts col) (1+ (aref cnts col))))\n (if (= (aref cnts col) (aref xyz col))\n (setf (aref flags col) nil)))\n (format t \"~A~%\" total)))", "problem_context": "Score : 800 points\n\nProblem Statement\n\nThere are X+Y+Z people, conveniently numbered 1 through X+Y+Z.\nPerson i has A_i gold coins, B_i silver coins and C_i bronze coins.\n\nSnuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people.\nIt is not possible to get two or more different colors of coins from a single person.\nOn the other hand, a person will give all of his/her coins of the color specified by Snuke.\n\nSnuke would like to maximize the total number of coins of all colors he gets.\nFind the maximum possible number of coins.\n\nConstraints\n\n1 \\leq X\n\n1 \\leq Y\n\n1 \\leq Z\n\nX+Y+Z \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\n1 \\leq B_i \\leq 10^9\n\n1 \\leq C_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y Z\nA_1 B_1 C_1\nA_2 B_2 C_2\n:\nA_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}\n\nOutput\n\nPrint the maximum possible total number of coins of all colors he gets.\n\nSample Input 1\n\n1 2 1\n2 4 4\n3 2 1\n7 6 7\n5 2 3\n\nSample Output 1\n\n18\n\nGet silver coins from Person 1, silver coins from Person 2, bronze coins from Person 3 and gold coins from Person 4.\nIn this case, the total number of coins will be 4+2+7+5=18.\nIt is not possible to get 19 or more coins, and the answer is therefore 18.\n\nSample Input 2\n\n3 3 2\n16 17 1\n2 7 5\n2 16 12\n17 7 7\n13 2 10\n12 18 3\n16 15 19\n5 6 2\n\nSample Output 2\n\n110\n\nSample Input 3\n\n6 2 4\n33189 87907 277349742\n71616 46764 575306520\n8801 53151 327161251\n58589 4337 796697686\n66854 17565 289910583\n50598 35195 478112689\n13919 88414 103962455\n7953 69657 699253752\n44255 98144 468443709\n2332 42580 752437097\n39752 19060 845062869\n60126 74101 382963164\n\nSample Output 3\n\n3093929975", "sample_input": "1 2 1\n2 4 4\n3 2 1\n7 6 7\n5 2 3\n"}, "reference_outputs": ["18\n"], "source_document_id": "p03653", "source_text": "Score : 800 points\n\nProblem Statement\n\nThere are X+Y+Z people, conveniently numbered 1 through X+Y+Z.\nPerson i has A_i gold coins, B_i silver coins and C_i bronze coins.\n\nSnuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people.\nIt is not possible to get two or more different colors of coins from a single person.\nOn the other hand, a person will give all of his/her coins of the color specified by Snuke.\n\nSnuke would like to maximize the total number of coins of all colors he gets.\nFind the maximum possible number of coins.\n\nConstraints\n\n1 \\leq X\n\n1 \\leq Y\n\n1 \\leq Z\n\nX+Y+Z \\leq 10^5\n\n1 \\leq A_i \\leq 10^9\n\n1 \\leq B_i \\leq 10^9\n\n1 \\leq C_i \\leq 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nX Y Z\nA_1 B_1 C_1\nA_2 B_2 C_2\n:\nA_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z}\n\nOutput\n\nPrint the maximum possible total number of coins of all colors he gets.\n\nSample Input 1\n\n1 2 1\n2 4 4\n3 2 1\n7 6 7\n5 2 3\n\nSample Output 1\n\n18\n\nGet silver coins from Person 1, silver coins from Person 2, bronze coins from Person 3 and gold coins from Person 4.\nIn this case, the total number of coins will be 4+2+7+5=18.\nIt is not possible to get 19 or more coins, and the answer is therefore 18.\n\nSample Input 2\n\n3 3 2\n16 17 1\n2 7 5\n2 16 12\n17 7 7\n13 2 10\n12 18 3\n16 15 19\n5 6 2\n\nSample Output 2\n\n110\n\nSample Input 3\n\n6 2 4\n33189 87907 277349742\n71616 46764 575306520\n8801 53151 327161251\n58589 4337 796697686\n66854 17565 289910583\n50598 35195 478112689\n13919 88414 103962455\n7953 69657 699253752\n44255 98144 468443709\n2332 42580 752437097\n39752 19060 845062869\n60126 74101 382963164\n\nSample Output 3\n\n3093929975", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 1217, "memory_kb": 78280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s130005181", "group_id": "codeNet:p03659", "input_text": "(let* ((n (read))\n (a (make-array n :element-type 'integer))\n (x 0)\n (y 0)\n (res 0))\n (dotimes (i n)\n (setf (aref a i) (read)))\n (setf x (aref a 0)\n y (loop for i from 1 below n sum (aref a i))\n res (abs (- x y)))\n (loop for i from 1 below (1- n)\n for ai = (aref a i) do\n (incf x ai)\n (decf y ai)\n (setf res (min res (abs (- x y)))))\n (format t \"~A~%\" res))", "language": "Lisp", "metadata": {"date": 1512349456, "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/s130005181.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s130005181", "user_id": "u275710783"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let* ((n (read))\n (a (make-array n :element-type 'integer))\n (x 0)\n (y 0)\n (res 0))\n (dotimes (i n)\n (setf (aref a i) (read)))\n (setf x (aref a 0)\n y (loop for i from 1 below n sum (aref a i))\n res (abs (- x y)))\n (loop for i from 1 below (1- n)\n for ai = (aref a i) do\n (incf x ai)\n (decf y ai)\n (setf res (min res (abs (- x y)))))\n (format t \"~A~%\" res))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 430, "cpu_time_ms": 403, "memory_kb": 59752}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s625999456", "group_id": "codeNet:p03672", "input_text": "(let* ((s (reverse (cdr (reverse (concatenate 'list (read-line))))))\n (len (length s)))\n\n (defun f (l)\n (let ((lst1 (subseq l 0 (truncate (length l) 2)))\n (lst2 (subseq l (truncate (length l) 2))))\n\n (if (equal lst1 lst2)\n (length l)\n (f (reverse (cdr (reverse l)))))))\n\n (format t \"~A~%\"\n (f s)))\n\n", "language": "Lisp", "metadata": {"date": 1595022876, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s625999456.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s625999456", "user_id": "u336541610"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let* ((s (reverse (cdr (reverse (concatenate 'list (read-line))))))\n (len (length s)))\n\n (defun f (l)\n (let ((lst1 (subseq l 0 (truncate (length l) 2)))\n (lst2 (subseq l (truncate (length l) 2))))\n\n (if (equal lst1 lst2)\n (length l)\n (f (reverse (cdr (reverse l)))))))\n\n (format t \"~A~%\"\n (f s)))\n\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 347, "cpu_time_ms": 17, "memory_kb": 25020}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s192820830", "group_id": "codeNet:p03673", "input_text": ";;; Utils\n\n \n#+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 (princ obj stream) (terpri stream))))\n\n(in-package :cl-user)\n\n(defmethod fast-sort ((sequence list) &optional (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) &optional (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(defmethod princ-for-each-line ((sequence list))\n (labels ((inner (sequence)\n (if (null sequence)\n (fresh-line)\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 (fresh-line))\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;; deque\n\n(defparameter *default-deque-size* 100)\n\n(defstruct deque\n (data nil)\n (size nil)\n (head 0)\n (tail 0)\n (count 0))\n\n\n(defun deque-create (&optional (size *default-deque-size*))\n (make-deque\n :size size\n :data (make-array size)))\n\n\n\n(defmethod deque-clear ((d deque))\n (fill (deque-data d) 0)\n (setf (deque-size d) 0)\n (setf (deque-head d) 0)\n (setf (deque-tail d) 0)\n (setf (deque-count d) 0))\n\n;; Subcommand\n\n(declaim (inline deque-empty-p\n deque-full-p\n deque-get-prev-index\n deque-get-next-index))\n\n\n(defmethod deque-empty-p ((d deque))\n (zerop (deque-count d)))\n\n\n\n(defmethod deque-full-p ((d deque))\n (= (deque-count d) (deque-size d)))\n\n(defmethod deque-get-prev-index ((d deque) idx)\n (declare (inline deque-get-next-index))\n (if (zerop idx)\n (1- (deque-size d))\n (1- idx)))\n\n(defmethod deque-get-next-index ((d deque) idx)\n (rem (1+ idx) (deque-size d)))\n\n\n\n(defmethod deque-pushfront ((d deque) item)\n (when (deque-full-p d)\n (error \"deque is full\"))\n\n (setf (deque-head d) (deque-get-prev-index d (deque-head d)))\n (setf (aref (deque-data d) (deque-head d)) item)\n (when (deque-empty-p d) ; first insersion\n (setf (deque-tail d) (deque-head d)))\n (incf (deque-count d)))\n\n\n\n(defmethod deque-pushback ((d deque) item)\n (when (deque-full-p d)\n (error \"deque is full\"))\n \n (setf (deque-tail d) (deque-get-next-index d (deque-tail d)))\n (setf (aref (deque-data d) (deque-tail d)) item)\n (when (deque-empty-p d) ; first insersion\n (setf (deque-head d) (deque-tail d)))\n (incf (deque-count d)))\n\n\n(defmethod deque-popfront ((d deque))\n (when (deque-empty-p d)\n (error \"deque is empty,\"))\n \n (let ((value (aref (deque-data d) (deque-head d))))\n (setf (deque-head d) (deque-get-next-index d (deque-head d)))\n (decf (deque-count d))\n value))\n\n\n\n(defmethod deque-popback ((d deque))\n (when (deque-empty-p d)\n (error \"deque is empty,\"))\n \n (let ((value (aref (deque-data d) (deque-tail d))))\n (setf (deque-tail d) (deque-get-prev-index d (deque-tail d)))\n (decf (deque-count d))\n value))\n\n\n(defmethod dref ((d deque) subscripts)\n (let ((arr (deque-data d))\n (size (deque-size d))\n (head (deque-head d)))\n (aref arr (mod (+ subscripts\n head)\n size))))\n\n;;; Write code here\n\n\n\n(defun main ()\n (let* ((n (read))\n (a (read-numbers-to-array n))\n (d (deque-create n)))\n (loop for i below n do\n (if (evenp i)\n (deque-pushback d (aref a i))\n (deque-pushfront d (aref a i))))\n (with-buffered-stdout\n (if (evenp n)\n (dotimes (i n)\n (format t \"~a \" (deque-popfront d)))\n (dotimes (i n)\n (format t \"~a \" (deque-popback d))))\n (terpri))\n (assert (deque-empty-p d))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1599070491, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s192820830.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s192820830", "user_id": "u425762225"}, "prompt_components": {"gold_output": "4 2 1 3\n", "input_to_evaluate": ";;; Utils\n\n \n#+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 (princ obj stream) (terpri stream))))\n\n(in-package :cl-user)\n\n(defmethod fast-sort ((sequence list) &optional (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) &optional (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(defmethod princ-for-each-line ((sequence list))\n (labels ((inner (sequence)\n (if (null sequence)\n (fresh-line)\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 (fresh-line))\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;; deque\n\n(defparameter *default-deque-size* 100)\n\n(defstruct deque\n (data nil)\n (size nil)\n (head 0)\n (tail 0)\n (count 0))\n\n\n(defun deque-create (&optional (size *default-deque-size*))\n (make-deque\n :size size\n :data (make-array size)))\n\n\n\n(defmethod deque-clear ((d deque))\n (fill (deque-data d) 0)\n (setf (deque-size d) 0)\n (setf (deque-head d) 0)\n (setf (deque-tail d) 0)\n (setf (deque-count d) 0))\n\n;; Subcommand\n\n(declaim (inline deque-empty-p\n deque-full-p\n deque-get-prev-index\n deque-get-next-index))\n\n\n(defmethod deque-empty-p ((d deque))\n (zerop (deque-count d)))\n\n\n\n(defmethod deque-full-p ((d deque))\n (= (deque-count d) (deque-size d)))\n\n(defmethod deque-get-prev-index ((d deque) idx)\n (declare (inline deque-get-next-index))\n (if (zerop idx)\n (1- (deque-size d))\n (1- idx)))\n\n(defmethod deque-get-next-index ((d deque) idx)\n (rem (1+ idx) (deque-size d)))\n\n\n\n(defmethod deque-pushfront ((d deque) item)\n (when (deque-full-p d)\n (error \"deque is full\"))\n\n (setf (deque-head d) (deque-get-prev-index d (deque-head d)))\n (setf (aref (deque-data d) (deque-head d)) item)\n (when (deque-empty-p d) ; first insersion\n (setf (deque-tail d) (deque-head d)))\n (incf (deque-count d)))\n\n\n\n(defmethod deque-pushback ((d deque) item)\n (when (deque-full-p d)\n (error \"deque is full\"))\n \n (setf (deque-tail d) (deque-get-next-index d (deque-tail d)))\n (setf (aref (deque-data d) (deque-tail d)) item)\n (when (deque-empty-p d) ; first insersion\n (setf (deque-head d) (deque-tail d)))\n (incf (deque-count d)))\n\n\n(defmethod deque-popfront ((d deque))\n (when (deque-empty-p d)\n (error \"deque is empty,\"))\n \n (let ((value (aref (deque-data d) (deque-head d))))\n (setf (deque-head d) (deque-get-next-index d (deque-head d)))\n (decf (deque-count d))\n value))\n\n\n\n(defmethod deque-popback ((d deque))\n (when (deque-empty-p d)\n (error \"deque is empty,\"))\n \n (let ((value (aref (deque-data d) (deque-tail d))))\n (setf (deque-tail d) (deque-get-prev-index d (deque-tail d)))\n (decf (deque-count d))\n value))\n\n\n(defmethod dref ((d deque) subscripts)\n (let ((arr (deque-data d))\n (size (deque-size d))\n (head (deque-head d)))\n (aref arr (mod (+ subscripts\n head)\n size))))\n\n;;; Write code here\n\n\n\n(defun main ()\n (let* ((n (read))\n (a (read-numbers-to-array n))\n (d (deque-create n)))\n (loop for i below n do\n (if (evenp i)\n (deque-pushback d (aref a i))\n (deque-pushfront d (aref a i))))\n (with-buffered-stdout\n (if (evenp n)\n (dotimes (i n)\n (format t \"~a \" (deque-popfront d)))\n (dotimes (i n)\n (format t \"~a \" (deque-popback d))))\n (terpri))\n (assert (deque-empty-p d))))\n\n(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": "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5955, "cpu_time_ms": 338, "memory_kb": 83736}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s827894485", "group_id": "codeNet:p03673", "input_text": ";;; Utils (quoted from https://competitive12.blogspot.com/2020/03/common-lisp.html)\n\n\n;; Read fixnum\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;; fast read-line\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\n;;; invoke child process\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; Write code here\n;-------------------\n\n\n\n(defun solve (n a)\n (let ((ans (make-array n)))\n (cond\n ((= n 1) a)\n ((oddp n)\n (let ((k (floor n 2)))\n ; n = 2k + 1\n (setf (aref ans k) (aref a 0))\n (dotimes (i k)\n (setf (aref ans (+ k (1+ i))) (aref a (+ (* i 2) 1)))\n (setf (aref ans (- k (1+ i))) (aref a (+ (* i 2) 2))))\n ans))\n ((evenp n)\n (let ((k (floor n 2)))\n (dotimes (i k)\n (setf (aref ans (+ k i)) (aref a (* i 2)))\n (setf (aref ans (- k (1+ i))) (aref a (1+ (* i 2)))))\n ans)))))\n\n(defun main ()\n (let* ((n (read))\n (a (make-array n :initial-contents (read-from-string (concatenate 'string \"(\" (read-line) \")\")))))\n (setq ans (solve n a))\n (dotimes (i n)\n (format t \"~a \" (aref ans i)))\n (fresh-line)))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1596204046, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s827894485.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s827894485", "user_id": "u425762225"}, "prompt_components": {"gold_output": "4 2 1 3\n", "input_to_evaluate": ";;; Utils (quoted from https://competitive12.blogspot.com/2020/03/common-lisp.html)\n\n\n;; Read fixnum\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;; fast read-line\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\n;;; invoke child process\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; Write code here\n;-------------------\n\n\n\n(defun solve (n a)\n (let ((ans (make-array n)))\n (cond\n ((= n 1) a)\n ((oddp n)\n (let ((k (floor n 2)))\n ; n = 2k + 1\n (setf (aref ans k) (aref a 0))\n (dotimes (i k)\n (setf (aref ans (+ k (1+ i))) (aref a (+ (* i 2) 1)))\n (setf (aref ans (- k (1+ i))) (aref a (+ (* i 2) 2))))\n ans))\n ((evenp n)\n (let ((k (floor n 2)))\n (dotimes (i k)\n (setf (aref ans (+ k i)) (aref a (* i 2)))\n (setf (aref ans (- k (1+ i))) (aref a (1+ (* i 2)))))\n ans)))))\n\n(defun main ()\n (let* ((n (read))\n (a (make-array n :initial-contents (read-from-string (concatenate 'string \"(\" (read-line) \")\")))))\n (setq ans (solve n a))\n (dotimes (i n)\n (format t \"~a \" (aref ans i)))\n (fresh-line)))\n\n(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": "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3519, "cpu_time_ms": 291, "memory_kb": 60152}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s944573632", "group_id": "codeNet:p03674", "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;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\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(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 (declare #.OPT)\n (let* ((n (read))\n (mem (make-array (+ n 1) :element-type 'int32 :initial-element -1))\n (l 0)\n (r 0))\n (declare (uint32 n))\n (dotimes (i (+ n 1))\n (let ((a (read-fixnum)))\n (if (= -1 (aref mem a))\n (setf (aref mem a) i)\n (setf l (aref mem a)\n r i))))\n (with-output-buffer\n (loop for k from 1 to (+ n 1)\n do (println (mod (- (binom (+ n 1) k)\n (binom (+ l (- n r)) (- k 1)))\n +mod+))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558474880, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03674.html", "problem_id": "p03674", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03674/input.txt", "sample_output_relpath": "derived/input_output/data/p03674/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03674/Lisp/s944573632.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s944573632", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n5\n4\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 (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;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\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(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 (declare #.OPT)\n (let* ((n (read))\n (mem (make-array (+ n 1) :element-type 'int32 :initial-element -1))\n (l 0)\n (r 0))\n (declare (uint32 n))\n (dotimes (i (+ n 1))\n (let ((a (read-fixnum)))\n (if (= -1 (aref mem a))\n (setf (aref mem a) i)\n (setf l (aref mem a)\n r i))))\n (with-output-buffer\n (loop for k from 1 to (+ n 1)\n do (println (mod (- (binom (+ n 1) k)\n (binom (+ l (- n r)) (- k 1)))\n +mod+))))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n.\nIt is known that each of the n integers 1,...,n appears at least once in this sequence.\n\nFor each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.\n\nNotes\n\nIf the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.\n\nA subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.\n\nConstraints\n\n1 \\leq n \\leq 10^5\n\n1 \\leq a_i \\leq n\n\nEach of the integers 1,...,n appears in the sequence.\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+1}\n\nOutput\n\nPrint n+1 lines.\nThe k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 10^9+7.\n\nSample Input 1\n\n3\n1 2 1 3\n\nSample Output 1\n\n3\n5\n4\n1\n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\nSample Input 2\n\n1\n1 1\n\nSample Output 2\n\n1\n1\n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\nSample Input 3\n\n32\n29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9\n\nSample Output 3\n\n32\n525\n5453\n40919\n237336\n1107568\n4272048\n13884156\n38567100\n92561040\n193536720\n354817320\n573166440\n818809200\n37158313\n166803103\n166803103\n37158313\n818809200\n573166440\n354817320\n193536720\n92561040\n38567100\n13884156\n4272048\n1107568\n237336\n40920\n5456\n528\n33\n1\n\nBe sure to print the numbers modulo 10^9+7.", "sample_input": "3\n1 2 1 3\n"}, "reference_outputs": ["3\n5\n4\n1\n"], "source_document_id": "p03674", "source_text": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n.\nIt is known that each of the n integers 1,...,n appears at least once in this sequence.\n\nFor each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.\n\nNotes\n\nIf the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.\n\nA subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.\n\nConstraints\n\n1 \\leq n \\leq 10^5\n\n1 \\leq a_i \\leq n\n\nEach of the integers 1,...,n appears in the sequence.\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+1}\n\nOutput\n\nPrint n+1 lines.\nThe k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 10^9+7.\n\nSample Input 1\n\n3\n1 2 1 3\n\nSample Output 1\n\n3\n5\n4\n1\n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\nSample Input 2\n\n1\n1 1\n\nSample Output 2\n\n1\n1\n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\nSample Input 3\n\n32\n29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9\n\nSample Output 3\n\n32\n525\n5453\n40919\n237336\n1107568\n4272048\n13884156\n38567100\n92561040\n193536720\n354817320\n573166440\n818809200\n37158313\n166803103\n166803103\n37158313\n818809200\n573166440\n354817320\n193536720\n92561040\n38567100\n13884156\n4272048\n1107568\n237336\n40920\n5456\n528\n33\n1\n\nBe sure to print the numbers modulo 10^9+7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5252, "cpu_time_ms": 178, "memory_kb": 26212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s286147172", "group_id": "codeNet:p03674", "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;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\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(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 (declare #.OPT)\n (let* ((n (read))\n (mem (make-array (+ n 1) :element-type 'int32 :initial-element -1))\n (l 0)\n (r 0))\n (declare (uint32 n))\n (dotimes (i (+ n 1))\n (let ((a (read-fixnum)))\n (if (= -1 (aref mem a))\n (setf (aref mem a) i)\n (setf l (aref mem a)\n r i))))\n (with-output-buffer\n (loop for k from 1 to (+ n 1)\n do (println (mod (+ (binom (- n 1) k)\n (- (* 2 (binom (- n 1) (- k 1)))\n (binom (+ l (- n r)) (- k 1)))\n (binom (- n 1) (- k 2)))\n +mod+))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558474759, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03674.html", "problem_id": "p03674", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03674/input.txt", "sample_output_relpath": "derived/input_output/data/p03674/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03674/Lisp/s286147172.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s286147172", "user_id": "u352600849"}, "prompt_components": {"gold_output": "3\n5\n4\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 (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;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\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(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 (declare #.OPT)\n (let* ((n (read))\n (mem (make-array (+ n 1) :element-type 'int32 :initial-element -1))\n (l 0)\n (r 0))\n (declare (uint32 n))\n (dotimes (i (+ n 1))\n (let ((a (read-fixnum)))\n (if (= -1 (aref mem a))\n (setf (aref mem a) i)\n (setf l (aref mem a)\n r i))))\n (with-output-buffer\n (loop for k from 1 to (+ n 1)\n do (println (mod (+ (binom (- n 1) k)\n (- (* 2 (binom (- n 1) (- k 1)))\n (binom (+ l (- n r)) (- k 1)))\n (binom (- n 1) (- k 2)))\n +mod+))))))\n\n#-swank(main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n.\nIt is known that each of the n integers 1,...,n appears at least once in this sequence.\n\nFor each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.\n\nNotes\n\nIf the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.\n\nA subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.\n\nConstraints\n\n1 \\leq n \\leq 10^5\n\n1 \\leq a_i \\leq n\n\nEach of the integers 1,...,n appears in the sequence.\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+1}\n\nOutput\n\nPrint n+1 lines.\nThe k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 10^9+7.\n\nSample Input 1\n\n3\n1 2 1 3\n\nSample Output 1\n\n3\n5\n4\n1\n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\nSample Input 2\n\n1\n1 1\n\nSample Output 2\n\n1\n1\n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\nSample Input 3\n\n32\n29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9\n\nSample Output 3\n\n32\n525\n5453\n40919\n237336\n1107568\n4272048\n13884156\n38567100\n92561040\n193536720\n354817320\n573166440\n818809200\n37158313\n166803103\n166803103\n37158313\n818809200\n573166440\n354817320\n193536720\n92561040\n38567100\n13884156\n4272048\n1107568\n237336\n40920\n5456\n528\n33\n1\n\nBe sure to print the numbers modulo 10^9+7.", "sample_input": "3\n1 2 1 3\n"}, "reference_outputs": ["3\n5\n4\n1\n"], "source_document_id": "p03674", "source_text": "Score : 600 points\n\nProblem Statement\n\nYou are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n.\nIt is known that each of the n integers 1,...,n appears at least once in this sequence.\n\nFor each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.\n\nNotes\n\nIf the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.\n\nA subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.\n\nConstraints\n\n1 \\leq n \\leq 10^5\n\n1 \\leq a_i \\leq n\n\nEach of the integers 1,...,n appears in the sequence.\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+1}\n\nOutput\n\nPrint n+1 lines.\nThe k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 10^9+7.\n\nSample Input 1\n\n3\n1 2 1 3\n\nSample Output 1\n\n3\n5\n4\n1\n\nThere are three subsequences with length 1: 1 and 2 and 3.\n\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.\n\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.\n\nThere is one subsequence with length 4: 1,2,1,3.\n\nSample Input 2\n\n1\n1 1\n\nSample Output 2\n\n1\n1\n\nThere is one subsequence with length 1: 1.\n\nThere is one subsequence with length 2: 1,1.\n\nSample Input 3\n\n32\n29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9\n\nSample Output 3\n\n32\n525\n5453\n40919\n237336\n1107568\n4272048\n13884156\n38567100\n92561040\n193536720\n354817320\n573166440\n818809200\n37158313\n166803103\n166803103\n37158313\n818809200\n573166440\n354817320\n193536720\n92561040\n38567100\n13884156\n4272048\n1107568\n237336\n40920\n5456\n528\n33\n1\n\nBe sure to print the numbers modulo 10^9+7.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5377, "cpu_time_ms": 192, "memory_kb": 28136}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s128224424", "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": 1595695763, "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/s128224424.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s128224424", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 23436}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s558824652", "group_id": "codeNet:p03680", "input_text": "(let* ((n (read))\n (vec (concatenate 'vector (loop repeat n\n collect (read)))))\n\n (defun f (v &optional (pos 0) (cnt 0))\n (if (> cnt n)\n -1\n (if (= pos 1)\n cnt\n (f v (1- (aref v pos)) (1+ cnt)))))\n\n (format t \"~A~%\"\n (f vec)))\n", "language": "Lisp", "metadata": {"date": 1595020594, "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/s558824652.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s558824652", "user_id": "u336541610"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let* ((n (read))\n (vec (concatenate 'vector (loop repeat n\n collect (read)))))\n\n (defun f (v &optional (pos 0) (cnt 0))\n (if (> cnt n)\n -1\n (if (= pos 1)\n cnt\n (f v (1- (aref v pos)) (1+ cnt)))))\n\n (format t \"~A~%\"\n (f vec)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 309, "cpu_time_ms": 124, "memory_kb": 78464}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s262071200", "group_id": "codeNet:p03681", "input_text": "(declaim (optimize (sped 3) (debug 0) (safety 0)))\n\n(defun fact (n)\n (loop for a = 1 then (mod (* a i) 1000000007)\n for i from 2 to n\n finally (return a)))\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": 1504557526, "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/s262071200.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s262071200", "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 (loop for a = 1 then (mod (* a i) 1000000007)\n for i from 2 to n\n finally (return a)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 553, "cpu_time_ms": 66, "memory_kb": 9828}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s096686536", "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 ;; (cost from to)\n (edges (make-array (* 2 (- n 1)) :element-type '(cons uint32 (cons uint32 uint32)))))\n (loop for j of-type uint32 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 (setf (aref edges (+ j j))\n (list (min (abs (- x2 x1)) (abs (- y2 y1))) city1 city2))))\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 (setf (aref edges (+ j j 1))\n (list (min (abs (- x2 x1)) (abs (- y2 y1))) city1 city2))))\n finally (setf edges (stable-sort edges #'< :key #'first)))\n (let ((tree (make-union-find n))\n (cost-sum 0))\n (dotimes (i (length edges))\n (destructuring-bind (cost from to) (aref edges i)\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": 1547538825, "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/s096686536.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s096686536", "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 ;; (cost from to)\n (edges (make-array (* 2 (- n 1)) :element-type '(cons uint32 (cons uint32 uint32)))))\n (loop for j of-type uint32 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 (setf (aref edges (+ j j))\n (list (min (abs (- x2 x1)) (abs (- y2 y1))) city1 city2))))\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 (setf (aref edges (+ j j 1))\n (list (min (abs (- x2 x1)) (abs (- y2 y1))) city1 city2))))\n finally (setf edges (stable-sort edges #'< :key #'first)))\n (let ((tree (make-union-find n))\n (cost-sum 0))\n (dotimes (i (length edges))\n (destructuring-bind (cost from to) (aref edges i)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5858, "cpu_time_ms": 422, "memory_kb": 41700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s551101174", "group_id": "codeNet:p03685", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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* ((r (read))\n (c (read))\n (n (read))\n queries)\n (declare (uint31 r c n))\n (labels ((on-edge-p (y x)\n (or (zerop y) (zerop x)\n (= y r) (= x c)))\n (render (y x)\n (cond ((zerop y) x)\n ((= x c) (+ c y))\n ((= y r) (+ c r (- c x)))\n (t (+ c r c (- r y))))))\n (dotimes (i n)\n (let ((y1 (read-fixnum))\n (x1 (read-fixnum))\n (y2 (read-fixnum))\n (x2 (read-fixnum)))\n (declare (uint31 y1 x1 y2 x2))\n (when (and (on-edge-p y1 x1)\n (on-edge-p y2 x2))\n (let ((pos1 (render y1 x1))\n (pos2 (render y2 x2)))\n (when (> pos1 pos2) (rotatef pos1 pos2))\n (push (list* pos1 i :add) queries)\n (push (list* pos2 i :delete) queries)))))\n (setq queries (sort queries #'< :key (lambda (x) (the fixnum (car x))))))\n (let (stack)\n (loop for (_ idx . op) in queries\n do (cond ((eq op :add)\n (push idx stack))\n ((= (car stack) idx)\n (pop stack))\n (t\n (write-line \"NO\")\n (return-from main))))\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 \"4 2 3\n0 1 3 1\n1 1 4 1\n2 0 2 2\n\"\n \"YES\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 2 4\n0 0 2 2\n2 0 0 1\n0 2 1 2\n1 1 2 1\n\"\n \"NO\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5 7\n0 0 2 4\n2 3 4 5\n3 5 5 2\n5 5 5 4\n0 3 5 1\n2 2 4 4\n0 5 4 1\n\"\n \"YES\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1 2\n0 0 1 1\n1 0 0 1\n\"\n \"NO\n\")))\n", "language": "Lisp", "metadata": {"date": 1584767920, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03685.html", "problem_id": "p03685", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03685/input.txt", "sample_output_relpath": "derived/input_output/data/p03685/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03685/Lisp/s551101174.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s551101174", "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 ;; 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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* ((r (read))\n (c (read))\n (n (read))\n queries)\n (declare (uint31 r c n))\n (labels ((on-edge-p (y x)\n (or (zerop y) (zerop x)\n (= y r) (= x c)))\n (render (y x)\n (cond ((zerop y) x)\n ((= x c) (+ c y))\n ((= y r) (+ c r (- c x)))\n (t (+ c r c (- r y))))))\n (dotimes (i n)\n (let ((y1 (read-fixnum))\n (x1 (read-fixnum))\n (y2 (read-fixnum))\n (x2 (read-fixnum)))\n (declare (uint31 y1 x1 y2 x2))\n (when (and (on-edge-p y1 x1)\n (on-edge-p y2 x2))\n (let ((pos1 (render y1 x1))\n (pos2 (render y2 x2)))\n (when (> pos1 pos2) (rotatef pos1 pos2))\n (push (list* pos1 i :add) queries)\n (push (list* pos2 i :delete) queries)))))\n (setq queries (sort queries #'< :key (lambda (x) (the fixnum (car x))))))\n (let (stack)\n (loop for (_ idx . op) in queries\n do (cond ((eq op :add)\n (push idx stack))\n ((= (car stack) idx)\n (pop stack))\n (t\n (write-line \"NO\")\n (return-from main))))\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 \"4 2 3\n0 1 3 1\n1 1 4 1\n2 0 2 2\n\"\n \"YES\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"2 2 4\n0 0 2 2\n2 0 0 1\n0 2 1 2\n1 1 2 1\n\"\n \"NO\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 5 7\n0 0 2 4\n2 3 4 5\n3 5 5 2\n5 5 5 4\n0 3 5 1\n2 2 4 4\n0 5 4 1\n\"\n \"YES\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1 1 2\n0 0 1 1\n1 0 0 1\n\"\n \"NO\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nSnuke is playing a puzzle game.\nIn this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).\n\nThe objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N.\nHere, the curves may not go outside the board or cross each other.\n\nDetermine whether this is possible.\n\nConstraints\n\n1 ≤ R,C ≤ 10^8\n\n1 ≤ N ≤ 10^5\n\n0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)\n\n0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)\n\nAll given points are distinct.\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR C N\nx_{1,1} y_{1,1} x_{1,2} y_{1,2}\n:\nx_{N,1} y_{N,1} x_{N,2} y_{N,2}\n\nOutput\n\nPrint YES if the objective is achievable; print NO otherwise.\n\nSample Input 1\n\n4 2 3\n0 1 3 1\n1 1 4 1\n2 0 2 2\n\nSample Output 1\n\nYES\n\nThe above figure shows a possible solution.\n\nSample Input 2\n\n2 2 4\n0 0 2 2\n2 0 0 1\n0 2 1 2\n1 1 2 1\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n5 5 7\n0 0 2 4\n2 3 4 5\n3 5 5 2\n5 5 5 4\n0 3 5 1\n2 2 4 4\n0 5 4 1\n\nSample Output 3\n\nYES\n\nSample Input 4\n\n1 1 2\n0 0 1 1\n1 0 0 1\n\nSample Output 4\n\nNO", "sample_input": "4 2 3\n0 1 3 1\n1 1 4 1\n2 0 2 2\n"}, "reference_outputs": ["YES\n"], "source_document_id": "p03685", "source_text": "Score : 700 points\n\nProblem Statement\n\nSnuke is playing a puzzle game.\nIn this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}).\n\nThe objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N.\nHere, the curves may not go outside the board or cross each other.\n\nDetermine whether this is possible.\n\nConstraints\n\n1 ≤ R,C ≤ 10^8\n\n1 ≤ N ≤ 10^5\n\n0 ≤ x_{i,1},x_{i,2} ≤ R(1 ≤ i ≤ N)\n\n0 ≤ y_{i,1},y_{i,2} ≤ C(1 ≤ i ≤ N)\n\nAll given points are distinct.\n\nAll input values are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nR C N\nx_{1,1} y_{1,1} x_{1,2} y_{1,2}\n:\nx_{N,1} y_{N,1} x_{N,2} y_{N,2}\n\nOutput\n\nPrint YES if the objective is achievable; print NO otherwise.\n\nSample Input 1\n\n4 2 3\n0 1 3 1\n1 1 4 1\n2 0 2 2\n\nSample Output 1\n\nYES\n\nThe above figure shows a possible solution.\n\nSample Input 2\n\n2 2 4\n0 0 2 2\n2 0 0 1\n0 2 1 2\n1 1 2 1\n\nSample Output 2\n\nNO\n\nSample Input 3\n\n5 5 7\n0 0 2 4\n2 3 4 5\n3 5 5 2\n5 5 5 4\n0 3 5 1\n2 2 4 4\n0 5 4 1\n\nSample Output 3\n\nYES\n\nSample Input 4\n\n1 1 2\n0 0 1 1\n1 0 0 1\n\nSample Output 4\n\nNO", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6390, "cpu_time_ms": 503, "memory_kb": 50024}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s834593515", "group_id": "codeNet:p03687", "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(defun main ()\n (let* ((s (read-line))\n (n (length s)))\n (labels ((calc-cost (c)\n (let ((res 0)\n (prev 0))\n (loop\n (let ((next (or (position c s :start prev) n)))\n (maxf res (- next prev))\n (when (= next n)\n (return res))\n (setq prev (+ next 1)))))))\n (println\n (loop for c across \"abcdefghijklmnopqrstuvwxyz\"\n minimize (calc-cost c))))))\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 \"serval\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"jackal\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"zzz\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"whbrjpjyhsrywlqjxdbrbaomnw\n\"\n \"8\n\")))\n", "language": "Lisp", "metadata": {"date": 1578040043, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03687.html", "problem_id": "p03687", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03687/input.txt", "sample_output_relpath": "derived/input_output/data/p03687/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03687/Lisp/s834593515.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s834593515", "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 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* ((s (read-line))\n (n (length s)))\n (labels ((calc-cost (c)\n (let ((res 0)\n (prev 0))\n (loop\n (let ((next (or (position c s :start prev) n)))\n (maxf res (- next prev))\n (when (= next n)\n (return res))\n (setq prev (+ next 1)))))))\n (println\n (loop for c across \"abcdefghijklmnopqrstuvwxyz\"\n minimize (calc-cost c))))))\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 \"serval\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"jackal\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"zzz\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"whbrjpjyhsrywlqjxdbrbaomnw\n\"\n \"8\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nSnuke can change a string t of length N into a string t' of length N - 1 under the following rule:\n\nFor each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.\n\nThere is a string s consisting of lowercase English letters.\nSnuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same.\nFind the minimum necessary number of operations.\n\nConstraints\n\n1 ≤ |s| ≤ 100\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 necessary number of operations to achieve the objective.\n\nSample Input 1\n\nserval\n\nSample Output 1\n\n3\n\nOne solution is: serval → srvvl → svvv → vvv.\n\nSample Input 2\n\njackal\n\nSample Output 2\n\n2\n\nOne solution is: jackal → aacaa → aaaa.\n\nSample Input 3\n\nzzz\n\nSample Output 3\n\n0\n\nAll the characters in s are the same from the beginning.\n\nSample Input 4\n\nwhbrjpjyhsrywlqjxdbrbaomnw\n\nSample Output 4\n\n8\n\nIn 8 operations, he can change s to rrrrrrrrrrrrrrrrrr.", "sample_input": "serval\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03687", "source_text": "Score : 300 points\n\nProblem Statement\n\nSnuke can change a string t of length N into a string t' of length N - 1 under the following rule:\n\nFor each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.\n\nThere is a string s consisting of lowercase English letters.\nSnuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same.\nFind the minimum necessary number of operations.\n\nConstraints\n\n1 ≤ |s| ≤ 100\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 necessary number of operations to achieve the objective.\n\nSample Input 1\n\nserval\n\nSample Output 1\n\n3\n\nOne solution is: serval → srvvl → svvv → vvv.\n\nSample Input 2\n\njackal\n\nSample Output 2\n\n2\n\nOne solution is: jackal → aacaa → aaaa.\n\nSample Input 3\n\nzzz\n\nSample Output 3\n\n0\n\nAll the characters in s are the same from the beginning.\n\nSample Input 4\n\nwhbrjpjyhsrywlqjxdbrbaomnw\n\nSample Output 4\n\n8\n\nIn 8 operations, he can change s to rrrrrrrrrrrrrrrrrr.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4560, "cpu_time_ms": 72, "memory_kb": 14176}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s512592615", "group_id": "codeNet:p03694", "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(let* ((n (read)) (l (loop for i from 1 to n collect (read))))\n (princ (- (reduce #'max l) (reduce #'min l))))\n", "language": "Lisp", "metadata": {"date": 1578009105, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03694.html", "problem_id": "p03694", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03694/input.txt", "sample_output_relpath": "derived/input_output/data/p03694/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03694/Lisp/s512592615.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s512592615", "user_id": "u493610446"}, "prompt_components": {"gold_output": "7\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(let* ((n (read)) (l (loop for i from 1 to n collect (read))))\n (princ (- (reduce #'max l) (reduce #'min l))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIt is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.\n\nThere are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.\n\nFind the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.\n\nConstraints\n\n1 ≤ N ≤ 100\n\n0 ≤ a_i ≤ 1000\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 distance to be traveled.\n\nSample Input 1\n\n4\n2 3 7 9\n\nSample Output 1\n\n7\n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2.\n\nIt is not possible to do with a travel distance of less than 7, and thus 7 is the minimum distance to be traveled.\n\nSample Input 2\n\n8\n3 1 4 1 5 9 2 6\n\nSample Output 2\n\n8\n\nThere may be more than one house at a position.", "sample_input": "4\n2 3 7 9\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03694", "source_text": "Score : 200 points\n\nProblem Statement\n\nIt is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.\n\nThere are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.\n\nFind the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.\n\nConstraints\n\n1 ≤ N ≤ 100\n\n0 ≤ a_i ≤ 1000\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 distance to be traveled.\n\nSample Input 1\n\n4\n2 3 7 9\n\nSample Output 1\n\n7\n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2.\n\nIt is not possible to do with a travel distance of less than 7, and thus 7 is the minimum distance to be traveled.\n\nSample Input 2\n\n8\n3 1 4 1 5 9 2 6\n\nSample Output 2\n\n8\n\nThere may be more than one house at a position.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 17, "memory_kb": 6328}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s082250621", "group_id": "codeNet:p03694", "input_text": "(defun solver (&aux (max 0) (min 1001) temp)\n (let ((n (read)))\n (loop repeat n do\n (setf temp (read))\n (when (> temp max) (setf max temp))\n (when (< temp min) (setf min temp)))\n (format t \"~A~%\" (- max min))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1497143938, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03694.html", "problem_id": "p03694", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03694/input.txt", "sample_output_relpath": "derived/input_output/data/p03694/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03694/Lisp/s082250621.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s082250621", "user_id": "u183015556"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(defun solver (&aux (max 0) (min 1001) temp)\n (let ((n (read)))\n (loop repeat n do\n (setf temp (read))\n (when (> temp max) (setf max temp))\n (when (< temp min) (setf min temp)))\n (format t \"~A~%\" (- max min))))\n\n(solver)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nIt is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.\n\nThere are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.\n\nFind the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.\n\nConstraints\n\n1 ≤ N ≤ 100\n\n0 ≤ a_i ≤ 1000\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 distance to be traveled.\n\nSample Input 1\n\n4\n2 3 7 9\n\nSample Output 1\n\n7\n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2.\n\nIt is not possible to do with a travel distance of less than 7, and thus 7 is the minimum distance to be traveled.\n\nSample Input 2\n\n8\n3 1 4 1 5 9 2 6\n\nSample Output 2\n\n8\n\nThere may be more than one house at a position.", "sample_input": "4\n2 3 7 9\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03694", "source_text": "Score : 200 points\n\nProblem Statement\n\nIt is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.\n\nThere are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.\n\nFind the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.\n\nConstraints\n\n1 ≤ N ≤ 100\n\n0 ≤ a_i ≤ 1000\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 distance to be traveled.\n\nSample Input 1\n\n4\n2 3 7 9\n\nSample Output 1\n\n7\n\nThe travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2.\n\nIt is not possible to do with a travel distance of less than 7, and thus 7 is the minimum distance to be traveled.\n\nSample Input 2\n\n8\n3 1 4 1 5 9 2 6\n\nSample Output 2\n\n8\n\nThere may be more than one house at a position.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 240, "memory_kb": 13668}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s058783268", "group_id": "codeNet:p03695", "input_text": "(let ((n (read))\n (other 0)\n (ans 0))\n (defparameter *hash* (make-hash-table))\n\n (loop for i below n do\n (case (floor (/ (read) 400))\n (0 (setf (gethash 'hai *hash*) 1))\n (1 (setf (gethash 'cha *hash*) 1))\n (2 (setf (gethash 'midori *hash*) 1))\n (3 (setf (gethash 'mizu *hash*) 1))\n (4 (setf (gethash 'ao *hash*) 1))\n (5 (setf (gethash 'ki *hash*) 1))\n (6 (setf (gethash 'daidai *hash*) 1))\n (7 (setf (gethash 'aka *hash*) 1))\n ((8 9 10 11 12) (incf other))\n )\n )\n (maphash #'(lambda (key value)\n (if (= value 1)\n (incf ans)\n )\n )\n *hash*)\n\n (if (= ans 0)\n (format t \"1\")\n (format t \"~D\" ans)\n )\n\n (incf ans other)\n (if (<= 8 ans)\n (format t \" 8~%\")\n (format t \" ~D~%\" ans)\n )\n)", "language": "Lisp", "metadata": {"date": 1595899944, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s058783268.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s058783268", "user_id": "u136500538"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(let ((n (read))\n (other 0)\n (ans 0))\n (defparameter *hash* (make-hash-table))\n\n (loop for i below n do\n (case (floor (/ (read) 400))\n (0 (setf (gethash 'hai *hash*) 1))\n (1 (setf (gethash 'cha *hash*) 1))\n (2 (setf (gethash 'midori *hash*) 1))\n (3 (setf (gethash 'mizu *hash*) 1))\n (4 (setf (gethash 'ao *hash*) 1))\n (5 (setf (gethash 'ki *hash*) 1))\n (6 (setf (gethash 'daidai *hash*) 1))\n (7 (setf (gethash 'aka *hash*) 1))\n ((8 9 10 11 12) (incf other))\n )\n )\n (maphash #'(lambda (key value)\n (if (= value 1)\n (incf ans)\n )\n )\n *hash*)\n\n (if (= ans 0)\n (format t \"1\")\n (format t \"~D\" ans)\n )\n\n (incf ans other)\n (if (<= 8 ans)\n (format t \" 8~%\")\n (format t \" ~D~%\" ans)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 899, "cpu_time_ms": 17, "memory_kb": 24780}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s750934538", "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 (if (<= (+ ln over3200) 8)\n (+ ln over3200)\n 8))))\n", "language": "Lisp", "metadata": {"date": 1586412913, "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/s750934538.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s750934538", "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 (if (<= (+ ln over3200) 8)\n (+ ln over3200)\n 8))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1040, "cpu_time_ms": 145, "memory_kb": 16104}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s580177929", "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 (format t \"~A ~A\" ln (+ ln over3200)))\n\n", "language": "Lisp", "metadata": {"date": 1586412612, "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/s580177929.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s580177929", "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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 879, "cpu_time_ms": 133, "memory_kb": 16100}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s712378559", "group_id": "codeNet:p03695", "input_text": "(let* ((a (read))\n (li (loop :repeat a collect (read)))\n (hi 0))\n (map-into li (lambda (n)\n (case (floor n 400)\n (1 1)\n (2 2)\n (3 3)\n (4 4)\n (5 5)\n (6 6)\n (7 7)\n (otherwise (setq hi (1+ hi))))) li)\n (setf li (remove-duplicates li))\n (format t \"~A ~A\" (if (< (length li) hi)\n hi (length li)) (+ (length li) hi)))", "language": "Lisp", "metadata": {"date": 1542396310, "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/s712378559.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s712378559", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(let* ((a (read))\n (li (loop :repeat a collect (read)))\n (hi 0))\n (map-into li (lambda (n)\n (case (floor n 400)\n (1 1)\n (2 2)\n (3 3)\n (4 4)\n (5 5)\n (6 6)\n (7 7)\n (otherwise (setq hi (1+ hi))))) li)\n (setf li (remove-duplicates li))\n (format t \"~A ~A\" (if (< (length li) hi)\n hi (length li)) (+ (length li) hi)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 142, "memory_kb": 16224}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s737183131", "group_id": "codeNet:p03695", "input_text": "(defvar +rate+\n '((399 . \"gray\")\n (799 . \"brown\")\n (1199 . \"green\")\n (1599 . \"cyan\")\n (1999 . \"blue\")\n (2399 . \"yellow\")\n (2799 . \"orange\")\n (3199 . \"red\")))\n\n(defun select-color (point)\n (loop for (rate . color) in +rate+\n when (<= point rate)\n return color))\n\n(let ((n (read))\n (a (make-hash-table))\n (any 0))\n (dotimes (i n)\n (let ((color (select-color (read))))\n (if color\n (setf (gethash color a)\n (1+ (gethash color a 0)))\n (incf any))))\n (let* ((count (loop for key being each hash-key of a\n using (hash-value value)\n count (< 0 value)))\n (mini (max count))\n (maxi (min (+ count any) 8)))\n (format t \"~A ~A~%\" mini maxi)))", "language": "Lisp", "metadata": {"date": 1511891768, "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/s737183131.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s737183131", "user_id": "u275710783"}, "prompt_components": {"gold_output": "2 2\n", "input_to_evaluate": "(defvar +rate+\n '((399 . \"gray\")\n (799 . \"brown\")\n (1199 . \"green\")\n (1599 . \"cyan\")\n (1999 . \"blue\")\n (2399 . \"yellow\")\n (2799 . \"orange\")\n (3199 . \"red\")))\n\n(defun select-color (point)\n (loop for (rate . color) in +rate+\n when (<= point rate)\n return color))\n\n(let ((n (read))\n (a (make-hash-table))\n (any 0))\n (dotimes (i n)\n (let ((color (select-color (read))))\n (if color\n (setf (gethash color a)\n (1+ (gethash color a 0)))\n (incf any))))\n (let* ((count (loop for key being each hash-key of a\n using (hash-value value)\n count (< 0 value)))\n (mini (max count))\n (maxi (min (+ count any) 8)))\n (format t \"~A ~A~%\" mini maxi)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 780, "cpu_time_ms": 205, "memory_kb": 16612}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s623359755", "group_id": "codeNet:p03697", "input_text": "(format t \"~A~%\" (let ((a (+ (read) (read))))\n (if (>= a 10)\n \"error\"\n a)))", "language": "Lisp", "metadata": {"date": 1504741320, "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/s623359755.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s623359755", "user_id": "u140665374"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(format t \"~A~%\" (let ((a (+ (read) (read))))\n (if (>= a 10)\n \"error\"\n a)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 11, "memory_kb": 3428}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s500532709", "group_id": "codeNet:p03698", "input_text": "(setq s(read-line))\n(setq f 0)\n(loop for i from 0 to (1-(length s))do\n\t (loop for j from (1+ i)to(1-(length s))do\n\t\t\t(if(char=(char s i)(char s j))(incf f))))\n(princ(if(> f 0)\"no\"\"yes\"))\n", "language": "Lisp", "metadata": {"date": 1534929753, "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/s500532709.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s500532709", "user_id": "u657913472"}, "prompt_components": {"gold_output": "yes\n", "input_to_evaluate": "(setq s(read-line))\n(setq f 0)\n(loop for i from 0 to (1-(length s))do\n\t (loop for j from (1+ i)to(1-(length s))do\n\t\t\t(if(char=(char s i)(char s j))(incf f))))\n(princ(if(> f 0)\"no\"\"yes\"))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 142, "memory_kb": 13156}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s307043541", "group_id": "codeNet:p03699", "input_text": "(defun sum (list)\n (reduce #'+ list :initial-value 0))\n\n(defun search-min (list)\n (let ((result (car list)))\n (dolist (i list)\n (if (and (< i result) (not (= 0 (mod i 10))))\n (setf result i)))\n (if (= 0 (mod result 10))\n (sum list)\n result)))\n\n(defun main ()\n (let ((times (read))\n (list nil))\n (dotimes (i times)\n (setf list (cons (read) list)))\n (format t \"~A~%\" (- (sum list) (search-min list)))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1497109218, "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/s307043541.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s307043541", "user_id": "u328322317"}, "prompt_components": {"gold_output": "25\n", "input_to_evaluate": "(defun sum (list)\n (reduce #'+ list :initial-value 0))\n\n(defun search-min (list)\n (let ((result (car list)))\n (dolist (i list)\n (if (and (< i result) (not (= 0 (mod i 10))))\n (setf result i)))\n (if (= 0 (mod result 10))\n (sum list)\n result)))\n\n(defun main ()\n (let ((times (read))\n (list nil))\n (dotimes (i times)\n (setf list (cons (read) list)))\n (format t \"~A~%\" (- (sum list) (search-min list)))))\n\n(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 31, "memory_kb": 7396}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s463145208", "group_id": "codeNet:p03701", "input_text": "(let* ((n (read))\n (s (make-array n))\n (ans 0)\n (herasu 0))\n (loop for i below n do\n (progn\n (setf (aref s i) (read))\n (incf ans (aref s i))\n )\n )\n (setf s (sort s #'<))\n (loop for i below n do\n (if (not (zerop (rem (aref s i) 10)))\n (progn\n (setf herasu (aref s i))\n (return)\n )\n )\n )\n (if (zerop (rem ans 10))\n (if (zerop herasu)\n (setq ans 0)\n (decf ans herasu)\n )\n )\n (format t \"~D~%\" ans)\n)", "language": "Lisp", "metadata": {"date": 1597263719, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03701.html", "problem_id": "p03701", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03701/input.txt", "sample_output_relpath": "derived/input_output/data/p03701/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03701/Lisp/s463145208.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s463145208", "user_id": "u136500538"}, "prompt_components": {"gold_output": "25\n", "input_to_evaluate": "(let* ((n (read))\n (s (make-array n))\n (ans 0)\n (herasu 0))\n (loop for i below n do\n (progn\n (setf (aref s i) (read))\n (incf ans (aref s i))\n )\n )\n (setf s (sort s #'<))\n (loop for i below n do\n (if (not (zerop (rem (aref s i) 10)))\n (progn\n (setf herasu (aref s i))\n (return)\n )\n )\n )\n (if (zerop (rem ans 10))\n (if (zerop herasu)\n (setq ans 0)\n (decf ans herasu)\n )\n )\n (format t \"~D~%\" ans)\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": "p03701", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 19, "memory_kb": 24556}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s887040814", "group_id": "codeNet:p03702", "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;; 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 main ()\n (declare #.OPT)\n (let* ((n (read))\n (a (read))\n (b (read))\n (delta (- a b))\n (hs (make-array 100000 :element-type 'uint32))\n (tmp-hs (make-array 100000 :element-type 'uint32)))\n (declare (uint31 delta a b n))\n (dotimes (i n) (setf (aref hs i) (read-fixnum)))\n (labels ((feasible-p (k)\n (declare (uint31 k))\n (let ((base (* k b)))\n (dotimes (i n) (setf (aref tmp-hs i) (max 0 (- (aref hs i) base))))\n (<= (loop for h across tmp-hs\n sum (ceiling h delta) of-type fixnum)\n k))))\n (let ((sup (ceiling (reduce #'max hs) b)))\n (nlet bisect ((ng 0) (ok sup))\n (declare (uint31 ng ok))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (ash (+ ok ng) -1)))\n (if (feasible-p mid)\n (bisect ng mid)\n (bisect mid ok)))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559984209, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03702.html", "problem_id": "p03702", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03702/input.txt", "sample_output_relpath": "derived/input_output/data/p03702/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03702/Lisp/s887040814.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s887040814", "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;; 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 main ()\n (declare #.OPT)\n (let* ((n (read))\n (a (read))\n (b (read))\n (delta (- a b))\n (hs (make-array 100000 :element-type 'uint32))\n (tmp-hs (make-array 100000 :element-type 'uint32)))\n (declare (uint31 delta a b n))\n (dotimes (i n) (setf (aref hs i) (read-fixnum)))\n (labels ((feasible-p (k)\n (declare (uint31 k))\n (let ((base (* k b)))\n (dotimes (i n) (setf (aref tmp-hs i) (max 0 (- (aref hs i) base))))\n (<= (loop for h across tmp-hs\n sum (ceiling h delta) of-type fixnum)\n k))))\n (let ((sup (ceiling (reduce #'max hs) b)))\n (nlet bisect ((ng 0) (ok sup))\n (declare (uint31 ng ok))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (ash (+ ok ng) -1)))\n (if (feasible-p mid)\n (bisect ng mid)\n (bisect mid ok)))))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.\n\nFortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:\n\nSelect an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.\n\nAt least how many explosions do you need to cause in order to vanish all the monsters?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 10^5\n\n1 ≤ B < A ≤ 10^9\n\n1 ≤ h_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\nh_1\nh_2\n:\nh_N\n\nOutput\n\nPrint the minimum number of explosions that needs to be caused in order to vanish all the monsters.\n\nSample Input 1\n\n4 5 3\n8\n7\n4\n2\n\nSample Output 1\n\n2\n\nYou can vanish all the monsters in two explosion, as follows:\n\nFirst, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n\nSecond, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\nSample Input 2\n\n2 10 4\n20\n20\n\nSample Output 2\n\n4\n\nYou need to cause two explosions centered at each monster, for a total of four.\n\nSample Input 3\n\n5 2 1\n900000000\n900000000\n1000000000\n1000000000\n1000000000\n\nSample Output 3\n\n800000000", "sample_input": "4 5 3\n8\n7\n4\n2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03702", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.\n\nFortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:\n\nSelect an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.\n\nAt least how many explosions do you need to cause in order to vanish all the monsters?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 10^5\n\n1 ≤ B < A ≤ 10^9\n\n1 ≤ h_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\nh_1\nh_2\n:\nh_N\n\nOutput\n\nPrint the minimum number of explosions that needs to be caused in order to vanish all the monsters.\n\nSample Input 1\n\n4 5 3\n8\n7\n4\n2\n\nSample Output 1\n\n2\n\nYou can vanish all the monsters in two explosion, as follows:\n\nFirst, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n\nSecond, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\nSample Input 2\n\n2 10 4\n20\n20\n\nSample Output 2\n\n4\n\nYou need to cause two explosions centered at each monster, for a total of four.\n\nSample Input 3\n\n5 2 1\n900000000\n900000000\n1000000000\n1000000000\n1000000000\n\nSample Output 3\n\n800000000", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3671, "cpu_time_ms": 109, "memory_kb": 13156}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s262304578", "group_id": "codeNet:p03702", "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;; 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 main ()\n (declare #.OPT)\n (let* ((n (read))\n (a (read))\n (b (read))\n (delta (- a b))\n (hs (make-array n :element-type 'uint32)))\n (declare (uint31 delta a b))\n (dotimes (i n) (setf (aref hs i) (read-fixnum)))\n (labels ((feasible-p (k)\n (declare (uint31 k))\n (let ((hs (copy-seq hs))\n (base (* k b)))\n (dotimes (i n) (setf (aref hs i) (max 0 (- (aref hs i) base))))\n (<= (the uint32\n (reduce #'+ hs\n :key (lambda (h) (ceiling (the uint31 h) delta))))\n k))))\n (let ((sup (ceiling (reduce #'max hs) b)))\n (nlet bisect ((ng 0) (ok sup))\n (declare (uint31 ng ok))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (ash (+ ok ng) -1)))\n (if (feasible-p mid)\n (bisect ng mid)\n (bisect mid ok)))))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1559983863, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03702.html", "problem_id": "p03702", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03702/input.txt", "sample_output_relpath": "derived/input_output/data/p03702/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03702/Lisp/s262304578.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s262304578", "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;; 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 main ()\n (declare #.OPT)\n (let* ((n (read))\n (a (read))\n (b (read))\n (delta (- a b))\n (hs (make-array n :element-type 'uint32)))\n (declare (uint31 delta a b))\n (dotimes (i n) (setf (aref hs i) (read-fixnum)))\n (labels ((feasible-p (k)\n (declare (uint31 k))\n (let ((hs (copy-seq hs))\n (base (* k b)))\n (dotimes (i n) (setf (aref hs i) (max 0 (- (aref hs i) base))))\n (<= (the uint32\n (reduce #'+ hs\n :key (lambda (h) (ceiling (the uint31 h) delta))))\n k))))\n (let ((sup (ceiling (reduce #'max hs) b)))\n (nlet bisect ((ng 0) (ok sup))\n (declare (uint31 ng ok))\n (if (<= (- ok ng) 1)\n (println ok)\n (let ((mid (ash (+ ok ng) -1)))\n (if (feasible-p mid)\n (bisect ng mid)\n (bisect mid ok)))))))))\n\n#-swank(main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.\n\nFortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:\n\nSelect an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.\n\nAt least how many explosions do you need to cause in order to vanish all the monsters?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 10^5\n\n1 ≤ B < A ≤ 10^9\n\n1 ≤ h_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\nh_1\nh_2\n:\nh_N\n\nOutput\n\nPrint the minimum number of explosions that needs to be caused in order to vanish all the monsters.\n\nSample Input 1\n\n4 5 3\n8\n7\n4\n2\n\nSample Output 1\n\n2\n\nYou can vanish all the monsters in two explosion, as follows:\n\nFirst, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n\nSecond, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\nSample Input 2\n\n2 10 4\n20\n20\n\nSample Output 2\n\n4\n\nYou need to cause two explosions centered at each monster, for a total of four.\n\nSample Input 3\n\n5 2 1\n900000000\n900000000\n1000000000\n1000000000\n1000000000\n\nSample Output 3\n\n800000000", "sample_input": "4 5 3\n8\n7\n4\n2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03702", "source_text": "Score : 400 points\n\nProblem Statement\n\nYou are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.\n\nFortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:\n\nSelect an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.\n\nAt least how many explosions do you need to cause in order to vanish all the monsters?\n\nConstraints\n\nAll input values are integers.\n\n1 ≤ N ≤ 10^5\n\n1 ≤ B < A ≤ 10^9\n\n1 ≤ h_i ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN A B\nh_1\nh_2\n:\nh_N\n\nOutput\n\nPrint the minimum number of explosions that needs to be caused in order to vanish all the monsters.\n\nSample Input 1\n\n4 5 3\n8\n7\n4\n2\n\nSample Output 1\n\n2\n\nYou can vanish all the monsters in two explosion, as follows:\n\nFirst, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n\nSecond, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\nSample Input 2\n\n2 10 4\n20\n20\n\nSample Output 2\n\n4\n\nYou need to cause two explosions centered at each monster, for a total of four.\n\nSample Input 3\n\n5 2 1\n900000000\n900000000\n1000000000\n1000000000\n1000000000\n\nSample Output 3\n\n800000000", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3687, "cpu_time_ms": 233, "memory_kb": 27112}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s397796233", "group_id": "codeNet:p03703", "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;;; 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 merge-to-vec1-p (<= (- r l) 8))\n (%calc-by-bubble-sort! vec1 predicate l r))\n (t\n (let ((mid (ash (+ l r) -1)))\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(defmacro %bench-sort (sort-func predicate size count &optional (sample 1))\n (let ((state (gensym))\n (vector (gensym))\n (idx (gensym)))\n `(let* ((,state (sb-ext:seed-random-state 0))\n (,vector (make-array ,size :element-type 'fixnum)))\n (declare (optimize (speed 3))\n ((simple-array fixnum (,size)) ,vector))\n (,@(if (= sample 1)\n `(galante:time-after-gc)\n `(galante:time-median ,sample))\n (loop repeat ,count\n do (dotimes (,idx ,size)\n (setf (aref ,vector ,idx) (random #xffffffff ,state)))\n sum (funcall ,sort-func ,vector ,predicate)\n of-type fixnum)))))\n\n(defun bench-sort ()\n (%bench-sort #'calc-inversion-number! #'< 1000000 20))\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": 1554446979, "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/s397796233.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s397796233", "user_id": "u352600849"}, "prompt_components": {"gold_output": "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 (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 merge-to-vec1-p (<= (- r l) 8))\n (%calc-by-bubble-sort! vec1 predicate l r))\n (t\n (let ((mid (ash (+ l r) -1)))\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(defmacro %bench-sort (sort-func predicate size count &optional (sample 1))\n (let ((state (gensym))\n (vector (gensym))\n (idx (gensym)))\n `(let* ((,state (sb-ext:seed-random-state 0))\n (,vector (make-array ,size :element-type 'fixnum)))\n (declare (optimize (speed 3))\n ((simple-array fixnum (,size)) ,vector))\n (,@(if (= sample 1)\n `(galante:time-after-gc)\n `(galante:time-median ,sample))\n (loop repeat ,count\n do (dotimes (,idx ,size)\n (setf (aref ,vector ,idx) (random #xffffffff ,state)))\n sum (funcall ,sort-func ,vector ,predicate)\n of-type fixnum)))))\n\n(defun bench-sort ()\n (%bench-sort #'calc-inversion-number! #'< 1000000 20))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7886, "cpu_time_ms": 93, "memory_kb": 15840}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s688982711", "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 (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(declaim (inline initialize-2dcumul))\n(defun initialize-2dcumul (cumul-table)\n (destructuring-bind (h+1 w+1) (array-dimensions cumul-table)\n (declare ((integer 0 #.most-positive-fixnum) h+1 w+1))\n (let ((h (- h+1 1))\n (w (- w+1 1)))\n (declare ((integer 0 #.most-positive-fixnum) h w))\n (dotimes (i h+1)\n (dotimes (j w)\n (incf (aref cumul-table i (+ j 1))\n (aref cumul-table i j))))\n (dotimes (j w+1)\n (dotimes (i h)\n (incf (aref cumul-table (+ i 1) j)\n (aref cumul-table i j)))))))\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 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 (declare #.OPT)\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 (dp-h (make-array (list (+ n 1) (+ m 1)) :element-type 'uint31 :initial-element 0))\n (dp-v (make-array (list (+ n 1) (+ m 1)) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n m q))\n (dotimes (i n)\n (dotimes (j m (read-schar))\n (when (char= #\\1 (read-schar))\n (setf (aref plan i j) 1))))\n (dotimes (i n)\n (dotimes (j m)\n (when (= 1 (aref plan i j))\n (incf (aref dp (+ i 1) (+ j 1)))\n (when (and (> j 0) (= 1 (aref plan i (- j 1))))\n (incf (aref dp-h (+ i 1) (+ j 1))))\n (when (and (> i 0) (= 1 (aref plan (- i 1) j)))\n (incf (aref dp-v (+ i 1) (+ j 1)))))))\n (initialize-2dcumul dp)\n (initialize-2dcumul dp-h)\n (initialize-2dcumul dp-v)\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 (- (get-2dcumul dp y1 x1 y2 x2)\n (get-2dcumul dp-h y1 (+ x1 1) y2 x2)\n (get-2dcumul dp-v (+ y1 1) x1 y2 x2)))))))))\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": 1589462472, "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/s688982711.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s688982711", "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 (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(declaim (inline initialize-2dcumul))\n(defun initialize-2dcumul (cumul-table)\n (destructuring-bind (h+1 w+1) (array-dimensions cumul-table)\n (declare ((integer 0 #.most-positive-fixnum) h+1 w+1))\n (let ((h (- h+1 1))\n (w (- w+1 1)))\n (declare ((integer 0 #.most-positive-fixnum) h w))\n (dotimes (i h+1)\n (dotimes (j w)\n (incf (aref cumul-table i (+ j 1))\n (aref cumul-table i j))))\n (dotimes (j w+1)\n (dotimes (i h)\n (incf (aref cumul-table (+ i 1) j)\n (aref cumul-table i j)))))))\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 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 (declare #.OPT)\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 (dp-h (make-array (list (+ n 1) (+ m 1)) :element-type 'uint31 :initial-element 0))\n (dp-v (make-array (list (+ n 1) (+ m 1)) :element-type 'uint31 :initial-element 0)))\n (declare (uint31 n m q))\n (dotimes (i n)\n (dotimes (j m (read-schar))\n (when (char= #\\1 (read-schar))\n (setf (aref plan i j) 1))))\n (dotimes (i n)\n (dotimes (j m)\n (when (= 1 (aref plan i j))\n (incf (aref dp (+ i 1) (+ j 1)))\n (when (and (> j 0) (= 1 (aref plan i (- j 1))))\n (incf (aref dp-h (+ i 1) (+ j 1))))\n (when (and (> i 0) (= 1 (aref plan (- i 1) j)))\n (incf (aref dp-v (+ i 1) (+ j 1)))))))\n (initialize-2dcumul dp)\n (initialize-2dcumul dp-h)\n (initialize-2dcumul dp-v)\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 (- (get-2dcumul dp y1 x1 y2 x2)\n (get-2dcumul dp-h y1 (+ x1 1) y2 x2)\n (get-2dcumul dp-v (+ y1 1) x1 y2 x2)))))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7569, "cpu_time_ms": 409, "memory_kb": 75856}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s034756742", "group_id": "codeNet:p03712", "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(defun print-# (w)\n (dotimes (i (+ w 2))\n\t(princ #\\#)))\n\n(let ((h (read)) (w (read)))\n (print-# w)\n (fresh-line)\n (dotimes (i h)\n\t(princ #\\#)\n\t(princ (read-line))\n\t(princ #\\#)\n\t(fresh-line))\n (print-# w)\n (fresh-line))\n", "language": "Lisp", "metadata": {"date": 1578007922, "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/s034756742.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s034756742", "user_id": "u493610446"}, "prompt_components": {"gold_output": "#####\n#abc#\n#arc#\n#####\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(defun print-# (w)\n (dotimes (i (+ w 2))\n\t(princ #\\#)))\n\n(let ((h (read)) (w (read)))\n (print-# w)\n (fresh-line)\n (dotimes (i h)\n\t(princ #\\#)\n\t(princ (read-line))\n\t(princ #\\#)\n\t(fresh-line))\n (print-# w)\n (fresh-line))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 607, "cpu_time_ms": 22, "memory_kb": 6584}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s894865312", "group_id": "codeNet:p03713", "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(defsolver prob-c (h w)\n (cond ((and (= h 2)\n\t (= w 2))\n\t (format t \"1\"))\n\t((or (= (mod h 3) 0)\n\t (= (mod w 3) 0))\n\t (format t \"0\"))\n\t(t\n\t (format t \"~a\" (+ h w)))))\n\n(prob-c)", "language": "Lisp", "metadata": {"date": 1495333298, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s894865312.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s894865312", "user_id": "u100932207"}, "prompt_components": {"gold_output": "0\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(defsolver prob-c (h w)\n (cond ((and (= h 2)\n\t (= w 2))\n\t (format t \"1\"))\n\t((or (= (mod h 3) 0)\n\t (= (mod w 3) 0))\n\t (format t \"0\"))\n\t(t\n\t (format t \"~a\" (+ h w)))))\n\n(prob-c)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 354, "cpu_time_ms": 181, "memory_kb": 16096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s461782065", "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(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;;;\n;;; Ford-Fulkerson\n;;;\n(deftype edge () '(cons (unsigned-byte 62) t))\n\n(declaim (inline %make-edge))\n(defun %make-edge (to &key (capacity 0) reversed)\n (declare ((unsigned-byte 31) to capacity)\n (values edge))\n (cons (+ capacity (ash to 31))\n reversed))\n\n(declaim (inline edge-reversed))\n(defun edge-reversed (edge)\n (cdr edge))\n\n(declaim (inline (setf edge-reversed)))\n(defun (setf edge-reversed) (new-value edge)\n (setf (cdr edge) new-value))\n\n(declaim (inline edge-capacity))\n(defun edge-capacity (edge)\n (logand (car edge) #.(- (expt 2 31) 1)))\n\n(declaim (inline (setf edge-capacity)))\n(defun (setf edge-capacity) (new-value edge)\n (declare ((unsigned-byte 31) new-value))\n (setf (car edge)\n (logior new-value (logand (car edge) #.(ash (- (expt 2 31) 1) 31)))))\n\n(declaim (inline edge-to))\n(defun edge-to (edge)\n (ash (the (unsigned-byte 62) (car edge)) -31))\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\n ((simple-array list (*)) graph))\n (let* ((dep (%make-edge to-idx :capacity capacity))\n (ret (%make-edge 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-capacity edge) 0))\n (let ((flow (%find-flow (edge-to edge)\n dest-idx\n graph\n (min max-flow (edge-capacity edge))\n checked)))\n (declare ((integer 0 #.most-positive-fixnum) flow))\n (unless (zerop flow)\n (decf (edge-capacity 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 define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (graph (make-array (* h w 2) :element-type 'list :initial-element nil))\n (start-i 0)\n (start-j 0)\n (goal-i 0)\n (goal-j 0))\n (declare (uint7 h w start-i start-j goal-i goal-j))\n (macrolet ((trans-coord (i j)\n `(* 2 (+ (* w ,i) ,j))))\n (dotimes (i h)\n (let ((line (buffered-read-line 100)))\n (dotimes (j w)\n (case (aref line j)\n (#\\o (setf (aref plan i j) 1)\n (let ((index (trans-coord i j)))\n (push-edge index (1+ index) 1 graph)))\n (#\\S (setf start-i i\n start-j j))\n (#\\T (setf goal-i i\n goal-j j))))))\n (when (or (= start-i goal-i) (= start-j goal-j))\n (println -1)\n (return-from main))\n (let ((start-index (trans-coord start-i start-j))\n (goal-index (trans-coord goal-i goal-j)))\n (dotimes (i h)\n (loop for row-rest on (loop for j below w\n when (= 1 (aref plan i j))\n collect j)\n for init-j of-type uint7 = (car row-rest)\n for init-coord = (trans-coord i init-j)\n do (loop for dest-j of-type uint7 in (cdr row-rest)\n for dest-coord = (trans-coord i dest-j)\n do (push-edge (1+ init-coord) dest-coord #xffff graph)\n (push-edge (1+ dest-coord) init-coord #xffff graph))))\n (dotimes (j w)\n (loop for col-rest on (loop for i below h\n when (= 1 (aref plan i j))\n collect i)\n for init-i of-type uint7 = (car col-rest)\n for init-coord = (trans-coord init-i j)\n do (loop for dest-i of-type uint7 in (cdr col-rest)\n for dest-coord = (trans-coord dest-i j)\n do (push-edge (1+ init-coord) dest-coord #xffff graph)\n (push-edge (1+ dest-coord) init-coord #xffff graph))))\n (loop for j of-type uint7 in (loop for j below w\n when (= 1 (aref plan start-i j))\n collect j)\n do (push-edge (1+ start-index) (trans-coord start-i j) #xffff graph))\n (loop for j of-type uint7 in (loop for j below w\n when (= 1 (aref plan goal-i j))\n collect j)\n do (push-edge (1+ (trans-coord goal-i j)) goal-index #xffff graph))\n (loop for i of-type uint7 in (loop for i below h\n when (= 1 (aref plan i start-j))\n collect i)\n do (push-edge (1+ start-index) (trans-coord i start-j) #xffff graph))\n (loop for i of-type uint7 in (loop for i below h\n when (= 1 (aref plan i goal-j))\n collect i)\n do (push-edge (1+ (trans-coord i goal-j)) goal-index #xffff graph))\n (println (max-flow (1+ start-index) goal-index graph))))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1552115518, "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/s461782065.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s461782065", "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 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;;;\n;;; Ford-Fulkerson\n;;;\n(deftype edge () '(cons (unsigned-byte 62) t))\n\n(declaim (inline %make-edge))\n(defun %make-edge (to &key (capacity 0) reversed)\n (declare ((unsigned-byte 31) to capacity)\n (values edge))\n (cons (+ capacity (ash to 31))\n reversed))\n\n(declaim (inline edge-reversed))\n(defun edge-reversed (edge)\n (cdr edge))\n\n(declaim (inline (setf edge-reversed)))\n(defun (setf edge-reversed) (new-value edge)\n (setf (cdr edge) new-value))\n\n(declaim (inline edge-capacity))\n(defun edge-capacity (edge)\n (logand (car edge) #.(- (expt 2 31) 1)))\n\n(declaim (inline (setf edge-capacity)))\n(defun (setf edge-capacity) (new-value edge)\n (declare ((unsigned-byte 31) new-value))\n (setf (car edge)\n (logior new-value (logand (car edge) #.(ash (- (expt 2 31) 1) 31)))))\n\n(declaim (inline edge-to))\n(defun edge-to (edge)\n (ash (the (unsigned-byte 62) (car edge)) -31))\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\n ((simple-array list (*)) graph))\n (let* ((dep (%make-edge to-idx :capacity capacity))\n (ret (%make-edge 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-capacity edge) 0))\n (let ((flow (%find-flow (edge-to edge)\n dest-idx\n graph\n (min max-flow (edge-capacity edge))\n checked)))\n (declare ((integer 0 #.most-positive-fixnum) flow))\n (unless (zerop flow)\n (decf (edge-capacity 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 define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (graph (make-array (* h w 2) :element-type 'list :initial-element nil))\n (start-i 0)\n (start-j 0)\n (goal-i 0)\n (goal-j 0))\n (declare (uint7 h w start-i start-j goal-i goal-j))\n (macrolet ((trans-coord (i j)\n `(* 2 (+ (* w ,i) ,j))))\n (dotimes (i h)\n (let ((line (buffered-read-line 100)))\n (dotimes (j w)\n (case (aref line j)\n (#\\o (setf (aref plan i j) 1)\n (let ((index (trans-coord i j)))\n (push-edge index (1+ index) 1 graph)))\n (#\\S (setf start-i i\n start-j j))\n (#\\T (setf goal-i i\n goal-j j))))))\n (when (or (= start-i goal-i) (= start-j goal-j))\n (println -1)\n (return-from main))\n (let ((start-index (trans-coord start-i start-j))\n (goal-index (trans-coord goal-i goal-j)))\n (dotimes (i h)\n (loop for row-rest on (loop for j below w\n when (= 1 (aref plan i j))\n collect j)\n for init-j of-type uint7 = (car row-rest)\n for init-coord = (trans-coord i init-j)\n do (loop for dest-j of-type uint7 in (cdr row-rest)\n for dest-coord = (trans-coord i dest-j)\n do (push-edge (1+ init-coord) dest-coord #xffff graph)\n (push-edge (1+ dest-coord) init-coord #xffff graph))))\n (dotimes (j w)\n (loop for col-rest on (loop for i below h\n when (= 1 (aref plan i j))\n collect i)\n for init-i of-type uint7 = (car col-rest)\n for init-coord = (trans-coord init-i j)\n do (loop for dest-i of-type uint7 in (cdr col-rest)\n for dest-coord = (trans-coord dest-i j)\n do (push-edge (1+ init-coord) dest-coord #xffff graph)\n (push-edge (1+ dest-coord) init-coord #xffff graph))))\n (loop for j of-type uint7 in (loop for j below w\n when (= 1 (aref plan start-i j))\n collect j)\n do (push-edge (1+ start-index) (trans-coord start-i j) #xffff graph))\n (loop for j of-type uint7 in (loop for j below w\n when (= 1 (aref plan goal-i j))\n collect j)\n do (push-edge (1+ (trans-coord goal-i j)) goal-index #xffff graph))\n (loop for i of-type uint7 in (loop for i below h\n when (= 1 (aref plan i start-j))\n collect i)\n do (push-edge (1+ start-index) (trans-coord i start-j) #xffff graph))\n (loop for i of-type uint7 in (loop for i below h\n when (= 1 (aref plan i goal-j))\n collect i)\n do (push-edge (1+ (trans-coord i goal-j)) goal-index #xffff graph))\n (println (max-flow (1+ start-index) goal-index graph))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8126, "cpu_time_ms": 2113, "memory_kb": 232032}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s939613886", "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(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;;;\n;;; Ford-Fulkerson\n;;;\n\n(defstruct (edge (:constructor %make-edge))\n (to nil :type fixnum)\n (capacity 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\n ((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-capacity edge) 0))\n (let ((flow (%find-flow (edge-to edge)\n dest-idx\n graph\n (min max-flow (edge-capacity edge))\n checked)))\n (declare ((integer 0 #.most-positive-fixnum) flow))\n (unless (zerop flow)\n (decf (edge-capacity 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 define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (graph (make-array (* h w 2) :element-type 'list :initial-element nil))\n (start-i 0)\n (start-j 0)\n (goal-i 0)\n (goal-j 0))\n (declare (uint7 h w start-i start-j goal-i goal-j))\n (macrolet ((trans-coord (i j)\n `(* 2 (+ (* w ,i) ,j))))\n (dotimes (i h)\n (let ((line (buffered-read-line 100)))\n (dotimes (j w)\n (case (aref line j)\n (#\\o (setf (aref plan i j) 1)\n (let ((index (trans-coord i j)))\n (push-edge index (1+ index) 1 graph)))\n (#\\S (setf start-i i\n start-j j))\n (#\\T (setf goal-i i\n goal-j j))))))\n (when (or (= start-i goal-i) (= start-j goal-j))\n (println -1)\n (return-from main))\n (let ((start-index (trans-coord start-i start-j))\n (goal-index (trans-coord goal-i goal-j)))\n (dotimes (i h)\n (loop for row-rest on (loop for j below w\n when (= 1 (aref plan i j))\n collect j)\n for init-j of-type uint7 = (car row-rest)\n for init-coord = (trans-coord i init-j)\n do (loop for dest-j of-type uint7 in (cdr row-rest)\n for dest-coord = (trans-coord i dest-j)\n do (push-edge (1+ init-coord) dest-coord #xffffffff graph)\n (push-edge (1+ dest-coord) init-coord #xffffffff graph))))\n (dotimes (j w)\n (loop for col-rest on (loop for i below h\n when (= 1 (aref plan i j))\n collect i)\n for init-i of-type uint7 = (car col-rest)\n for init-coord = (trans-coord init-i j)\n do (loop for dest-i of-type uint7 in (cdr col-rest)\n for dest-coord = (trans-coord dest-i j)\n do (push-edge (1+ init-coord) dest-coord #xffffffff graph)\n (push-edge (1+ dest-coord) init-coord #xffffffff graph))))\n (loop for j of-type uint7 in (loop for j below w\n when (= 1 (aref plan start-i j))\n collect j)\n do (push-edge (1+ start-index) (trans-coord start-i j) #xffffffff graph))\n (loop for j of-type uint7 in (loop for j below w\n when (= 1 (aref plan goal-i j))\n collect j)\n do (push-edge (1+ (trans-coord goal-i j)) goal-index #xffffffff graph))\n (loop for i of-type uint7 in (loop for i below h\n when (= 1 (aref plan i start-j))\n collect i)\n do (push-edge (1+ start-index) (trans-coord i start-j) #xffffffff graph))\n (loop for i of-type uint7 in (loop for i below h\n when (= 1 (aref plan i goal-j))\n collect i)\n do (push-edge (1+ (trans-coord i goal-j)) goal-index #xffffffff graph))\n (println (max-flow (1+ start-index) goal-index graph))))))\n\n(gc :full t)\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1552114272, "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/s939613886.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Memory Limit Exceeded", "submission_id": "s939613886", "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 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;;;\n;;; Ford-Fulkerson\n;;;\n\n(defstruct (edge (:constructor %make-edge))\n (to nil :type fixnum)\n (capacity 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\n ((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-capacity edge) 0))\n (let ((flow (%find-flow (edge-to edge)\n dest-idx\n graph\n (min max-flow (edge-capacity edge))\n checked)))\n (declare ((integer 0 #.most-positive-fixnum) flow))\n (unless (zerop flow)\n (decf (edge-capacity 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 define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0))\n (graph (make-array (* h w 2) :element-type 'list :initial-element nil))\n (start-i 0)\n (start-j 0)\n (goal-i 0)\n (goal-j 0))\n (declare (uint7 h w start-i start-j goal-i goal-j))\n (macrolet ((trans-coord (i j)\n `(* 2 (+ (* w ,i) ,j))))\n (dotimes (i h)\n (let ((line (buffered-read-line 100)))\n (dotimes (j w)\n (case (aref line j)\n (#\\o (setf (aref plan i j) 1)\n (let ((index (trans-coord i j)))\n (push-edge index (1+ index) 1 graph)))\n (#\\S (setf start-i i\n start-j j))\n (#\\T (setf goal-i i\n goal-j j))))))\n (when (or (= start-i goal-i) (= start-j goal-j))\n (println -1)\n (return-from main))\n (let ((start-index (trans-coord start-i start-j))\n (goal-index (trans-coord goal-i goal-j)))\n (dotimes (i h)\n (loop for row-rest on (loop for j below w\n when (= 1 (aref plan i j))\n collect j)\n for init-j of-type uint7 = (car row-rest)\n for init-coord = (trans-coord i init-j)\n do (loop for dest-j of-type uint7 in (cdr row-rest)\n for dest-coord = (trans-coord i dest-j)\n do (push-edge (1+ init-coord) dest-coord #xffffffff graph)\n (push-edge (1+ dest-coord) init-coord #xffffffff graph))))\n (dotimes (j w)\n (loop for col-rest on (loop for i below h\n when (= 1 (aref plan i j))\n collect i)\n for init-i of-type uint7 = (car col-rest)\n for init-coord = (trans-coord init-i j)\n do (loop for dest-i of-type uint7 in (cdr col-rest)\n for dest-coord = (trans-coord dest-i j)\n do (push-edge (1+ init-coord) dest-coord #xffffffff graph)\n (push-edge (1+ dest-coord) init-coord #xffffffff graph))))\n (loop for j of-type uint7 in (loop for j below w\n when (= 1 (aref plan start-i j))\n collect j)\n do (push-edge (1+ start-index) (trans-coord start-i j) #xffffffff graph))\n (loop for j of-type uint7 in (loop for j below w\n when (= 1 (aref plan goal-i j))\n collect j)\n do (push-edge (1+ (trans-coord goal-i j)) goal-index #xffffffff graph))\n (loop for i of-type uint7 in (loop for i below h\n when (= 1 (aref plan i start-j))\n collect i)\n do (push-edge (1+ start-index) (trans-coord i start-j) #xffffffff graph))\n (loop for i of-type uint7 in (loop for i below h\n when (= 1 (aref plan i goal-j))\n collect i)\n do (push-edge (1+ (trans-coord i goal-j)) goal-index #xffffffff graph))\n (println (max-flow (1+ start-index) goal-index graph))))))\n\n(gc :full t)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7442, "cpu_time_ms": 1299, "memory_kb": 322336}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s636749621", "group_id": "codeNet:p03719", "input_text": "(let ((a (read))\n (b (read))\n (c (read)))\n\n (format t \"~A~%\"\n (if (and (<= c b) (<= a c)) \"Yes\" \"No\")))\n", "language": "Lisp", "metadata": {"date": 1572922111, "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/s636749621.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s636749621", "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 (and (<= c b) (<= a c)) \"Yes\" \"No\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 96, "memory_kb": 11112}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s068830777", "group_id": "codeNet:p03720", "input_text": "(let* ((n (read))\n (m (read))\n (lst (loop repeat (* 2 m)\n collect (read))))\n\n (loop for i from 1 to n\n do (format t \"~A~%\" (count i lst))))\n", "language": "Lisp", "metadata": {"date": 1572921122, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s068830777.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s068830777", "user_id": "u336541610"}, "prompt_components": {"gold_output": "2\n2\n1\n1\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst (loop repeat (* 2 m)\n collect (read))))\n\n (loop for i from 1 to n\n do (format t \"~A~%\" (count i lst))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 79, "memory_kb": 8808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s310721780", "group_id": "codeNet:p03721", "input_text": "(defun solver ()\n (let* ((N (read)) (K (read))\n (array (make-array 100001 :initial-element 0)))\n (do ((i 0 (incf i))) ((= i N))\n (let ((a (read)) (b (read)))\n (incf (aref array a) b)))\n (let ((count 0))\n (do ((j 0 (incf j))) ((= j 100000))\n (incf count (aref array j))\n (when (>= count K)\n (return (format t \"~A~%\" j)))))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1494727387, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s310721780.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s310721780", "user_id": "u183015556"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun solver ()\n (let* ((N (read)) (K (read))\n (array (make-array 100001 :initial-element 0)))\n (do ((i 0 (incf i))) ((= i N))\n (let ((a (read)) (b (read)))\n (incf (aref array a) b)))\n (let ((count 0))\n (do ((j 0 (incf j))) ((= j 100000))\n (incf count (aref array j))\n (when (>= count K)\n (return (format t \"~A~%\" j)))))))\n\n(solver)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 427, "memory_kb": 57704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s538117841", "group_id": "codeNet:p03723", "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* ((a (read))\n (b (read))\n (c (read))\n (res 0))\n (declare (uint32 a b c res))\n (println\n (sb-int:with-progressive-timeout (elapsed-time :seconds 1.9f0)\n (loop\n (when (eq 0 (elapsed-time))\n (return -1))\n (when (or (oddp a) (oddp b) (oddp c))\n (return res))\n (psetq a (ash (+ b c) -1)\n b (ash (+ c a) -1)\n c (ash (+ a b) -1))\n (incf 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 \"4 12 20\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"14 14 14\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"454 414 444\n\"\n \"1\n\")))\n", "language": "Lisp", "metadata": {"date": 1578105251, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03723.html", "problem_id": "p03723", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03723/input.txt", "sample_output_relpath": "derived/input_output/data/p03723/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03723/Lisp/s538117841.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s538117841", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (declare (uint32 a b c res))\n (println\n (sb-int:with-progressive-timeout (elapsed-time :seconds 1.9f0)\n (loop\n (when (eq 0 (elapsed-time))\n (return -1))\n (when (or (oddp a) (oddp b) (oddp c))\n (return res))\n (psetq a (ash (+ b c) -1)\n b (ash (+ c a) -1)\n c (ash (+ a b) -1))\n (incf 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 \"4 12 20\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"14 14 14\n\"\n \"-1\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"454 414 444\n\"\n \"1\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:\n\nEach person simultaneously divides his cookies in half and gives one half to each of the other two persons.\n\nThis action will be repeated until there is a person with odd number of cookies in hand.\n\nHow many times will they repeat this action?\nNote that the answer may not be finite.\n\nConstraints\n\n1 ≤ A,B,C ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the number of times the action will be performed by the three people, if this number is finite.\nIf it is infinite, print -1 instead.\n\nSample Input 1\n\n4 12 20\n\nSample Output 1\n\n3\n\nInitially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,\n\nAfter the first action, they have 16, 12 and 8.\n\nAfter the second action, they have 10, 12 and 14.\n\nAfter the third action, they have 13, 12 and 11.\n\nNow, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.\n\nSample Input 2\n\n14 14 14\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n454 414 444\n\nSample Output 3\n\n1", "sample_input": "4 12 20\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03723", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:\n\nEach person simultaneously divides his cookies in half and gives one half to each of the other two persons.\n\nThis action will be repeated until there is a person with odd number of cookies in hand.\n\nHow many times will they repeat this action?\nNote that the answer may not be finite.\n\nConstraints\n\n1 ≤ A,B,C ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the number of times the action will be performed by the three people, if this number is finite.\nIf it is infinite, print -1 instead.\n\nSample Input 1\n\n4 12 20\n\nSample Output 1\n\n3\n\nInitially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,\n\nAfter the first action, they have 16, 12 and 8.\n\nAfter the second action, they have 10, 12 and 14.\n\nAfter the third action, they have 13, 12 and 11.\n\nNow, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.\n\nSample Input 2\n\n14 14 14\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n454 414 444\n\nSample Output 3\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4221, "cpu_time_ms": 1927, "memory_kb": 6624}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s851193543", "group_id": "codeNet:p03723", "input_text": "(defun solve (a b c)\n (when (= a b c)\n (if (oddp a)\n (return-from solve 0)\n (return-from solve -1)))\n (labels \n ((proc (a b c num)\n (if (or (oddp a) (oddp b) (oddp c))\n (return-from proc num) \n (proc (/ (+ b c) 2) (/ (+ c a) 2) (/ (+ a b) 2) (1+ num)))))\n (proc a b c 0)))\n(princ (solve (read) (read) (read)))", "language": "Lisp", "metadata": {"date": 1523234128, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03723.html", "problem_id": "p03723", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03723/input.txt", "sample_output_relpath": "derived/input_output/data/p03723/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03723/Lisp/s851193543.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s851193543", "user_id": "u672956630"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun solve (a b c)\n (when (= a b c)\n (if (oddp a)\n (return-from solve 0)\n (return-from solve -1)))\n (labels \n ((proc (a b c num)\n (if (or (oddp a) (oddp b) (oddp c))\n (return-from proc num) \n (proc (/ (+ b c) 2) (/ (+ c a) 2) (/ (+ a b) 2) (1+ num)))))\n (proc a b c 0)))\n(princ (solve (read) (read) (read)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:\n\nEach person simultaneously divides his cookies in half and gives one half to each of the other two persons.\n\nThis action will be repeated until there is a person with odd number of cookies in hand.\n\nHow many times will they repeat this action?\nNote that the answer may not be finite.\n\nConstraints\n\n1 ≤ A,B,C ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the number of times the action will be performed by the three people, if this number is finite.\nIf it is infinite, print -1 instead.\n\nSample Input 1\n\n4 12 20\n\nSample Output 1\n\n3\n\nInitially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,\n\nAfter the first action, they have 16, 12 and 8.\n\nAfter the second action, they have 10, 12 and 14.\n\nAfter the third action, they have 13, 12 and 11.\n\nNow, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.\n\nSample Input 2\n\n14 14 14\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n454 414 444\n\nSample Output 3\n\n1", "sample_input": "4 12 20\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03723", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:\n\nEach person simultaneously divides his cookies in half and gives one half to each of the other two persons.\n\nThis action will be repeated until there is a person with odd number of cookies in hand.\n\nHow many times will they repeat this action?\nNote that the answer may not be finite.\n\nConstraints\n\n1 ≤ A,B,C ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the number of times the action will be performed by the three people, if this number is finite.\nIf it is infinite, print -1 instead.\n\nSample Input 1\n\n4 12 20\n\nSample Output 1\n\n3\n\nInitially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,\n\nAfter the first action, they have 16, 12 and 8.\n\nAfter the second action, they have 10, 12 and 14.\n\nAfter the third action, they have 13, 12 and 11.\n\nNow, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.\n\nSample Input 2\n\n14 14 14\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n454 414 444\n\nSample Output 3\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 352, "cpu_time_ms": 15, "memory_kb": 4072}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s157483301", "group_id": "codeNet:p03723", "input_text": "(defun f (a b c n)\n (if (or (oddp a)\n\t (oddp b)\n\t (oddp c))\n n\n (f (/ (+ b c) 2)\n\t (/ (+ a c) 2)\n\t (/ (+ a b) 2)\n\t (+ n 1))))\n\n(defun ff (a b c)\n (if (and (= a b) (= b c))\n (if (evenp a)\n\t -1\n\t 0)\n (f a b c 0)))\n\n(let ((a (read))\n (b (read))\n (c (read)))\n (format t \"~a~%\" (ff a b c)))", "language": "Lisp", "metadata": {"date": 1494133059, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03723.html", "problem_id": "p03723", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03723/input.txt", "sample_output_relpath": "derived/input_output/data/p03723/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03723/Lisp/s157483301.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s157483301", "user_id": "u100932207"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun f (a b c n)\n (if (or (oddp a)\n\t (oddp b)\n\t (oddp c))\n n\n (f (/ (+ b c) 2)\n\t (/ (+ a c) 2)\n\t (/ (+ a b) 2)\n\t (+ n 1))))\n\n(defun ff (a b c)\n (if (and (= a b) (= b c))\n (if (evenp a)\n\t -1\n\t 0)\n (f a b c 0)))\n\n(let ((a (read))\n (b (read))\n (c (read)))\n (format t \"~a~%\" (ff a b c)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:\n\nEach person simultaneously divides his cookies in half and gives one half to each of the other two persons.\n\nThis action will be repeated until there is a person with odd number of cookies in hand.\n\nHow many times will they repeat this action?\nNote that the answer may not be finite.\n\nConstraints\n\n1 ≤ A,B,C ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the number of times the action will be performed by the three people, if this number is finite.\nIf it is infinite, print -1 instead.\n\nSample Input 1\n\n4 12 20\n\nSample Output 1\n\n3\n\nInitially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,\n\nAfter the first action, they have 16, 12 and 8.\n\nAfter the second action, they have 10, 12 and 14.\n\nAfter the third action, they have 13, 12 and 11.\n\nNow, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.\n\nSample Input 2\n\n14 14 14\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n454 414 444\n\nSample Output 3\n\n1", "sample_input": "4 12 20\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03723", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:\n\nEach person simultaneously divides his cookies in half and gives one half to each of the other two persons.\n\nThis action will be repeated until there is a person with odd number of cookies in hand.\n\nHow many times will they repeat this action?\nNote that the answer may not be finite.\n\nConstraints\n\n1 ≤ A,B,C ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the number of times the action will be performed by the three people, if this number is finite.\nIf it is infinite, print -1 instead.\n\nSample Input 1\n\n4 12 20\n\nSample Output 1\n\n3\n\nInitially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,\n\nAfter the first action, they have 16, 12 and 8.\n\nAfter the second action, they have 10, 12 and 14.\n\nAfter the third action, they have 13, 12 and 11.\n\nNow, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.\n\nSample Input 2\n\n14 14 14\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n454 414 444\n\nSample Output 3\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 322, "cpu_time_ms": 144, "memory_kb": 14052}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s171252283", "group_id": "codeNet:p03723", "input_text": "(defun f (a b c n)\n (if (or (= (mod a 2) 1)\n\t (= (mod b 2) 1)\n\t (= (mod c 2) 1))\n n\n (f (/ (+ b c) 2)\n\t (/ (+ a c) 2)\n\t (/ (+ a b) 2)\n\t (+ n 1))))\n\n(defun ff (a b c)\n (if (and (= a b) (= b c))\n (if (= (mod a 2) 0)\n\t -1\n\t 0)\n (f a b c 0)))\n\n(let ((a (read))\n (b (read))\n (c (read)))\n (format t \"~a~%\" (ff a b c)))", "language": "Lisp", "metadata": {"date": 1494132804, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03723.html", "problem_id": "p03723", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03723/input.txt", "sample_output_relpath": "derived/input_output/data/p03723/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03723/Lisp/s171252283.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s171252283", "user_id": "u100932207"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun f (a b c n)\n (if (or (= (mod a 2) 1)\n\t (= (mod b 2) 1)\n\t (= (mod c 2) 1))\n n\n (f (/ (+ b c) 2)\n\t (/ (+ a c) 2)\n\t (/ (+ a b) 2)\n\t (+ n 1))))\n\n(defun ff (a b c)\n (if (and (= a b) (= b c))\n (if (= (mod a 2) 0)\n\t -1\n\t 0)\n (f a b c 0)))\n\n(let ((a (read))\n (b (read))\n (c (read)))\n (format t \"~a~%\" (ff a b c)))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:\n\nEach person simultaneously divides his cookies in half and gives one half to each of the other two persons.\n\nThis action will be repeated until there is a person with odd number of cookies in hand.\n\nHow many times will they repeat this action?\nNote that the answer may not be finite.\n\nConstraints\n\n1 ≤ A,B,C ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the number of times the action will be performed by the three people, if this number is finite.\nIf it is infinite, print -1 instead.\n\nSample Input 1\n\n4 12 20\n\nSample Output 1\n\n3\n\nInitially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,\n\nAfter the first action, they have 16, 12 and 8.\n\nAfter the second action, they have 10, 12 and 14.\n\nAfter the third action, they have 13, 12 and 11.\n\nNow, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.\n\nSample Input 2\n\n14 14 14\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n454 414 444\n\nSample Output 3\n\n1", "sample_input": "4 12 20\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03723", "source_text": "Score : 300 points\n\nProblem Statement\n\nTakahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:\n\nEach person simultaneously divides his cookies in half and gives one half to each of the other two persons.\n\nThis action will be repeated until there is a person with odd number of cookies in hand.\n\nHow many times will they repeat this action?\nNote that the answer may not be finite.\n\nConstraints\n\n1 ≤ A,B,C ≤ 10^9\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA B C\n\nOutput\n\nPrint the number of times the action will be performed by the three people, if this number is finite.\nIf it is infinite, print -1 instead.\n\nSample Input 1\n\n4 12 20\n\nSample Output 1\n\n3\n\nInitially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,\n\nAfter the first action, they have 16, 12 and 8.\n\nAfter the second action, they have 10, 12 and 14.\n\nAfter the third action, they have 13, 12 and 11.\n\nNow, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.\n\nSample Input 2\n\n14 14 14\n\nSample Output 2\n\n-1\n\nSample Input 3\n\n454 414 444\n\nSample Output 3\n\n1", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 349, "cpu_time_ms": 133, "memory_kb": 15972}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s301048076", "group_id": "codeNet:p03724", "input_text": "(let ((n (read))\n (m (read))\n (total 0))\n (loop for i from 1 to m\n do\n (let ((a (read))\n\t (b (read)))\n\t (when (oddp (- a b))\n\t (incf total))))\n (format t \"~:[YES~;NO~]\" (oddp total)))", "language": "Lisp", "metadata": {"date": 1494135500, "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/s301048076.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s301048076", "user_id": "u100932207"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(let ((n (read))\n (m (read))\n (total 0))\n (loop for i from 1 to m\n do\n (let ((a (read))\n\t (b (read)))\n\t (when (oddp (- a b))\n\t (incf total))))\n (format t \"~:[YES~;NO~]\" (oddp total)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 505, "memory_kb": 67684}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s844982901", "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;;;\n;;; Maximum bipartite matching (Hopcroft-Karp, O(E sqrt(V)))\n;;;\n\n;; NOTE: The number of elements in the graph must be less than 2^32-1 as we use\n;; (UNSIGNED-BYTE 32) here for efficiency.\n\n;; NOTE: Pay attention to the stack size!\n\n(defconstant +graph-inf-distance+ #xffffffff)\n\n(defstruct (bipartite-graph\n (:constructor make-bgraph\n (size1\n size2\n &aux\n (graph1 (make-array size1 :element-type 'list :initial-element nil))\n (levels1 (make-array size1 :element-type '(unsigned-byte 32)))\n (levels2 (make-array size2 :element-type '(unsigned-byte 32)))\n (matching1 (make-array size1 :element-type 'fixnum :initial-element -1))\n (matching2 (make-array size2 :element-type 'fixnum :initial-element -1))\n (queue (make-array (+ size1 size2) :element-type '(unsigned-byte 32)))))\n (:conc-name bgraph-))\n (size1 0 :type (unsigned-byte 32))\n (size2 0 :type (unsigned-byte 32))\n (graph1 nil :type (simple-array list (*)))\n (levels1 nil :type (simple-array (unsigned-byte 32) (*)))\n (levels2 nil :type (simple-array (unsigned-byte 32) (*)))\n (matching1 nil :type (simple-array fixnum (*)))\n (matching2 nil :type (simple-array fixnum (*)))\n (queue nil :type (simple-array (unsigned-byte 32) (*))))\n\n(declaim (inline bgraph-add-edge!))\n(defun bgraph-add-edge! (bgraph vertex1 vertex2)\n (push vertex2 (aref (bgraph-graph1 bgraph) vertex1))\n bgraph)\n\n(defun %fill-levels (bgraph)\n \"Does BFS and fills LEVELS.\"\n (declare (optimize (speed 3) (safety 0)))\n (let ((graph1 (bgraph-graph1 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (levels1 (bgraph-levels1 bgraph))\n (levels2 (bgraph-levels2 bgraph))\n (queue (bgraph-queue bgraph))\n (q-front 0)\n (q-end 0)\n (found nil))\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 levels1 +graph-inf-distance+)\n (fill levels2 +graph-inf-distance+)\n (dotimes (i (bgraph-size1 bgraph))\n (when (= -1 (aref matching1 i))\n (setf (aref levels1 i) 0)\n (enqueue i)))\n (loop until (= q-front q-end)\n for vertex = (dequeue)\n do (dolist (next (aref graph1 vertex))\n (when (= +graph-inf-distance+ (aref levels2 next))\n (setf (aref levels2 next) (+ 1 (aref levels1 vertex)))\n (let ((partner (aref matching2 next)))\n (when (= -1 partner)\n (setq found t)\n (return))\n (setf (aref levels1 partner) (+ 1 (aref levels2 next)))\n (enqueue partner))))))\n found))\n\n(defun %find-matching (bgraph src)\n \"Does DFS and makes matching greedily on the residual network.\"\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) src))\n (let ((matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (levels1 (bgraph-levels1 bgraph))\n (levels2 (bgraph-levels2 bgraph))\n (graph1 (bgraph-graph1 bgraph)))\n (labels ((dfs (v)\n (declare ((integer 0 #.most-positive-fixnum) v))\n (dolist (next (aref graph1 v))\n (when (= (aref levels2 next) (+ 1 (aref levels1 v)))\n (setf (aref levels2 next) +graph-inf-distance+) ; mark visited\n (let ((partner (aref matching2 next)))\n (when (or (= -1 partner) (dfs partner))\n (setf (aref matching1 v) next\n (aref matching2 next) v\n (aref levels1 v) +graph-inf-distance+ ; mark visited\n )\n (return-from dfs t)))))\n (setf (aref levels1 v) +graph-inf-distance+) ; mark visited\n nil ; not matched\n ))\n (dfs src))))\n\n(declaim (ftype (function * (values (unsigned-byte 32) &optional)) bgraph-build-matching!))\n(defun bgraph-build-matching! (bgraph)\n \"Makes a maximum bipartite matching and returns two vectors: correspondence\nfrom group 1 to group 2, and correspondence from group 2 to group 1. At an\nunmatched vertex, -1 is stored.\"\n (declare (optimize (speed 3)))\n (let* ((size1 (bgraph-size1 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (count 0))\n (declare ((integer 0 #.most-positive-fixnum) count))\n (loop while (%fill-levels bgraph)\n do (dotimes (v size1)\n (when (and (= -1 (aref matching1 v))\n (%find-matching bgraph v))\n (incf count))))\n count))\n\n;; not tested\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n (simple-array (integer 0 #.most-positive-fixnum) (*))\n &optional))\n bgraph-decompose!))\n(defun bgraph-decompose (bgraph)\n \"Decomposes a residual network to strongly connected components by Tarjan's\nalgorithm. BGRAPH-BUILD-MATCHING! must be called beforehand.\"\n (declare (optimize (speed 3)))\n (let* ((size1 (bgraph-size1 bgraph))\n (size2 (bgraph-size2 bgraph))\n (total-size (+ size1 size2 2))\n (source (+ size1 size2))\n (sink (+ size1 size2 1))\n (graph1 (bgraph-graph1 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (ord 0) ; in-order\n (ords (make-array total-size :element-type 'fixnum :initial-element -1))\n (lowlinks (make-array total-size :element-type 'fixnum))\n (components (make-array total-size\n :element-type '(integer 0 #.most-positive-fixnum)))\n (comp-index 0) ; index number of component\n (sizes (make-array total-size\n :element-type '(integer 0 #.most-positive-fixnum)\n :initial-element 0))\n (stack (make-array total-size :element-type '(integer 0 #.most-positive-fixnum)))\n (end 0) ; stack pointer\n (in-stack (make-array total-size :element-type 'bit :initial-element 0)))\n (declare ((integer 0 #.most-positive-fixnum) ord end comp-index source sink total-size))\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 (frob (v next)\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 (visit (v)\n (setf (aref ords v) ord\n (aref lowlinks v) ord)\n (incf ord)\n (%push v)\n (cond ((= v source)\n (loop for next below size1\n when (= -1 (aref matching1 next))\n do (frob v next)))\n ((= v sink)\n (loop for next below size2\n unless (= -1 (aref matching2 next))\n do (frob v (+ size1 next))))\n ((and (< v size1) (= -1 (aref matching1 v)))\n (dolist (next (aref graph1 v))\n (declare ((integer 0 #.most-positive-fixnum) next))\n (frob v (+ next size1))))\n ((and (< v size1) (/= -1 (aref matching1 v)))\n (frob v source)\n (dolist (next (aref graph1 v))\n (declare ((integer 0 #.most-positive-fixnum) next))\n (unless (= next (aref matching1 v))\n (frob v (+ next size1)))))\n ((= -1 (aref matching2 (- v size1)))\n (frob v sink))\n (t\n ;; (assert (/= -1 (aref matching2 (- v size1))))\n (frob v (aref matching2 (- v size1)))))\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 total-size)\n (when (= -1 (aref ords v))\n (visit v)))\n (values (subseq components 0 size1)\n (subseq components size1 (+ size1 size2))))))\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(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(defun main ()\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (as (make-array n :element-type 'uint31 :initial-element 0))\n (bs (make-array n :element-type 'uint31 :initial-element 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 (setf (aref as i) a\n (aref bs i) b)))\n (let ((colors (bipartite-p graph))\n (maps (make-array n :element-type 'int32 :initial-element 0))\n (size0 0)\n (size1 0))\n (dotimes (i n)\n (if (zerop (aref colors i))\n (progn (setf (aref maps i) size0)\n (incf size0))\n (progn (setf (aref maps i) size1)\n (incf size1))))\n (let ((bgraph (make-bgraph size0 size1)))\n (loop for a across as\n for b across bs\n when (zerop (aref colors a))\n do (bgraph-add-edge! bgraph (aref maps a) (aref maps b))\n else do (bgraph-add-edge! bgraph (aref maps b) (aref maps a)))\n (let ((res (bgraph-build-matching! bgraph)))\n (write-line\n (if (= (* res 2) n)\n \"Second\"\n \"First\")))))))\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": 1589552425, "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/s844982901.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s844982901", "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;;;\n;;; Maximum bipartite matching (Hopcroft-Karp, O(E sqrt(V)))\n;;;\n\n;; NOTE: The number of elements in the graph must be less than 2^32-1 as we use\n;; (UNSIGNED-BYTE 32) here for efficiency.\n\n;; NOTE: Pay attention to the stack size!\n\n(defconstant +graph-inf-distance+ #xffffffff)\n\n(defstruct (bipartite-graph\n (:constructor make-bgraph\n (size1\n size2\n &aux\n (graph1 (make-array size1 :element-type 'list :initial-element nil))\n (levels1 (make-array size1 :element-type '(unsigned-byte 32)))\n (levels2 (make-array size2 :element-type '(unsigned-byte 32)))\n (matching1 (make-array size1 :element-type 'fixnum :initial-element -1))\n (matching2 (make-array size2 :element-type 'fixnum :initial-element -1))\n (queue (make-array (+ size1 size2) :element-type '(unsigned-byte 32)))))\n (:conc-name bgraph-))\n (size1 0 :type (unsigned-byte 32))\n (size2 0 :type (unsigned-byte 32))\n (graph1 nil :type (simple-array list (*)))\n (levels1 nil :type (simple-array (unsigned-byte 32) (*)))\n (levels2 nil :type (simple-array (unsigned-byte 32) (*)))\n (matching1 nil :type (simple-array fixnum (*)))\n (matching2 nil :type (simple-array fixnum (*)))\n (queue nil :type (simple-array (unsigned-byte 32) (*))))\n\n(declaim (inline bgraph-add-edge!))\n(defun bgraph-add-edge! (bgraph vertex1 vertex2)\n (push vertex2 (aref (bgraph-graph1 bgraph) vertex1))\n bgraph)\n\n(defun %fill-levels (bgraph)\n \"Does BFS and fills LEVELS.\"\n (declare (optimize (speed 3) (safety 0)))\n (let ((graph1 (bgraph-graph1 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (levels1 (bgraph-levels1 bgraph))\n (levels2 (bgraph-levels2 bgraph))\n (queue (bgraph-queue bgraph))\n (q-front 0)\n (q-end 0)\n (found nil))\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 levels1 +graph-inf-distance+)\n (fill levels2 +graph-inf-distance+)\n (dotimes (i (bgraph-size1 bgraph))\n (when (= -1 (aref matching1 i))\n (setf (aref levels1 i) 0)\n (enqueue i)))\n (loop until (= q-front q-end)\n for vertex = (dequeue)\n do (dolist (next (aref graph1 vertex))\n (when (= +graph-inf-distance+ (aref levels2 next))\n (setf (aref levels2 next) (+ 1 (aref levels1 vertex)))\n (let ((partner (aref matching2 next)))\n (when (= -1 partner)\n (setq found t)\n (return))\n (setf (aref levels1 partner) (+ 1 (aref levels2 next)))\n (enqueue partner))))))\n found))\n\n(defun %find-matching (bgraph src)\n \"Does DFS and makes matching greedily on the residual network.\"\n (declare (optimize (speed 3) (safety 0))\n ((integer 0 #.most-positive-fixnum) src))\n (let ((matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (levels1 (bgraph-levels1 bgraph))\n (levels2 (bgraph-levels2 bgraph))\n (graph1 (bgraph-graph1 bgraph)))\n (labels ((dfs (v)\n (declare ((integer 0 #.most-positive-fixnum) v))\n (dolist (next (aref graph1 v))\n (when (= (aref levels2 next) (+ 1 (aref levels1 v)))\n (setf (aref levels2 next) +graph-inf-distance+) ; mark visited\n (let ((partner (aref matching2 next)))\n (when (or (= -1 partner) (dfs partner))\n (setf (aref matching1 v) next\n (aref matching2 next) v\n (aref levels1 v) +graph-inf-distance+ ; mark visited\n )\n (return-from dfs t)))))\n (setf (aref levels1 v) +graph-inf-distance+) ; mark visited\n nil ; not matched\n ))\n (dfs src))))\n\n(declaim (ftype (function * (values (unsigned-byte 32) &optional)) bgraph-build-matching!))\n(defun bgraph-build-matching! (bgraph)\n \"Makes a maximum bipartite matching and returns two vectors: correspondence\nfrom group 1 to group 2, and correspondence from group 2 to group 1. At an\nunmatched vertex, -1 is stored.\"\n (declare (optimize (speed 3)))\n (let* ((size1 (bgraph-size1 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (count 0))\n (declare ((integer 0 #.most-positive-fixnum) count))\n (loop while (%fill-levels bgraph)\n do (dotimes (v size1)\n (when (and (= -1 (aref matching1 v))\n (%find-matching bgraph v))\n (incf count))))\n count))\n\n;; not tested\n(declaim (ftype (function * (values (simple-array (integer 0 #.most-positive-fixnum) (*))\n (simple-array (integer 0 #.most-positive-fixnum) (*))\n &optional))\n bgraph-decompose!))\n(defun bgraph-decompose (bgraph)\n \"Decomposes a residual network to strongly connected components by Tarjan's\nalgorithm. BGRAPH-BUILD-MATCHING! must be called beforehand.\"\n (declare (optimize (speed 3)))\n (let* ((size1 (bgraph-size1 bgraph))\n (size2 (bgraph-size2 bgraph))\n (total-size (+ size1 size2 2))\n (source (+ size1 size2))\n (sink (+ size1 size2 1))\n (graph1 (bgraph-graph1 bgraph))\n (matching1 (bgraph-matching1 bgraph))\n (matching2 (bgraph-matching2 bgraph))\n (ord 0) ; in-order\n (ords (make-array total-size :element-type 'fixnum :initial-element -1))\n (lowlinks (make-array total-size :element-type 'fixnum))\n (components (make-array total-size\n :element-type '(integer 0 #.most-positive-fixnum)))\n (comp-index 0) ; index number of component\n (sizes (make-array total-size\n :element-type '(integer 0 #.most-positive-fixnum)\n :initial-element 0))\n (stack (make-array total-size :element-type '(integer 0 #.most-positive-fixnum)))\n (end 0) ; stack pointer\n (in-stack (make-array total-size :element-type 'bit :initial-element 0)))\n (declare ((integer 0 #.most-positive-fixnum) ord end comp-index source sink total-size))\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 (frob (v next)\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 (visit (v)\n (setf (aref ords v) ord\n (aref lowlinks v) ord)\n (incf ord)\n (%push v)\n (cond ((= v source)\n (loop for next below size1\n when (= -1 (aref matching1 next))\n do (frob v next)))\n ((= v sink)\n (loop for next below size2\n unless (= -1 (aref matching2 next))\n do (frob v (+ size1 next))))\n ((and (< v size1) (= -1 (aref matching1 v)))\n (dolist (next (aref graph1 v))\n (declare ((integer 0 #.most-positive-fixnum) next))\n (frob v (+ next size1))))\n ((and (< v size1) (/= -1 (aref matching1 v)))\n (frob v source)\n (dolist (next (aref graph1 v))\n (declare ((integer 0 #.most-positive-fixnum) next))\n (unless (= next (aref matching1 v))\n (frob v (+ next size1)))))\n ((= -1 (aref matching2 (- v size1)))\n (frob v sink))\n (t\n ;; (assert (/= -1 (aref matching2 (- v size1))))\n (frob v (aref matching2 (- v size1)))))\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 total-size)\n (when (= -1 (aref ords v))\n (visit v)))\n (values (subseq components 0 size1)\n (subseq components size1 (+ size1 size2))))))\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(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(defun main ()\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (as (make-array n :element-type 'uint31 :initial-element 0))\n (bs (make-array n :element-type 'uint31 :initial-element 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 (setf (aref as i) a\n (aref bs i) b)))\n (let ((colors (bipartite-p graph))\n (maps (make-array n :element-type 'int32 :initial-element 0))\n (size0 0)\n (size1 0))\n (dotimes (i n)\n (if (zerop (aref colors i))\n (progn (setf (aref maps i) size0)\n (incf size0))\n (progn (setf (aref maps i) size1)\n (incf size1))))\n (let ((bgraph (make-bgraph size0 size1)))\n (loop for a across as\n for b across bs\n when (zerop (aref colors a))\n do (bgraph-add-edge! bgraph (aref maps a) (aref maps b))\n else do (bgraph-add-edge! bgraph (aref maps b) (aref maps a)))\n (let ((res (bgraph-build-matching! bgraph)))\n (write-line\n (if (= (* res 2) n)\n \"Second\"\n \"First\")))))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 17715, "cpu_time_ms": 284, "memory_kb": 53988}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s266766523", "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;;;\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": 1589551076, "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/s266766523.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s266766523", "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;;;\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6980, "cpu_time_ms": 227, "memory_kb": 31592}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s905226275", "group_id": "codeNet:p03729", "input_text": "(setq a(concatenate(string(read))))\n(setq b(concatenate(string(read))))\n(setq c(concatenate(string(read))))\n(princ(if(and(char=(nth(length a)a)(first b))(char=(nth(length b)b)(first c)))\"YES\"\"NO\"))", "language": "Lisp", "metadata": {"date": 1528286576, "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/s905226275.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s905226275", "user_id": "u657913472"}, "prompt_components": {"gold_output": "YES\n", "input_to_evaluate": "(setq a(concatenate(string(read))))\n(setq b(concatenate(string(read))))\n(setq c(concatenate(string(read))))\n(princ(if(and(char=(nth(length a)a)(first b))(char=(nth(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 58, "memory_kb": 7268}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s881016140", "group_id": "codeNet:p03731", "input_text": "(let* ((n (read))\n (m (read))\n (lst (loop :repeat n :collect (read))))\n (princ (- (+ (car (last lst)) m)\n (reduce #'+ (mapcar (lambda (j k)\n (if (plusp (- (- k j) m))\n (- (- k j) m)\n 0))\n lst (cdr lst))))))", "language": "Lisp", "metadata": {"date": 1572980149, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03731.html", "problem_id": "p03731", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03731/input.txt", "sample_output_relpath": "derived/input_output/data/p03731/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03731/Lisp/s881016140.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s881016140", "user_id": "u610490393"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst (loop :repeat n :collect (read))))\n (princ (- (+ (car (last lst)) m)\n (reduce #'+ (mapcar (lambda (j k)\n (if (plusp (- (- k j) m))\n (- (- k j) m)\n 0))\n lst (cdr lst))))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nIn a public bath, there is a shower which emits water for T seconds when the switch is pushed.\n\nIf the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.\nNote that it does not mean that the shower emits water for T additional seconds.\n\nN people will push the switch while passing by the shower.\nThe i-th person will push the switch t_i seconds after the first person pushes it.\n\nHow long will the shower emit water in total?\n\nConstraints\n\n1 ≤ N ≤ 200,000\n\n1 ≤ T ≤ 10^9\n\n0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9\n\nT and each t_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\nt_1 t_2 ... t_N\n\nOutput\n\nAssume that the shower will emit water for a total of X seconds. Print X.\n\nSample Input 1\n\n2 4\n0 3\n\nSample Output 1\n\n7\n\nThree seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.\n\nSample Input 2\n\n2 4\n0 5\n\nSample Output 2\n\n8\n\nOne second after the shower stops emission of water triggered by the first person, the switch is pushed again.\n\nSample Input 3\n\n4 1000000000\n0 1000 1000000 1000000000\n\nSample Output 3\n\n2000000000\n\nSample Input 4\n\n1 1\n0\n\nSample Output 4\n\n1\n\nSample Input 5\n\n9 10\n0 3 5 7 100 110 200 300 311\n\nSample Output 5\n\n67", "sample_input": "2 4\n0 3\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03731", "source_text": "Score : 300 points\n\nProblem Statement\n\nIn a public bath, there is a shower which emits water for T seconds when the switch is pushed.\n\nIf the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.\nNote that it does not mean that the shower emits water for T additional seconds.\n\nN people will push the switch while passing by the shower.\nThe i-th person will push the switch t_i seconds after the first person pushes it.\n\nHow long will the shower emit water in total?\n\nConstraints\n\n1 ≤ N ≤ 200,000\n\n1 ≤ T ≤ 10^9\n\n0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9\n\nT and each t_i are integers.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nN T\nt_1 t_2 ... t_N\n\nOutput\n\nAssume that the shower will emit water for a total of X seconds. Print X.\n\nSample Input 1\n\n2 4\n0 3\n\nSample Output 1\n\n7\n\nThree seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.\n\nSample Input 2\n\n2 4\n0 5\n\nSample Output 2\n\n8\n\nOne second after the shower stops emission of water triggered by the first person, the switch is pushed again.\n\nSample Input 3\n\n4 1000000000\n0 1000 1000000 1000000000\n\nSample Output 3\n\n2000000000\n\nSample Input 4\n\n1 1\n0\n\nSample Output 4\n\n1\n\nSample Input 5\n\n9 10\n0 3 5 7 100 110 200 300 311\n\nSample Output 5\n\n67", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 368, "cpu_time_ms": 556, "memory_kb": 59748}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s600402113", "group_id": "codeNet:p03737", "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 (s1 s2 s3) (split (read-line))\n (format t \"~a~a~a~%\"\n (char-upcase (aref s1 0))\n (char-upcase (aref s2 0))\n (char-upcase (aref s3 0))))\n", "language": "Lisp", "metadata": {"date": 1492909409, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03737.html", "problem_id": "p03737", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03737/input.txt", "sample_output_relpath": "derived/input_output/data/p03737/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03737/Lisp/s600402113.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s600402113", "user_id": "u690263481"}, "prompt_components": {"gold_output": "ABC\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 (s1 s2 s3) (split (read-line))\n (format t \"~a~a~a~%\"\n (char-upcase (aref s1 0))\n (char-upcase (aref s2 0))\n (char-upcase (aref s3 0))))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between.\nPrint the acronym formed from the uppercased initial letters of the words.\n\nConstraints\n\ns_1, s_2 and s_3 are composed of lowercase English letters.\n\n1 ≤ |s_i| ≤ 10 (1≤i≤3)\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns_1 s_2 s_3\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\natcoder beginner contest\n\nSample Output 1\n\nABC\n\nThe initial letters of atcoder, beginner and contest are a, b and c. Uppercase and concatenate them to obtain ABC.\n\nSample Input 2\n\nresident register number\n\nSample Output 2\n\nRRN\n\nSample Input 3\n\nk nearest neighbor\n\nSample Output 3\n\nKNN\n\nSample Input 4\n\nasync layered coding\n\nSample Output 4\n\nALC", "sample_input": "atcoder beginner contest\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03737", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between.\nPrint the acronym formed from the uppercased initial letters of the words.\n\nConstraints\n\ns_1, s_2 and s_3 are composed of lowercase English letters.\n\n1 ≤ |s_i| ≤ 10 (1≤i≤3)\n\nInput\n\nInput is given from Standard Input in the following format:\n\ns_1 s_2 s_3\n\nOutput\n\nPrint the answer.\n\nSample Input 1\n\natcoder beginner contest\n\nSample Output 1\n\nABC\n\nThe initial letters of atcoder, beginner and contest are a, b and c. Uppercase and concatenate them to obtain ABC.\n\nSample Input 2\n\nresident register number\n\nSample Output 2\n\nRRN\n\nSample Input 3\n\nk nearest neighbor\n\nSample Output 3\n\nKNN\n\nSample Input 4\n\nasync layered coding\n\nSample Output 4\n\nALC", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 188, "memory_kb": 15840}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s852249223", "group_id": "codeNet:p03738", "input_text": "(let ((a (read))\n (b (read)))\n \n (if (> a b) (princ \"GREATER\")\n (if (< a b) (princ \"LESS\")\n (princ \"EQUAL\"))))", "language": "Lisp", "metadata": {"date": 1601314185, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03738.html", "problem_id": "p03738", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03738/input.txt", "sample_output_relpath": "derived/input_output/data/p03738/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03738/Lisp/s852249223.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s852249223", "user_id": "u136500538"}, "prompt_components": {"gold_output": "GREATER\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n \n (if (> a b) (princ \"GREATER\")\n (if (< a b) (princ \"LESS\")\n (princ \"EQUAL\"))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given two positive integers A and B. Compare the magnitudes of these numbers.\n\nConstraints\n\n1 ≤ A, B ≤ 10^{100}\n\nNeither A nor B begins with a 0.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint GREATER if A>B, LESS if A24, print GREATER.\n\nSample Input 2\n\n850\n3777\n\nSample Output 2\n\nLESS\n\nSample Input 3\n\n9720246\n22516266\n\nSample Output 3\n\nLESS\n\nSample Input 4\n\n123456789012345678901234567890\n234567890123456789012345678901\n\nSample Output 4\n\nLESS", "sample_input": "36\n24\n"}, "reference_outputs": ["GREATER\n"], "source_document_id": "p03738", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given two positive integers A and B. Compare the magnitudes of these numbers.\n\nConstraints\n\n1 ≤ A, B ≤ 10^{100}\n\nNeither A nor B begins with a 0.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint GREATER if A>B, LESS if A24, print GREATER.\n\nSample Input 2\n\n850\n3777\n\nSample Output 2\n\nLESS\n\nSample Input 3\n\n9720246\n22516266\n\nSample Output 3\n\nLESS\n\nSample Input 4\n\n123456789012345678901234567890\n234567890123456789012345678901\n\nSample Output 4\n\nLESS", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 133, "cpu_time_ms": 20, "memory_kb": 24016}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s366714115", "group_id": "codeNet:p03738", "input_text": "(format t \"~A~%\" (let ((a (read))\n (b (read)))\n (cond ((> a b) 'greater)\n ((= a b) 'equal)\n ((< a b) 'less))))", "language": "Lisp", "metadata": {"date": 1504581592, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03738.html", "problem_id": "p03738", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03738/input.txt", "sample_output_relpath": "derived/input_output/data/p03738/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03738/Lisp/s366714115.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s366714115", "user_id": "u140665374"}, "prompt_components": {"gold_output": "GREATER\n", "input_to_evaluate": "(format t \"~A~%\" (let ((a (read))\n (b (read)))\n (cond ((> a b) 'greater)\n ((= a b) 'equal)\n ((< a b) 'less))))", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given two positive integers A and B. Compare the magnitudes of these numbers.\n\nConstraints\n\n1 ≤ A, B ≤ 10^{100}\n\nNeither A nor B begins with a 0.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint GREATER if A>B, LESS if A24, print GREATER.\n\nSample Input 2\n\n850\n3777\n\nSample Output 2\n\nLESS\n\nSample Input 3\n\n9720246\n22516266\n\nSample Output 3\n\nLESS\n\nSample Input 4\n\n123456789012345678901234567890\n234567890123456789012345678901\n\nSample Output 4\n\nLESS", "sample_input": "36\n24\n"}, "reference_outputs": ["GREATER\n"], "source_document_id": "p03738", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given two positive integers A and B. Compare the magnitudes of these numbers.\n\nConstraints\n\n1 ≤ A, B ≤ 10^{100}\n\nNeither A nor B begins with a 0.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint GREATER if A>B, LESS if A24, print GREATER.\n\nSample Input 2\n\n850\n3777\n\nSample Output 2\n\nLESS\n\nSample Input 3\n\n9720246\n22516266\n\nSample Output 3\n\nLESS\n\nSample Input 4\n\n123456789012345678901234567890\n234567890123456789012345678901\n\nSample Output 4\n\nLESS", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 198, "cpu_time_ms": 15, "memory_kb": 3556}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s790387894", "group_id": "codeNet:p03738", "input_text": "(defun solver ()\n (let ((a (read)) (b (read)))\n (cond ((> a b) (format t \"GREATER~%\"))\n ((< a b) (format t \"LESS~%\"))\n ((= a b) (format t \"EQUAL~%\")))))\n\n(solver)", "language": "Lisp", "metadata": {"date": 1493268025, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03738.html", "problem_id": "p03738", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03738/input.txt", "sample_output_relpath": "derived/input_output/data/p03738/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03738/Lisp/s790387894.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s790387894", "user_id": "u183015556"}, "prompt_components": {"gold_output": "GREATER\n", "input_to_evaluate": "(defun solver ()\n (let ((a (read)) (b (read)))\n (cond ((> a b) (format t \"GREATER~%\"))\n ((< a b) (format t \"LESS~%\"))\n ((= a b) (format t \"EQUAL~%\")))))\n\n(solver)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nYou are given two positive integers A and B. Compare the magnitudes of these numbers.\n\nConstraints\n\n1 ≤ A, B ≤ 10^{100}\n\nNeither A nor B begins with a 0.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint GREATER if A>B, LESS if A24, print GREATER.\n\nSample Input 2\n\n850\n3777\n\nSample Output 2\n\nLESS\n\nSample Input 3\n\n9720246\n22516266\n\nSample Output 3\n\nLESS\n\nSample Input 4\n\n123456789012345678901234567890\n234567890123456789012345678901\n\nSample Output 4\n\nLESS", "sample_input": "36\n24\n"}, "reference_outputs": ["GREATER\n"], "source_document_id": "p03738", "source_text": "Score : 200 points\n\nProblem Statement\n\nYou are given two positive integers A and B. Compare the magnitudes of these numbers.\n\nConstraints\n\n1 ≤ A, B ≤ 10^{100}\n\nNeither A nor B begins with a 0.\n\nInput\n\nInput is given from Standard Input in the following format:\n\nA\nB\n\nOutput\n\nPrint GREATER if A>B, LESS if A24, print GREATER.\n\nSample Input 2\n\n850\n3777\n\nSample Output 2\n\nLESS\n\nSample Input 3\n\n9720246\n22516266\n\nSample Output 3\n\nLESS\n\nSample Input 4\n\n123456789012345678901234567890\n234567890123456789012345678901\n\nSample Output 4\n\nLESS", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 116, "memory_kb": 11620}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s635541550", "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(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(defun main ()\n (declare #.OPT)\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 (println-sequence res :key #'1+))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563226990, "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/s635541550.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s635541550", "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(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(defun main ()\n (declare #.OPT)\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 (println-sequence res :key #'1+))))))\n\n#-swank (main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4449, "cpu_time_ms": 136, "memory_kb": 32312}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s782676046", "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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (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 count-collision (anticlock clock l time)\n (if (< (* 2 time) (mod (- x y) l))\n 0\n (let ((remain (- (* 2 time) (mod (- x y) l))))\n (+ 1 (floor remain l)))))\n\n(defun main ()\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 (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 (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 ((actual-index (mod (- (position end0 ends) end-index) n))\n (res (make-array n :element-type 'uint32)))\n (when (= (aref ends actual-index) (aref ends (mod (+ actual-index 1) n)))\n (when (= 1 (aref dirs 0))\n (setf actual-index (mod (+ actual-index 1) n))))\n (when (= (aref ends actual-index) (aref ends (mod (- actual-index 1) n)))\n (when (= 0 (aref dirs 0))\n (setf actual-index (mod (- actual-index 1) 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\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1558652847, "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/s782676046.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s782676046", "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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (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 count-collision (anticlock clock l time)\n (if (< (* 2 time) (mod (- x y) l))\n 0\n (let ((remain (- (* 2 time) (mod (- x y) l))))\n (+ 1 (floor remain l)))))\n\n(defun main ()\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 (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 (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 ((actual-index (mod (- (position end0 ends) end-index) n))\n (res (make-array n :element-type 'uint32)))\n (when (= (aref ends actual-index) (aref ends (mod (+ actual-index 1) n)))\n (when (= 1 (aref dirs 0))\n (setf actual-index (mod (+ actual-index 1) n))))\n (when (= (aref ends actual-index) (aref ends (mod (- actual-index 1) n)))\n (when (= 0 (aref dirs 0))\n (setf actual-index (mod (- actual-index 1) 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\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4494, "cpu_time_ms": 453, "memory_kb": 36196}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s385697855", "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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (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 count-collision (x y l time)\n (if (< (* 2 time) (abs (- x y)))\n 0\n (let ((remain (- (* 2 time) (abs (- x y)))))\n (+ 1 (floor remain l)))))\n\n(defun main ()\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 (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 (count-collision (aref inits 0) (aref inits i) l time)))\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 ((actual-index (- (position end0 ends) end-index))\n (res (make-array n :element-type 'uint32)))\n (when (= (aref ends actual-index) (aref ends (mod (+ actual-index 1) n)))\n (when (= 0 (aref dirs 0))\n (setf actual-index (mod (+ actual-index 1) n))))\n (when (= (aref ends actual-index) (aref ends (mod (- actual-index 1) n)))\n (when (= 1 (aref dirs 0))\n (setf actual-index (mod (- actual-index 1) 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": 1558652067, "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/s385697855.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s385697855", "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 (macrolet ((%read-byte ()\n `(the (unsigned-byte 8)\n #+swank (char-code (read-char in nil #\\Nul))\n #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\\Nul) nil))))\n (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 count-collision (x y l time)\n (if (< (* 2 time) (abs (- x y)))\n 0\n (let ((remain (- (* 2 time) (abs (- x y)))))\n (+ 1 (floor remain l)))))\n\n(defun main ()\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 (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 (count-collision (aref inits 0) (aref inits i) l time)))\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 ((actual-index (- (position end0 ends) end-index))\n (res (make-array n :element-type 'uint32)))\n (when (= (aref ends actual-index) (aref ends (mod (+ actual-index 1) n)))\n (when (= 0 (aref dirs 0))\n (setf actual-index (mod (+ actual-index 1) n))))\n (when (= (aref ends actual-index) (aref ends (mod (- actual-index 1) n)))\n (when (= 1 (aref dirs 0))\n (setf actual-index (mod (- actual-index 1) 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4313, "cpu_time_ms": 493, "memory_kb": 33504}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s575307141", "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(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/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 ((integer 0 #.(expt 10 12)) 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 (solve-small 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": 1598330918, "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/s575307141.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s575307141", "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(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/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 ((integer 0 #.(expt 10 12)) 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 (solve-small 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7863, "cpu_time_ms": 47, "memory_kb": 33944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s538654865", "group_id": "codeNet:p03754", "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/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(in-package :cl-user)\n\n;;;\n;;; Body\n;;;\n\n(defun main ()\n (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-array n :element-type 'double-float :initial-element 0d0))\n (res (make-array n :element-type 'double-float :initial-element 0d0))\n (degs (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i (- n 1))\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (incf (aref degs u))\n (incf (aref degs v))\n (push u (aref graph v))\n (push v (aref graph u))))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (let ((sum 0d0)\n (count (+ (aref degs v) (if (= -1 parent) 0 -1))))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (dfs child v)\n (incf sum (+ 1 (aref dp child)))))\n (setf (aref dp v)\n (if (zerop count) 0d0 (/ sum count)))))\n #>dp\n (sb-int:named-let dfs ((v 0) (parent -1))\n (setf (aref res v) (aref dp v))\n (let ((v-deg (aref degs v)))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (let* ((old-v-value (aref dp v))\n (old-child-value (aref dp child))\n (new-v-value (let ((num (* (- old-v-value\n (/ (+ old-child-value 1) v-deg))\n v-deg)))\n (if (zerop num)\n num\n (/ num (- v-deg 1)))))\n (new-child-value (/ (+ (* (- (aref degs child) 1) old-child-value)\n new-v-value\n 1)\n (aref degs child))))\n (setf (aref dp v) new-v-value\n (aref dp child) new-child-value)\n (dfs child v)\n (setf (aref dp v) old-v-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 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.0\n1.0\n2.0\n2.0\n\"\n (run \"4\n1 2\n2 3\n2 4\n\" nil)))\n (it.bese.fiveam:is\n (equal \"3.0\n1.5\n3.0\n1.5\n\"\n (run \"4\n1 2\n2 4\n4 3\n\" nil)))\n (it.bese.fiveam:is\n (equal \"4.0\n2.0\n2.0\n2.0\n4.0\n\"\n (run \"5\n1 2\n2 3\n3 4\n4 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"2.000000000000\n1.666666666667\n1.666666666667\n3.000000000000\n3.000000000000\n3.000000000000\n3.000000000000\n\"\n (run \"7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n\" nil)))\n (it.bese.fiveam:is\n (equal \"3.666666666667\n2.250000000000\n3.666666666667\n2.833333333333\n2.555555555556\n2.666666666667\n4.333333333333\n2.666666666667\n5.333333333333\n2.500000000000\n2.500000000000\n5.000000000000\n\"\n (run \"12\n1 2\n2 3\n2 4\n4 5\n5 6\n5 7\n6 8\n8 9\n2 10\n10 11\n11 12\n\" nil)))\n (it.bese.fiveam:is\n (equal \"1.0\n1.0\n\"\n (run \"2\n1 2\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1598328421, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03754.html", "problem_id": "p03754", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03754/input.txt", "sample_output_relpath": "derived/input_output/data/p03754/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03754/Lisp/s538654865.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s538654865", "user_id": "u352600849"}, "prompt_components": {"gold_output": "2.0\n1.0\n2.0\n2.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(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;; 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 (let* ((n (read))\n (graph (make-array n :element-type 'list :initial-element nil))\n (dp (make-array n :element-type 'double-float :initial-element 0d0))\n (res (make-array n :element-type 'double-float :initial-element 0d0))\n (degs (make-array n :element-type 'uint31 :initial-element 0)))\n (dotimes (i (- n 1))\n (let ((u (- (read-fixnum) 1))\n (v (- (read-fixnum) 1)))\n (incf (aref degs u))\n (incf (aref degs v))\n (push u (aref graph v))\n (push v (aref graph u))))\n (sb-int:named-let dfs ((v 0) (parent -1))\n (let ((sum 0d0)\n (count (+ (aref degs v) (if (= -1 parent) 0 -1))))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (dfs child v)\n (incf sum (+ 1 (aref dp child)))))\n (setf (aref dp v)\n (if (zerop count) 0d0 (/ sum count)))))\n #>dp\n (sb-int:named-let dfs ((v 0) (parent -1))\n (setf (aref res v) (aref dp v))\n (let ((v-deg (aref degs v)))\n (dolist (child (aref graph v))\n (unless (= child parent)\n (let* ((old-v-value (aref dp v))\n (old-child-value (aref dp child))\n (new-v-value (let ((num (* (- old-v-value\n (/ (+ old-child-value 1) v-deg))\n v-deg)))\n (if (zerop num)\n num\n (/ num (- v-deg 1)))))\n (new-child-value (/ (+ (* (- (aref degs child) 1) old-child-value)\n new-v-value\n 1)\n (aref degs child))))\n (setf (aref dp v) new-v-value\n (aref dp child) new-child-value)\n (dfs child v)\n (setf (aref dp v) old-v-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 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.0\n1.0\n2.0\n2.0\n\"\n (run \"4\n1 2\n2 3\n2 4\n\" nil)))\n (it.bese.fiveam:is\n (equal \"3.0\n1.5\n3.0\n1.5\n\"\n (run \"4\n1 2\n2 4\n4 3\n\" nil)))\n (it.bese.fiveam:is\n (equal \"4.0\n2.0\n2.0\n2.0\n4.0\n\"\n (run \"5\n1 2\n2 3\n3 4\n4 5\n\" nil)))\n (it.bese.fiveam:is\n (equal \"2.000000000000\n1.666666666667\n1.666666666667\n3.000000000000\n3.000000000000\n3.000000000000\n3.000000000000\n\"\n (run \"7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n\" nil)))\n (it.bese.fiveam:is\n (equal \"3.666666666667\n2.250000000000\n3.666666666667\n2.833333333333\n2.555555555556\n2.666666666667\n4.333333333333\n2.666666666667\n5.333333333333\n2.500000000000\n2.500000000000\n5.000000000000\n\"\n (run \"12\n1 2\n2 3\n2 4\n4 5\n5 6\n5 7\n6 8\n8 9\n2 10\n10 11\n11 12\n\" nil)))\n (it.bese.fiveam:is\n (equal \"1.0\n1.0\n\"\n (run \"2\n1 2\n\" nil))))\n", "problem_context": "Max Score: $800$ Points\n\nProblem Statement\n\nThere is an undirected connected graph with $N$ vertices and $N-1$ edges. The i-th edge connects u_i and v_i.\n\nE869120 the coder moves in the graph as follows:\n\nHe move to adjacent vertex, but he can't a visit vertex two or more times.\n\nHe ends move when there is no way to move.\n\nOtherwise, he moves randomly. (equal probability) If he has $p$ way to move this turn, he choose each vertex with $1/p$ probability.\n\nCalculate the expected value of the number of turns, when E869120 starts from vertex i, for all i (1 ≤ i ≤ N).\n\nInput\n\nThe input is given from standard input in the following format.\n\nN\nu_1 v_1\nu_2 v_2\n:\nu_{N-1} v_{N-1}\n\nOutput\n\nIn i-th (1 ≤ i ≤ N) line, print the expected vaule of the number of turns E869120 moves.\n\nThe relative error or absolute error of output should be within 10^{-6}.\n\nConstraints\n\n$1 \\le N \\le 150,000$\n\nThe graph is connected.\n\nSubtasks\n\nSubtask 1 [ $190$ points ]\n\nThere is no vertex which degree is more than 2.\n\nThis means the graph looks like a list.\n\nSubtask 2 [ $220$ points ]\n\n1 ≤ N ≤ 1000.\n\nSubtask 3 [ $390$ points ]\n\nThere are no additional constraints.\n\nSample Input 1\n\n4\n1 2\n2 3\n2 4\n\nSample Output 1\n\n2.0\n1.0\n2.0\n2.0\n\nSample Input 2\n\n4\n1 2\n2 4\n4 3", "sample_input": "4\n1 2\n2 3\n2 4\n"}, "reference_outputs": ["2.0\n1.0\n2.0\n2.0\n"], "source_document_id": "p03754", "source_text": "Max Score: $800$ Points\n\nProblem Statement\n\nThere is an undirected connected graph with $N$ vertices and $N-1$ edges. The i-th edge connects u_i and v_i.\n\nE869120 the coder moves in the graph as follows:\n\nHe move to adjacent vertex, but he can't a visit vertex two or more times.\n\nHe ends move when there is no way to move.\n\nOtherwise, he moves randomly. (equal probability) If he has $p$ way to move this turn, he choose each vertex with $1/p$ probability.\n\nCalculate the expected value of the number of turns, when E869120 starts from vertex i, for all i (1 ≤ i ≤ N).\n\nInput\n\nThe input is given from standard input in the following format.\n\nN\nu_1 v_1\nu_2 v_2\n:\nu_{N-1} v_{N-1}\n\nOutput\n\nIn i-th (1 ≤ i ≤ N) line, print the expected vaule of the number of turns E869120 moves.\n\nThe relative error or absolute error of output should be within 10^{-6}.\n\nConstraints\n\n$1 \\le N \\le 150,000$\n\nThe graph is connected.\n\nSubtasks\n\nSubtask 1 [ $190$ points ]\n\nThere is no vertex which degree is more than 2.\n\nThis means the graph looks like a list.\n\nSubtask 2 [ $220$ points ]\n\n1 ≤ N ≤ 1000.\n\nSubtask 3 [ $390$ points ]\n\nThere are no additional constraints.\n\nSample Input 1\n\n4\n1 2\n2 3\n2 4\n\nSample Output 1\n\n2.0\n1.0\n2.0\n2.0\n\nSample Input 2\n\n4\n1 2\n2 4\n4 3", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7772, "cpu_time_ms": 239, "memory_kb": 73420}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s851695594", "group_id": "codeNet:p03757", "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;; 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 (let* ((n (read))\n (q (read))\n (as (make-array (+ n q) :element-type 'uint31 :initial-element 0))\n (graph (make-array (+ n q) :element-type 'list :initial-element nil))\n (c n))\n (assert (<= n 5000))\n (dotimes (i n)\n (let ((p (read-fixnum))\n (a (read-fixnum)))\n (setf (aref as i) a)\n (unless (= -1 p)\n (push i (aref graph p)))))\n (dotimes (_ q)\n (ecase (read-fixnum)\n (1 (let ((v (read-fixnum))\n (d (read-fixnum))\n (x (read-fixnum)))\n (sb-int:named-let dfs ((v v) (depth 0))\n (when (<= depth d)\n (incf (aref as v) x)\n (dolist (child (aref graph v))\n (dfs child (+ depth 1)))))))\n (2 (let ((v (read-fixnum))\n (d (read-fixnum))\n (res 0))\n (sb-int:named-let dfs ((v v) (depth 0))\n (when (<= depth d)\n (incf res (aref as v))\n (dolist (child (aref graph v))\n (dfs child (+ depth 1)))))\n (println res)))\n (3 (let ((pr (read-fixnum))\n (ar (read-fixnum)))\n (push c (aref graph pr))\n (setf (aref as c) ar)\n (incf 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 \"15\n12\n30\n8\n\"\n (run \"6 7\n-1 6\n0 5\n0 4\n2 3\n2 2\n1 1\n2 0 1\n1 0 2 1\n2 2 1\n3 3 3\n2 0 3\n3 3 4\n2 1 1\n\" nil)))\n (it.bese.fiveam:is\n (equal \"8\n9\n8\n31\n49\n\"\n (run \"7 9\n-1 1\n0 5\n0 7\n0 8\n1 3\n4 1\n5 1\n2 1 1\n2 1 2\n1 1 2 3\n1 4 1 1\n2 3 1\n2 0 2\n3 6 1\n3 7 11\n2 0 15\n\" nil))))\n", "language": "Lisp", "metadata": {"date": 1598333104, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03757.html", "problem_id": "p03757", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03757/input.txt", "sample_output_relpath": "derived/input_output/data/p03757/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03757/Lisp/s851695594.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s851695594", "user_id": "u352600849"}, "prompt_components": {"gold_output": "15\n12\n30\n8\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;; 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 (let* ((n (read))\n (q (read))\n (as (make-array (+ n q) :element-type 'uint31 :initial-element 0))\n (graph (make-array (+ n q) :element-type 'list :initial-element nil))\n (c n))\n (assert (<= n 5000))\n (dotimes (i n)\n (let ((p (read-fixnum))\n (a (read-fixnum)))\n (setf (aref as i) a)\n (unless (= -1 p)\n (push i (aref graph p)))))\n (dotimes (_ q)\n (ecase (read-fixnum)\n (1 (let ((v (read-fixnum))\n (d (read-fixnum))\n (x (read-fixnum)))\n (sb-int:named-let dfs ((v v) (depth 0))\n (when (<= depth d)\n (incf (aref as v) x)\n (dolist (child (aref graph v))\n (dfs child (+ depth 1)))))))\n (2 (let ((v (read-fixnum))\n (d (read-fixnum))\n (res 0))\n (sb-int:named-let dfs ((v v) (depth 0))\n (when (<= depth d)\n (incf res (aref as v))\n (dolist (child (aref graph v))\n (dfs child (+ depth 1)))))\n (println res)))\n (3 (let ((pr (read-fixnum))\n (ar (read-fixnum)))\n (push c (aref graph pr))\n (setf (aref as c) ar)\n (incf 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 \"15\n12\n30\n8\n\"\n (run \"6 7\n-1 6\n0 5\n0 4\n2 3\n2 2\n1 1\n2 0 1\n1 0 2 1\n2 2 1\n3 3 3\n2 0 3\n3 3 4\n2 1 1\n\" nil)))\n (it.bese.fiveam:is\n (equal \"8\n9\n8\n31\n49\n\"\n (run \"7 9\n-1 1\n0 5\n0 7\n0 8\n1 3\n4 1\n5 1\n2 1 1\n2 1 2\n1 1 2 3\n1 4 1 1\n2 3 1\n2 0 2\n3 6 1\n3 7 11\n2 0 15\n\" nil))))\n", "problem_context": "Max Score: 1450 Points\n\nProblem Statement\n\nThere are N workers in Atcoder company. Each worker is numbered 0 through N - 1, and the boss for worker i is p_i like a tree structure and the salary is currently a_i. (p_i < i, especially p_0 = -1 because worker 0 is a president)\n\nIn atcoder, the boss of boss of boss of ... (repeated k times) worker i called \"k-th upper boss\", and \"k-th lower subordinate\" called for vice versa.\n\nYou have to process Q queries for Atcoder:\n\nQuery 1: You are given v_i, d_i, x_i. Increase the salary of worker v_i, and all j-th (1 ≤ j ≤ d_i) lower subordinates by x_i.\n\nQuery 2: You are given v_i, d_i. Calculate the sum of salary of worker v_i and all j-th (1 ≤ j ≤ d_i) lower subordinates.\n\nQuery 3: You are given pr_i, ar_i. Now Atcoder has a new worker c! (c is the current number of workers) The boss is pr_i, and the first salary is ar_i.\n\nProcess all queries!!!\n\nInput Format\n\nLet the i-th query query_i, the input format is following:\n\nN Q\np_0 a_0\np_1 a_1\n: :\np_{N - 1} a_{N - 1}\nquery_0\nquery_1\n: :\nquery_{Q - 1}\n\nTHe format of query_i is one of the three format:\n\n1 v_i d_i x_i\n\n2 v_i d_i\n\n3 pr_i ar_i\n\nOutput Format\n\nPrint the result in one line for each query 2.\n\nConstraints\n\nN ≤ 400000\n\nQ ≤ 50000\n\np_i < i for all valid i.\n\nIn each question 1 or 2, worker v_i exists.\n\nd_i ≤ 400000\n\n0 ≤ a_i, x_i ≤ 1000\n\nScoring\n\nSubtask 1 [170 points]\n\nN, Q ≤ 5000\n\nSubtask 2 [310 points]\n\np_i + 1 = i for all valid i.\n\nSubtask 3 [380 points]\n\nThere are no query 3.\n\nSubtask 4 [590 points]\n\nThere are no additional constraints.\n\nSample Input 1\n\n6 7\n-1 6\n0 5\n0 4\n2 3\n2 2\n1 1\n2 0 1\n1 0 2 1\n2 2 1\n3 3 3\n2 0 3\n3 3 4\n2 1 1\n\nSample Output 1\n\n15\n12\n30\n8\n\nSample Input 2\n\n7 9\n-1 1\n0 5\n0 7\n0 8\n1 3\n4 1\n5 1\n2 1 1\n2 1 2\n1 1 2 3\n1 4 1 1\n2 3 1\n2 0 2\n3 6 1\n3 7 11\n2 0 15\n\nSample Output 2\n\n8\n9\n8\n31\n49", "sample_input": "6 7\n-1 6\n0 5\n0 4\n2 3\n2 2\n1 1\n2 0 1\n1 0 2 1\n2 2 1\n3 3 3\n2 0 3\n3 3 4\n2 1 1\n"}, "reference_outputs": ["15\n12\n30\n8\n"], "source_document_id": "p03757", "source_text": "Max Score: 1450 Points\n\nProblem Statement\n\nThere are N workers in Atcoder company. Each worker is numbered 0 through N - 1, and the boss for worker i is p_i like a tree structure and the salary is currently a_i. (p_i < i, especially p_0 = -1 because worker 0 is a president)\n\nIn atcoder, the boss of boss of boss of ... (repeated k times) worker i called \"k-th upper boss\", and \"k-th lower subordinate\" called for vice versa.\n\nYou have to process Q queries for Atcoder:\n\nQuery 1: You are given v_i, d_i, x_i. Increase the salary of worker v_i, and all j-th (1 ≤ j ≤ d_i) lower subordinates by x_i.\n\nQuery 2: You are given v_i, d_i. Calculate the sum of salary of worker v_i and all j-th (1 ≤ j ≤ d_i) lower subordinates.\n\nQuery 3: You are given pr_i, ar_i. Now Atcoder has a new worker c! (c is the current number of workers) The boss is pr_i, and the first salary is ar_i.\n\nProcess all queries!!!\n\nInput Format\n\nLet the i-th query query_i, the input format is following:\n\nN Q\np_0 a_0\np_1 a_1\n: :\np_{N - 1} a_{N - 1}\nquery_0\nquery_1\n: :\nquery_{Q - 1}\n\nTHe format of query_i is one of the three format:\n\n1 v_i d_i x_i\n\n2 v_i d_i\n\n3 pr_i ar_i\n\nOutput Format\n\nPrint the result in one line for each query 2.\n\nConstraints\n\nN ≤ 400000\n\nQ ≤ 50000\n\np_i < i for all valid i.\n\nIn each question 1 or 2, worker v_i exists.\n\nd_i ≤ 400000\n\n0 ≤ a_i, x_i ≤ 1000\n\nScoring\n\nSubtask 1 [170 points]\n\nN, Q ≤ 5000\n\nSubtask 2 [310 points]\n\np_i + 1 = i for all valid i.\n\nSubtask 3 [380 points]\n\nThere are no query 3.\n\nSubtask 4 [590 points]\n\nThere are no additional constraints.\n\nSample Input 1\n\n6 7\n-1 6\n0 5\n0 4\n2 3\n2 2\n1 1\n2 0 1\n1 0 2 1\n2 2 1\n3 3 3\n2 0 3\n3 3 4\n2 1 1\n\nSample Output 1\n\n15\n12\n30\n8\n\nSample Input 2\n\n7 9\n-1 1\n0 5\n0 7\n0 8\n1 3\n4 1\n5 1\n2 1 1\n2 1 2\n1 1 2 3\n1 4 1 1\n2 3 1\n2 0 2\n3 6 1\n3 7 11\n2 0 15\n\nSample Output 2\n\n8\n9\n8\n31\n49", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5950, "cpu_time_ms": 28, "memory_kb": 30564}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s914672658", "group_id": "codeNet:p03760", "input_text": "(let ((o (concatenate 'list (read-line)))\n (e (concatenate 'list (read-line))))\n\n (defun f (lst1 lst2 &optional ans)\n (if (null (car lst1))\n (reverse ans)\n (f (cdr lst1) (cdr lst2) (cons (car lst2) (cons (car lst1) ans)))))\n\n (format t \"~A~%\"\n (concatenate 'string (remove-if #'null (f o e)))))\n", "language": "Lisp", "metadata": {"date": 1594842365, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s914672658.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s914672658", "user_id": "u336541610"}, "prompt_components": {"gold_output": "xaybzc\n", "input_to_evaluate": "(let ((o (concatenate 'list (read-line)))\n (e (concatenate 'list (read-line))))\n\n (defun f (lst1 lst2 &optional ans)\n (if (null (car lst1))\n (reverse ans)\n (f (cdr lst1) (cdr lst2) (cons (car lst2) (cons (car lst1) ans)))))\n\n (format t \"~A~%\"\n (concatenate 'string (remove-if #'null (f o e)))))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 15, "memory_kb": 23632}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s051898221", "group_id": "codeNet:p03760", "input_text": "(let ((o (concatenate 'list (read-line)))\n (e (concatenate 'list (read-line)))\n (lst '()))\n\n (loop for i from 0 to (1- (length o))\n for j from 0 to (1- (length e))\n do (if (= (length o) (length e))\n (progn (push (nth i o) lst)\n (push (nth j e) lst))\n (progn (push (nth i o) lst)\n (push (nth j e) lst)\n (if (not (nth (1+ j) e)) (push (nth (1+ i) o) lst)))))\n\n (setq lst2 (concatenate 'string (reverse lst)))\n\n (format t \"~A~%\"\n lst2))\n", "language": "Lisp", "metadata": {"date": 1572842149, "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/s051898221.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s051898221", "user_id": "u336541610"}, "prompt_components": {"gold_output": "xaybzc\n", "input_to_evaluate": "(let ((o (concatenate 'list (read-line)))\n (e (concatenate 'list (read-line)))\n (lst '()))\n\n (loop for i from 0 to (1- (length o))\n for j from 0 to (1- (length e))\n do (if (= (length o) (length e))\n (progn (push (nth i o) lst)\n (push (nth j e) lst))\n (progn (push (nth i o) lst)\n (push (nth j e) lst)\n (if (not (nth (1+ j) e)) (push (nth (1+ i) o) lst)))))\n\n (setq lst2 (concatenate 'string (reverse lst)))\n\n (format t \"~A~%\"\n lst2))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 551, "cpu_time_ms": 308, "memory_kb": 13544}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s239789645", "group_id": "codeNet:p03760", "input_text": "(defparameter yen (read))\n(defparameter stk (list 0))\n(defun lp ()\n (princ stk)\n (cond ((= (reduce #'+ stk) yen) (princ \"Yes\"))\n ((< (reduce #'+ stk) yen) (push 4 stk) (lp))\n ((= (first stk) 0) (princ \"No\"))\n ((= (pop stk) 4) (pop stk) (push 7 stk) (lp))\n (t (lp))))", "language": "Lisp", "metadata": {"date": 1539835448, "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/s239789645.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s239789645", "user_id": "u610490393"}, "prompt_components": {"gold_output": "xaybzc\n", "input_to_evaluate": "(defparameter yen (read))\n(defparameter stk (list 0))\n(defun lp ()\n (princ stk)\n (cond ((= (reduce #'+ stk) yen) (princ \"Yes\"))\n ((< (reduce #'+ stk) yen) (push 4 stk) (lp))\n ((= (first stk) 0) (princ \"No\"))\n ((= (pop stk) 4) (pop stk) (push 7 stk) (lp))\n (t (lp))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 10, "memory_kb": 3432}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s774900334", "group_id": "codeNet:p03760", "input_text": "(let((s(read-line))(u(read-line)))\n (loop for i from 0 to (1-(length s))do(princ(char s i))(if(< i(length u))(princ(char u i)))))", "language": "Lisp", "metadata": {"date": 1535014054, "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/s774900334.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s774900334", "user_id": "u657913472"}, "prompt_components": {"gold_output": "xaybzc\n", "input_to_evaluate": "(let((s(read-line))(u(read-line)))\n (loop for i from 0 to (1-(length s))do(princ(char s i))(if(< i(length u))(princ(char u i)))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 12, "memory_kb": 3560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s264826128", "group_id": "codeNet:p03760", "input_text": "(defun decrypt (o e)\n (labels ((inner-loop (now next acc)\n\t (if now\t\t \n\t\t (inner-loop next (cdr now) (cons (car now) acc))\n\t\t (coerce (reverse acc) 'string))))\n (inner-loop (coerce o 'list) (coerce e 'list) nil)))\n\n(let ((o (read-line))\n (e (read-line)))\n (format t \"~A~%\" (decrypt o e)))", "language": "Lisp", "metadata": {"date": 1491700498, "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/s264826128.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s264826128", "user_id": "u237110174"}, "prompt_components": {"gold_output": "xaybzc\n", "input_to_evaluate": "(defun decrypt (o e)\n (labels ((inner-loop (now next acc)\n\t (if now\t\t \n\t\t (inner-loop next (cdr now) (cons (car now) acc))\n\t\t (coerce (reverse acc) 'string))))\n (inner-loop (coerce o 'list) (coerce e 'list) nil)))\n\n(let ((o (read-line))\n (e (read-line)))\n (format t \"~A~%\" (decrypt o e)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 302, "cpu_time_ms": 46, "memory_kb": 6116}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s344804641", "group_id": "codeNet:p03761", "input_text": "(defun collector-mod (lst)\n (if lst\n (let* ((ans '())\n (mem (cons (car lst) 1)))\n (mapcar (lambda (k)\n (if (char= 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(let* ((lst (loop :repeat (read) :collect (sort (concatenate 'list (read-line)) #'char>))))\n (loop :for j\n :in (reduce (lambda (x y) (loop :for k :from 0 :upto 24 :collect (cons (car (elt x k)) (min (cdr (elt x k))\n (cdr (elt y k))))))\n (mapcar (lambda (ll)\n (loop :for k :from 97 :upto 122 :collect (let* ((s (position (code-char k) ll :key #'car :test #'char=)))\n (cons (code-char k) (if s (cdr (elt ll s)) 0))))) (mapcar #'collector-mod lst)))\n :do(loop :repeat (cdr j) :do(princ (car j)))))\n", "language": "Lisp", "metadata": {"date": 1573756016, "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/s344804641.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s344804641", "user_id": "u610490393"}, "prompt_components": {"gold_output": "aac\n", "input_to_evaluate": "(defun collector-mod (lst)\n (if lst\n (let* ((ans '())\n (mem (cons (car lst) 1)))\n (mapcar (lambda (k)\n (if (char= 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(let* ((lst (loop :repeat (read) :collect (sort (concatenate 'list (read-line)) #'char>))))\n (loop :for j\n :in (reduce (lambda (x y) (loop :for k :from 0 :upto 24 :collect (cons (car (elt x k)) (min (cdr (elt x k))\n (cdr (elt y k))))))\n (mapcar (lambda (ll)\n (loop :for k :from 97 :upto 122 :collect (let* ((s (position (code-char k) ll :key #'car :test #'char=)))\n (cons (code-char k) (if s (cdr (elt ll s)) 0))))) (mapcar #'collector-mod lst)))\n :do(loop :repeat (cdr j) :do(princ (car j)))))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1094, "cpu_time_ms": 154, "memory_kb": 16228}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s666643430", "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(define-alien-routine putchar_unlocked char (c char))\n\n(defmacro write-chars (string &optional (newline t))\n `(progn\n ,@(loop for c across string\n collect `(putchar_unlocked ,(char-code c)))\n ,@(when newline\n `((putchar_unlocked #.(char-code #\\Newline))))))\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 (the uint32 (- (aref cumuls b) (aref cumuls a))) 3)\n ;; (mod (the uint32 (- (aref cumult d) (aref cumult c))) 3))\n ;; (write-line \"YES\")\n ;; (write-line \"NO\")))))\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 (the uint32 (- (aref cumuls b) (aref cumuls a))) 3)\n (mod (the uint32 (- (aref cumult d) (aref cumult c))) 3))\n (write-chars \"YES\")\n (write-chars \"NO\"))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566762711, "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/s666643430.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s666643430", "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(define-alien-routine putchar_unlocked char (c char))\n\n(defmacro write-chars (string &optional (newline t))\n `(progn\n ,@(loop for c across string\n collect `(putchar_unlocked ,(char-code c)))\n ,@(when newline\n `((putchar_unlocked #.(char-code #\\Newline))))))\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 (the uint32 (- (aref cumuls b) (aref cumuls a))) 3)\n ;; (mod (the uint32 (- (aref cumult d) (aref cumult c))) 3))\n ;; (write-line \"YES\")\n ;; (write-line \"NO\")))))\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 (the uint32 (- (aref cumuls b) (aref cumuls a))) 3)\n (mod (the uint32 (- (aref cumult d) (aref cumult c))) 3))\n (write-chars \"YES\")\n (write-chars \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4622, "cpu_time_ms": 256, "memory_kb": 27236}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s676370823", "group_id": "codeNet:p03774", "input_text": "(let* ((n (read))\n (m (read))\n (lst1 (loop repeat n\n collect (cons (read) (read))))\n (lst2 (loop repeat m\n collect (cons (read) (read)))))\n\n (defun f (p q)\n (+ (abs (- (car p) (car q))) (abs (- (cdr p) (cdr q)))))\n\n\n (setq lst3\n (loop for i from 0 to (1- (length lst1))\n collect (loop for j from 0 to (1- (length lst2))\n collect (f (nth i lst1) (nth j lst2)))))\n\n (format t \"~{~A~%~}\"\n (loop for i in lst3\n collect (1+ (position (apply #'min i) i)))))\n\n", "language": "Lisp", "metadata": {"date": 1572742733, "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/s676370823.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s676370823", "user_id": "u336541610"}, "prompt_components": {"gold_output": "2\n1\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst1 (loop repeat n\n collect (cons (read) (read))))\n (lst2 (loop repeat m\n collect (cons (read) (read)))))\n\n (defun f (p q)\n (+ (abs (- (car p) (car q))) (abs (- (cdr p) (cdr q)))))\n\n\n (setq lst3\n (loop for i from 0 to (1- (length lst1))\n collect (loop for j from 0 to (1- (length lst2))\n collect (f (nth i lst1) (nth j lst2)))))\n\n (format t \"~{~A~%~}\"\n (loop for i in lst3\n collect (1+ (position (apply #'min i) i)))))\n\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 36, "memory_kb": 7140}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s472805643", "group_id": "codeNet:p03774", "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(defun manhattan-dis (a b c d)\n (declare (fixnum a b c d))\n (+ (abs (- a c)) (abs (- b d))))\n\n(defun read-data (p)\n (loop :for count :from 0 :below p\n :for line = (split-with (read-line t nil nil)) \n :for a = (parse-integer (car line))\n :for b = (parse-integer (car (cdr line)))\n :collect (cons a b)))\n\n(let* ((lst (split-with (read-line)))\n (n (parse-integer (car lst)))\n (m (parse-integer (car (cdr lst))))\n (ab-list (read-data n))\n (cd-list (read-data m)))\n (loop :for (a . b) :in ab-list\n :for min-dis = most-positive-fixnum\n :for min-index = 0\n :do (loop :for (c . d) :in cd-list\n :for count :upfrom 1\n :for dis = (manhattan-dis a b c d)\n :do (when (< dis min-dis)\n (progn (setf min-index count)\n (setf min-dis dis)))\n :finally (format t \"~d~%\" min-index))))\n", "language": "Lisp", "metadata": {"date": 1490578326, "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/s472805643.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s472805643", "user_id": "u690263481"}, "prompt_components": {"gold_output": "2\n1\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(defun manhattan-dis (a b c d)\n (declare (fixnum a b c d))\n (+ (abs (- a c)) (abs (- b d))))\n\n(defun read-data (p)\n (loop :for count :from 0 :below p\n :for line = (split-with (read-line t nil nil)) \n :for a = (parse-integer (car line))\n :for b = (parse-integer (car (cdr line)))\n :collect (cons a b)))\n\n(let* ((lst (split-with (read-line)))\n (n (parse-integer (car lst)))\n (m (parse-integer (car (cdr lst))))\n (ab-list (read-data n))\n (cd-list (read-data m)))\n (loop :for (a . b) :in ab-list\n :for min-dis = most-positive-fixnum\n :for min-index = 0\n :do (loop :for (c . d) :in cd-list\n :for count :upfrom 1\n :for dis = (manhattan-dis a b c d)\n :do (when (< dis min-dis)\n (progn (setf min-index count)\n (setf min-dis dis)))\n :finally (format t \"~d~%\" min-index))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1313, "cpu_time_ms": 134, "memory_kb": 15716}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s946544384", "group_id": "codeNet:p03775", "input_text": "(defun num-degit (n)\n (length (write-to-string n)))\n(let ((n (read))\n (a (expt 2 64)))\n (loop for i from 1 to (truncate (sqrt n)) do\n (when (= (mod n i) 0)\n (setf a (min a (max i (truncate n i))))))\n (princ (num-degit a)))\n", "language": "Lisp", "metadata": {"date": 1491750838, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s946544384.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s946544384", "user_id": "u231540466"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun num-degit (n)\n (length (write-to-string n)))\n(let ((n (read))\n (a (expt 2 64)))\n (loop for i from 1 to (truncate (sqrt n)) do\n (when (= (mod n i) 0)\n (setf a (min a (max i (truncate n i))))))\n (princ (num-degit a)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 20, "memory_kb": 4704}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s964083438", "group_id": "codeNet:p03778", "input_text": "(let ((w (read))\n (a (read))\n (b (read)))\n (if (> w (- a b))\n (princ 0)\n (princ (- b w a))\n ) \n)", "language": "Lisp", "metadata": {"date": 1595083279, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03778.html", "problem_id": "p03778", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03778/input.txt", "sample_output_relpath": "derived/input_output/data/p03778/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03778/Lisp/s964083438.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s964083438", "user_id": "u136500538"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(let ((w (read))\n (a (read))\n (b (read)))\n (if (> w (- a b))\n (princ 0)\n (princ (- b w a))\n ) \n)", "problem_context": "Score : 200 points\n\nProblem Statement\n\nAtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W.\nIf we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W], as shown in the following figure:\n\nAtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle.\nFind the minimum distance it needs to be moved.\n\nConstraints\n\nAll input values are integers.\n\n1≤W≤10^5\n\n1≤a,b≤10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nW a b\n\nOutput\n\nPrint the minimum distance the second rectangle needs to be moved.\n\nSample Input 1\n\n3 2 6\n\nSample Output 1\n\n1\n\nThis input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1.\n\nSample Input 2\n\n3 1 3\n\nSample Output 2\n\n0\n\nThe rectangles are already connected, and thus no move is needed.\n\nSample Input 3\n\n5 10 1\n\nSample Output 3\n\n4", "sample_input": "3 2 6\n"}, "reference_outputs": ["1\n"], "source_document_id": "p03778", "source_text": "Score : 200 points\n\nProblem Statement\n\nAtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W.\nIf we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W], as shown in the following figure:\n\nAtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle.\nFind the minimum distance it needs to be moved.\n\nConstraints\n\nAll input values are integers.\n\n1≤W≤10^5\n\n1≤a,b≤10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nW a b\n\nOutput\n\nPrint the minimum distance the second rectangle needs to be moved.\n\nSample Input 1\n\n3 2 6\n\nSample Output 1\n\n1\n\nThis input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1.\n\nSample Input 2\n\n3 1 3\n\nSample Output 2\n\n0\n\nThe rectangles are already connected, and thus no move is needed.\n\nSample Input 3\n\n5 10 1\n\nSample Output 3\n\n4", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 24080}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s214185283", "group_id": "codeNet:p03785", "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 (c (read))\n (k (read))\n (times (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (setf (aref times i) (read-fixnum)))\n (setq times (sort times #'<))\n (let ((init (aref times 0))\n (load 0)\n (res 1))\n (dotimes (i n)\n (let ((time (aref times i)))\n (when (or (> time (+ init k))\n (= load c))\n (incf res)\n (setq load 0\n init time))\n (incf load)))\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 \"5 3 5\n1\n2\n3\n6\n12\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 3 3\n7\n6\n2\n8\n10\n6\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1585533294, "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/s214185283.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s214185283", "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 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 (c (read))\n (k (read))\n (times (make-array n :element-type 'uint32)))\n (dotimes (i n)\n (setf (aref times i) (read-fixnum)))\n (setq times (sort times #'<))\n (let ((init (aref times 0))\n (load 0)\n (res 1))\n (dotimes (i n)\n (let ((time (aref times i)))\n (when (or (> time (+ init k))\n (= load c))\n (incf res)\n (setq load 0\n init time))\n (incf load)))\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 \"5 3 5\n1\n2\n3\n6\n12\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 3 3\n7\n6\n2\n8\n10\n6\n\"\n \"3\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5264, "cpu_time_ms": 152, "memory_kb": 13280}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s678589506", "group_id": "codeNet:p03785", "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-peek))\n(defun queue-peek (queue)\n (car (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 \"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 (inline sort))\n (let* ((n (read))\n (c (read))\n (k (read))\n (ts (make-array n :element-type 'uint31))\n (que (make-queue)) ; arrival . capacity\n (res 0))\n (declare (uint62 n c k res))\n (dotimes (i n)\n (setf (aref ts i) (read-fixnum)))\n (setq ts (sort ts #'<))\n (sb-int:dovector (time ts)\n (loop\n (when (queue-empty-p que)\n (enqueue (cons time c) que)\n (incf res)\n (return))\n (destructuring-bind (arr . cap) (queue-peek que)\n (declare (uint62 arr cap))\n (when (and (<= time (+ arr k))\n (> cap 0))\n (return))\n (dequeue que)))\n (decf (cdr (queue-peek que))))\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 \"5 3 5\n1\n2\n3\n6\n12\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 3 3\n7\n6\n2\n8\n10\n6\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1578112459, "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/s678589506.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s678589506", "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;;; 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-peek))\n(defun queue-peek (queue)\n (car (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 \"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 (inline sort))\n (let* ((n (read))\n (c (read))\n (k (read))\n (ts (make-array n :element-type 'uint31))\n (que (make-queue)) ; arrival . capacity\n (res 0))\n (declare (uint62 n c k res))\n (dotimes (i n)\n (setf (aref ts i) (read-fixnum)))\n (setq ts (sort ts #'<))\n (sb-int:dovector (time ts)\n (loop\n (when (queue-empty-p que)\n (enqueue (cons time c) que)\n (incf res)\n (return))\n (destructuring-bind (arr . cap) (queue-peek que)\n (declare (uint62 arr cap))\n (when (and (<= time (+ arr k))\n (> cap 0))\n (return))\n (dequeue que)))\n (decf (cdr (queue-peek que))))\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 \"5 3 5\n1\n2\n3\n6\n12\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 3 3\n7\n6\n2\n8\n10\n6\n\"\n \"3\n\")))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6830, "cpu_time_ms": 168, "memory_kb": 29284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s957057074", "group_id": "codeNet:p03785", "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(defun count-bus (n c k t-list)\n (declare (ignore n))\n (let ((t0 (aref t-list 0))\n (start-list nil))\n (loop\n :until (zerop (length t-list))\n :do (loop\n :for i :from (if (< (length t-list) c)\n (- (length t-list) 1)\n (- c 1)) :downto 0\n :when (<= (aref t-list i) (+ t0 k))\n :do (progn (push (aref t-list i) start-list)\n (setf t-list (subseq t-list (+ i 1)))\n (unless (zerop (length t-list))\n (setf t0 (aref t-list 0)))\n (loop-finish))))\n start-list))\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~%\" (length (count-bus n c k t-list))))\n", "language": "Lisp", "metadata": {"date": 1489370631, "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/s957057074.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s957057074", "user_id": "u690263481"}, "prompt_components": {"gold_output": "3\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(defun count-bus (n c k t-list)\n (declare (ignore n))\n (let ((t0 (aref t-list 0))\n (start-list nil))\n (loop\n :until (zerop (length t-list))\n :do (loop\n :for i :from (if (< (length t-list) c)\n (- (length t-list) 1)\n (- c 1)) :downto 0\n :when (<= (aref t-list i) (+ t0 k))\n :do (progn (push (aref t-list i) start-list)\n (setf t-list (subseq t-list (+ i 1)))\n (unless (zerop (length t-list))\n (setf t0 (aref t-list 0)))\n (loop-finish))))\n start-list))\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~%\" (length (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1490, "cpu_time_ms": 2104, "memory_kb": 83452}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s204741773", "group_id": "codeNet:p03785", "input_text": "(defun compute(c k lst)\n (labels ((rec (tt cc lst acc)\n (cond ((null lst) acc)\n ((zerop cc) (rec (car lst) (1- c) (cdr lst) (1+ acc)))\n ((<= tt (+ k (car lst))) (rec tt (1- cc) (cdr lst) acc))\n (t (rec (car lst) (1- c) (cdr lst) (1+ acc))))))\n (rec (car lst) (1- c) (cdr lst) 1)))\n(defun test()\n (format t \"~A~%\" (compute 2 5 (sort '(1 2 3 7 7 7 7 7 7 7 7 7 7 12) #'>)))\n (format t \"~A~%\" (compute 3 5 (sort '(1 2 3 7 7 7 7 7 7 7 7 7 7 12) #'>)))\n (format t \"~A~%\" (compute 3 5 (sort '(1 2 3 6 6 6 6 6 6 6 6 6 6 12) #'>)))\n (format t \"~A~%\" (compute 3 5 (sort '(1 2 3 6 6 6 6 6 6 12) #'>)))\n (format t \"~A~%\" (compute 3 5 (sort '(1 2 3 6 12) #'>)))\n (format t \"~A~%\" (compute 3 3 (sort '(7 6 2 8 10 6) #'>))))\n;(test)\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(cons line acc)))))\n\t(rec line nil)))\n(defun readline (callback)\n (labels ((rec (i)\n\t\t\t\t(let ((line (read-line nil nil)))\n\t\t\t\t (when (not (zerop (length line)))\n\t\t\t\t\t(funcall callback line i)\n\t\t\t\t\t(rec (1+ i))\n\t\t\t\t\t)\n\t\t\t\t )\n\t\t\t\t))\n\t(rec 0)))\n\n(let ((n 0)\n (c 0)\n (k 0)\n (lst nil))\n (defun start()\n (readline (lambda(line i)\n (cond ((zerop i) (let ((r (splitat #\\space line)))\n (setf n (parse-integer (nth 2 r)))\n (setf c (parse-integer (nth 1 r)))\n (setf k (parse-integer (nth 0 r)))))\n (t (setf lst (cons (parse-integer line) lst))))))\n (format t \"~A~%\" (compute c k (sort lst #'>)))))\n(start)", "language": "Lisp", "metadata": {"date": 1489369969, "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/s204741773.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s204741773", "user_id": "u254205055"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun compute(c k lst)\n (labels ((rec (tt cc lst acc)\n (cond ((null lst) acc)\n ((zerop cc) (rec (car lst) (1- c) (cdr lst) (1+ acc)))\n ((<= tt (+ k (car lst))) (rec tt (1- cc) (cdr lst) acc))\n (t (rec (car lst) (1- c) (cdr lst) (1+ acc))))))\n (rec (car lst) (1- c) (cdr lst) 1)))\n(defun test()\n (format t \"~A~%\" (compute 2 5 (sort '(1 2 3 7 7 7 7 7 7 7 7 7 7 12) #'>)))\n (format t \"~A~%\" (compute 3 5 (sort '(1 2 3 7 7 7 7 7 7 7 7 7 7 12) #'>)))\n (format t \"~A~%\" (compute 3 5 (sort '(1 2 3 6 6 6 6 6 6 6 6 6 6 12) #'>)))\n (format t \"~A~%\" (compute 3 5 (sort '(1 2 3 6 6 6 6 6 6 12) #'>)))\n (format t \"~A~%\" (compute 3 5 (sort '(1 2 3 6 12) #'>)))\n (format t \"~A~%\" (compute 3 3 (sort '(7 6 2 8 10 6) #'>))))\n;(test)\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(cons line acc)))))\n\t(rec line nil)))\n(defun readline (callback)\n (labels ((rec (i)\n\t\t\t\t(let ((line (read-line nil nil)))\n\t\t\t\t (when (not (zerop (length line)))\n\t\t\t\t\t(funcall callback line i)\n\t\t\t\t\t(rec (1+ i))\n\t\t\t\t\t)\n\t\t\t\t )\n\t\t\t\t))\n\t(rec 0)))\n\n(let ((n 0)\n (c 0)\n (k 0)\n (lst nil))\n (defun start()\n (readline (lambda(line i)\n (cond ((zerop i) (let ((r (splitat #\\space line)))\n (setf n (parse-integer (nth 2 r)))\n (setf c (parse-integer (nth 1 r)))\n (setf k (parse-integer (nth 0 r)))))\n (t (setf lst (cons (parse-integer line) lst))))))\n (format t \"~A~%\" (compute c k (sort lst #'>)))))\n(start)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1763, "cpu_time_ms": 199, "memory_kb": 43368}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s436895629", "group_id": "codeNet:p03786", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (as (make-array n :element-type 'uint62 :initial-element 0))\n (cumuls (make-array (+ n 1) :element-type 'uint62 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (setq as (sort as #'<))\n (dotimes (i n)\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (aref as i))))\n (loop for i from n downto 0\n when (< (* 2 (aref cumuls i)) (if (= n i) 0 (aref as i)))\n do (println (- n i))\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 \"3\n3 1 4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 1 1 1 1\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n40 1 30 2 7 20\n\"\n \"4\n\")))\n", "language": "Lisp", "metadata": {"date": 1585534184, "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/s436895629.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s436895629", "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(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 (inline sort))\n (let* ((n (read))\n (as (make-array n :element-type 'uint62 :initial-element 0))\n (cumuls (make-array (+ n 1) :element-type 'uint62 :initial-element 0)))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)))\n (setq as (sort as #'<))\n (dotimes (i n)\n (setf (aref cumuls (+ i 1))\n (+ (aref cumuls i) (aref as i))))\n (loop for i from n downto 0\n when (< (* 2 (aref cumuls i)) (if (= n i) 0 (aref as i)))\n do (println (- n i))\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 \"3\n3 1 4\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5\n1 1 1 1 1\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6\n40 1 30 2 7 20\n\"\n \"4\n\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5379, "cpu_time_ms": 282, "memory_kb": 32868}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s349704515", "group_id": "codeNet:p03786", "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 (inline sort))\n (let* ((n (read))\n (as (make-array n :element-type 'uint62))\n (base 0))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (setq as (sort as #'<))\n (dotimes (i (- n 1))\n (when (< (* 2 (aref as i)) (aref as (+ i 1)))\n (setq base (+ i 1)))\n (incf (aref as (+ i 1)) (aref as i)))\n (println (- n base))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1562379564, "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/s349704515.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s349704515", "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(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 (as (make-array n :element-type 'uint62))\n (base 0))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (setq as (sort as #'<))\n (dotimes (i (- n 1))\n (when (< (* 2 (aref as i)) (aref as (+ i 1)))\n (setq base (+ i 1)))\n (incf (aref as (+ i 1)) (aref as i)))\n (println (- n base))))\n\n#-swank(main)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 2820, "cpu_time_ms": 278, "memory_kb": 30820}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s832318675", "group_id": "codeNet:p03786", "input_text": "(defun compute(lst)\n (let ((lst (sort lst #'<)))\n (labels ((rec (lst sum)\n (cond ((null lst) t)\n ((<= (car lst) (* 2 sum)) (rec (cdr lst) (+ sum (car lst))))\n (t nil)))\n (rec0 (lst sum acc)\n (if (null lst)\n acc\n (if (rec (cdr lst) (+ sum (car lst)))\n (rec0 (cdr lst) (+ sum (car lst)) (1+ acc))\n (rec0 (cdr lst) (+ sum (car lst)) acc))))\n )\n (rec0 lst 0 0))))\n\n(defun test()\n (format t \"~A~%\" (compute '(3 1 4)))\n (format t \"~A~%\" (compute '(1 1 1 1 1)))\n (format t \"~A~%\" (compute '(40 1 30 2 7 20)))\n )\n;(test)\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(cons line acc)))))\n\t(rec line nil)))\n(defun readline (callback)\n (labels ((rec (i)\n\t\t\t\t(let ((line (read-line nil nil)))\n\t\t\t\t (when (not (zerop (length line)))\n\t\t\t\t\t(funcall callback line i)\n\t\t\t\t\t(rec (1+ i))\n\t\t\t\t\t)\n\t\t\t\t )\n\t\t\t\t))\n\t(rec 0)))\n\n(let ((n 0)\n (lst nil))\n (defun start()\n (readline (lambda(line i)\n (cond ((zerop i) (setf n (parse-integer line)))\n (t (setf lst (nreverse (mapcar #'parse-integer (splitat #\\space line))))))))\n (format t \"~A~%\" (compute lst))))\n(start)", "language": "Lisp", "metadata": {"date": 1489371298, "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/s832318675.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s832318675", "user_id": "u254205055"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(defun compute(lst)\n (let ((lst (sort lst #'<)))\n (labels ((rec (lst sum)\n (cond ((null lst) t)\n ((<= (car lst) (* 2 sum)) (rec (cdr lst) (+ sum (car lst))))\n (t nil)))\n (rec0 (lst sum acc)\n (if (null lst)\n acc\n (if (rec (cdr lst) (+ sum (car lst)))\n (rec0 (cdr lst) (+ sum (car lst)) (1+ acc))\n (rec0 (cdr lst) (+ sum (car lst)) acc))))\n )\n (rec0 lst 0 0))))\n\n(defun test()\n (format t \"~A~%\" (compute '(3 1 4)))\n (format t \"~A~%\" (compute '(1 1 1 1 1)))\n (format t \"~A~%\" (compute '(40 1 30 2 7 20)))\n )\n;(test)\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(cons line acc)))))\n\t(rec line nil)))\n(defun readline (callback)\n (labels ((rec (i)\n\t\t\t\t(let ((line (read-line nil nil)))\n\t\t\t\t (when (not (zerop (length line)))\n\t\t\t\t\t(funcall callback line i)\n\t\t\t\t\t(rec (1+ i))\n\t\t\t\t\t)\n\t\t\t\t )\n\t\t\t\t))\n\t(rec 0)))\n\n(let ((n 0)\n (lst nil))\n (defun start()\n (readline (lambda(line i)\n (cond ((zerop i) (setf n (parse-integer line)))\n (t (setf lst (nreverse (mapcar #'parse-integer (splitat #\\space line))))))))\n (format t \"~A~%\" (compute lst))))\n(start)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1445, "cpu_time_ms": 2105, "memory_kb": 112616}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s397242937", "group_id": "codeNet:p03796", "input_text": "(defparameter *n* (read))\n\n(defun fact (x a)\n (if (= x 0)\n a\n (fact (- x 1) (* a x))))\n\n\n(defparameter *ans* (mod (fact *n* 1) (+ 7 (expt 10 9))))\n\n(princ *ans*)", "language": "Lisp", "metadata": {"date": 1487471979, "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/s397242937.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s397242937", "user_id": "u678875535"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defparameter *n* (read))\n\n(defun fact (x a)\n (if (= x 0)\n a\n (fact (- x 1) (* a x))))\n\n\n(defparameter *ans* (mod (fact *n* 1) (+ 7 (expt 10 9))))\n\n(princ *ans*)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 2104, "memory_kb": 104804}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s136753839", "group_id": "codeNet:p03797", "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 (m (read))\n (base (min n (floor m 2))))\n (let ((m (- m (* 2 base))))\n (println (+ base (floor m 4))))))\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 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"12345 678901\n\"\n \"175897\n\")))\n", "language": "Lisp", "metadata": {"date": 1578202763, "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/s136753839.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s136753839", "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 (m (read))\n (base (min n (floor m 2))))\n (let ((m (- m (* 2 base))))\n (println (+ base (floor m 4))))))\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 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"12345 678901\n\"\n \"175897\n\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3827, "cpu_time_ms": 28, "memory_kb": 8552}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s784113822", "group_id": "codeNet:p03797", "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 (m (read))\n (base (min n (floor m 2))))\n (if (< base n)\n base\n (let ((m (- m (* 2 base))))\n (println (+ base (floor m 4)))))))\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 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"12345 678901\n\"\n \"175897\n\")))\n", "language": "Lisp", "metadata": {"date": 1578202712, "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/s784113822.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s784113822", "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 (m (read))\n (base (min n (floor m 2))))\n (if (< base n)\n base\n (let ((m (- m (* 2 base))))\n (println (+ base (floor m 4)))))))\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 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"12345 678901\n\"\n \"175897\n\")))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3868, "cpu_time_ms": 178, "memory_kb": 18408}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s337994161", "group_id": "codeNet:p03797", "input_text": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(print (trucate (/ (+ (* (read) 2)\n (read))\n 4)))\n(terpri)\n", "language": "Lisp", "metadata": {"date": 1487792998, "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/s337994161.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s337994161", "user_id": "u328322317"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(print (trucate (/ (+ (* (read) 2)\n (read))\n 4)))\n(terpri)\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 149, "memory_kb": 12516}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s106350121", "group_id": "codeNet:p03798", "input_text": "(defun foo (n s l)\n (loop for i from 1 upto n\n for animal = (char l i)\n if (eq animal #\\S)\n do (if (eq (aref s (1- i)) #\\o)\n (setf (aref l (1+ i)) (aref l (1- i)))\n (setf (aref l (1+ i)) (if (eq (aref l (1- i)) #\\S)\n #\\W\n #\\S)))\n else\n do (if (eq (aref s (1- i)) #\\o)\n (setf (aref l (1+ i)) (if (eq (aref l (1- i)) #\\S)\n #\\W\n #\\S))\n (setf (aref l (1+ i)) (aref l (1- i)))))\n l)\n\n(let* ((n (parse-integer (read-line)))\n (s (read-line))\n (l1 (make-array (+ n 2) :element-type 'character :initial-element #\\S))\n (l2 (make-array (+ n 2) :element-type 'character :initial-element #\\W)))\n (setf l1 (foo n s l1))\n (setf l2 (foo n s l2))\n (if (eq (aref l1 0) (aref l1 (1+ n)))\n (format t \"~A~%\" (subseq l1 1 (1+ n)))\n (if (eq (aref l2 0) (aref l2 (1+ n)))\n (format t \"~A~%\" (subseq l2 1 (1+ n)))\n (format t \"-1~%\"))))", "language": "Lisp", "metadata": {"date": 1487474342, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03798.html", "problem_id": "p03798", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03798/input.txt", "sample_output_relpath": "derived/input_output/data/p03798/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03798/Lisp/s106350121.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s106350121", "user_id": "u275710783"}, "prompt_components": {"gold_output": "SSSWWS\n", "input_to_evaluate": "(defun foo (n s l)\n (loop for i from 1 upto n\n for animal = (char l i)\n if (eq animal #\\S)\n do (if (eq (aref s (1- i)) #\\o)\n (setf (aref l (1+ i)) (aref l (1- i)))\n (setf (aref l (1+ i)) (if (eq (aref l (1- i)) #\\S)\n #\\W\n #\\S)))\n else\n do (if (eq (aref s (1- i)) #\\o)\n (setf (aref l (1+ i)) (if (eq (aref l (1- i)) #\\S)\n #\\W\n #\\S))\n (setf (aref l (1+ i)) (aref l (1- i)))))\n l)\n\n(let* ((n (parse-integer (read-line)))\n (s (read-line))\n (l1 (make-array (+ n 2) :element-type 'character :initial-element #\\S))\n (l2 (make-array (+ n 2) :element-type 'character :initial-element #\\W)))\n (setf l1 (foo n s l1))\n (setf l2 (foo n s l2))\n (if (eq (aref l1 0) (aref l1 (1+ n)))\n (format t \"~A~%\" (subseq l1 1 (1+ n)))\n (if (eq (aref l2 0) (aref l2 (1+ n)))\n (format t \"~A~%\" (subseq l2 1 (1+ n)))\n (format t \"-1~%\"))))", "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": "p03798", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1111, "cpu_time_ms": 518, "memory_kb": 19300}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s681139226", "group_id": "codeNet:p03803", "input_text": "(let ((a (read))\n (b (read)))\n\n (defun judge (x y)\n (cond ((= x y) \"Draw\")\n ((= x 1) \"Alice\")\n ((= y 1) \"Bob\")\n ((< x y) \"Bob\")\n (t \"Alice\")))\n\n (format t \"~A~%\"\n (judge a b)))\n", "language": "Lisp", "metadata": {"date": 1594687603, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s681139226.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s681139226", "user_id": "u336541610"}, "prompt_components": {"gold_output": "Alice\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n\n (defun judge (x y)\n (cond ((= x y) \"Draw\")\n ((= x 1) \"Alice\")\n ((= y 1) \"Bob\")\n ((< x y) \"Bob\")\n (t \"Alice\")))\n\n (format t \"~A~%\"\n (judge a b)))\n", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 18, "memory_kb": 23388}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s107568424", "group_id": "codeNet:p03804", "input_text": "(let* ((n (read))\n (m (read))\n (shift (- n m))\n (a (make-array n))\n (b (make-array m))\n (matchp nil))\n (dotimes (i n)\n (setf (aref a i) (read-line)))\n (dotimes (i m)\n (setf (aref b i) (read-line)))\n (dotimes (y (1+ shift))\n (dotimes (x (1+ shift))\n (setf matchp\n (loop for i from 0 below m always\n (loop for j from 0 below m always\n (eq (char (aref b i) j)\n (char (aref a (+ i y)) (+ j x))))))))\n (format t \"~A~%\" (if matchp \"Yes\" \"No\")))", "language": "Lisp", "metadata": {"date": 1512411161, "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/s107568424.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s107568424", "user_id": "u275710783"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (shift (- n m))\n (a (make-array n))\n (b (make-array m))\n (matchp nil))\n (dotimes (i n)\n (setf (aref a i) (read-line)))\n (dotimes (i m)\n (setf (aref b i) (read-line)))\n (dotimes (y (1+ shift))\n (dotimes (x (1+ shift))\n (setf matchp\n (loop for i from 0 below m always\n (loop for j from 0 below m always\n (eq (char (aref b i) j)\n (char (aref a (+ i y)) (+ j x))))))))\n (format t \"~A~%\" (if matchp \"Yes\" \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 564, "cpu_time_ms": 33, "memory_kb": 6756}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s030716060", "group_id": "codeNet:p03804", "input_text": "(let* ((n (read))\n (m (read))\n (shift (- n m))\n (a (make-array n))\n (b (make-array m))\n (matchp nil))\n (dotimes (i n)\n (setf (aref a i) (read-line)))\n (dotimes (i m)\n (setf (aref b i) (read-line)))\n (dotimes (y shift)\n (dotimes (x shift)\n (setf matchp\n (loop for i from 0 below m always\n (loop for j from 0 below m always\n (eq (char (aref b i) j)\n (char (aref a (+ i y)) (+ j x))))))))\n (format t \"~A~%\" (if matchp \"Yes\" \"No\")))", "language": "Lisp", "metadata": {"date": 1512410968, "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/s030716060.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s030716060", "user_id": "u275710783"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (shift (- n m))\n (a (make-array n))\n (b (make-array m))\n (matchp nil))\n (dotimes (i n)\n (setf (aref a i) (read-line)))\n (dotimes (i m)\n (setf (aref b i) (read-line)))\n (dotimes (y shift)\n (dotimes (x shift)\n (setf matchp\n (loop for i from 0 below m always\n (loop for j from 0 below m always\n (eq (char (aref b i) j)\n (char (aref a (+ i y)) (+ j x))))))))\n (format t \"~A~%\" (if matchp \"Yes\" \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 31, "memory_kb": 6756}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s384323745", "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 (declare (ignore m))\n (dotimes (i n)\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)))", "language": "Lisp", "metadata": {"date": 1512409668, "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/s384323745.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s384323745", "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 (declare (ignore m))\n (dotimes (i n)\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)))", "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(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 (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (res 0))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (loop for i from (- n 1) downto 0\n for a = (+ (aref as i) res)\n for b = (aref bs i)\n for dest = (* b (ceiling a b))\n do (incf res (- dest a)))\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\n3 5\n2 7\n9 4\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n3 1\n4 1\n5 9\n2 6\n5 3\n5 8\n9 7\n\"\n \"22\n\")))\n", "language": "Lisp", "metadata": {"date": 1578125655, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03821.html", "problem_id": "p03821", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03821/input.txt", "sample_output_relpath": "derived/input_output/data/p03821/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03821/Lisp/s236724685.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s236724685", "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 ;; 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 (as (make-array n :element-type 'uint31))\n (bs (make-array n :element-type 'uint31))\n (res 0))\n (dotimes (i n)\n (setf (aref as i) (read-fixnum)\n (aref bs i) (read-fixnum)))\n (loop for i from (- n 1) downto 0\n for a = (+ (aref as i) res)\n for b = (aref bs i)\n for dest = (* b (ceiling a b))\n do (incf res (- dest a)))\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\n3 5\n2 7\n9 4\n\"\n \"7\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n3 1\n4 1\n5 9\n2 6\n5 3\n5 8\n9 7\n\"\n \"22\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are an integer sequence A_1,...,A_N consisting of N terms, and N buttons.\nWhen the i-th (1 ≦ i ≦ N) button is pressed, the values of the i terms from the first through the i-th are all incremented by 1.\n\nThere is also another integer sequence B_1,...,B_N. Takahashi will push the buttons some number of times so that for every i, A_i will be a multiple of B_i.\n\nFind the minimum number of times Takahashi will press the buttons.\n\nConstraints\n\nAll input values are integers.\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9(1 ≦ i ≦ N)\n\n1 ≦ B_i ≦ 10^9(1 ≦ i ≦ N)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_N B_N\n\nOutput\n\nPrint an integer representing the minimum number of times Takahashi will press the buttons.\n\nSample Input 1\n\n3\n3 5\n2 7\n9 4\n\nSample Output 1\n\n7\n\nPress the first button twice, the second button twice and the third button three times.\n\nSample Input 2\n\n7\n3 1\n4 1\n5 9\n2 6\n5 3\n5 8\n9 7\n\nSample Output 2\n\n22", "sample_input": "3\n3 5\n2 7\n9 4\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03821", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are an integer sequence A_1,...,A_N consisting of N terms, and N buttons.\nWhen the i-th (1 ≦ i ≦ N) button is pressed, the values of the i terms from the first through the i-th are all incremented by 1.\n\nThere is also another integer sequence B_1,...,B_N. Takahashi will push the buttons some number of times so that for every i, A_i will be a multiple of B_i.\n\nFind the minimum number of times Takahashi will press the buttons.\n\nConstraints\n\nAll input values are integers.\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9(1 ≦ i ≦ N)\n\n1 ≦ B_i ≦ 10^9(1 ≦ i ≦ N)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_N B_N\n\nOutput\n\nPrint an integer representing the minimum number of times Takahashi will press the buttons.\n\nSample Input 1\n\n3\n3 5\n2 7\n9 4\n\nSample Output 1\n\n7\n\nPress the first button twice, the second button twice and the third button three times.\n\nSample Input 2\n\n7\n3 1\n4 1\n5 9\n2 6\n5 3\n5 8\n9 7\n\nSample Output 2\n\n22", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5314, "cpu_time_ms": 109, "memory_kb": 13412}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s192507269", "group_id": "codeNet:p03821", "input_text": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(defun input (n)\n (let ((a (make-array 1 :element-type 'fixnum\n :fill-pointer 0\n :adjustable t))\n (b (make-array 1 :element-type 'fixnum\n :fill-pointer 0\n :adjustable t)))\n (dotimes (i n)\n (progn\n (vector-push-extend (read) a)\n (vector-push-extend (read) b)))\n (values a b)))\n\n(let ((n (read))\n (c 0))\n (multiple-value-bind (an bn) (input n)\n (loop for i from 0 below n\n for a = (aref an (- n i 1)) for b = (aref bn (- n i 1)) \n do (setq c (+ (mod (- b (mod (+ a c) b)) b) c))))\n (format t \"~A~%\" c))", "language": "Lisp", "metadata": {"date": 1521757550, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03821.html", "problem_id": "p03821", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03821/input.txt", "sample_output_relpath": "derived/input_output/data/p03821/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03821/Lisp/s192507269.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s192507269", "user_id": "u672956630"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(defun input (n)\n (let ((a (make-array 1 :element-type 'fixnum\n :fill-pointer 0\n :adjustable t))\n (b (make-array 1 :element-type 'fixnum\n :fill-pointer 0\n :adjustable t)))\n (dotimes (i n)\n (progn\n (vector-push-extend (read) a)\n (vector-push-extend (read) b)))\n (values a b)))\n\n(let ((n (read))\n (c 0))\n (multiple-value-bind (an bn) (input n)\n (loop for i from 0 below n\n for a = (aref an (- n i 1)) for b = (aref bn (- n i 1)) \n do (setq c (+ (mod (- b (mod (+ a c) b)) b) c))))\n (format t \"~A~%\" c))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are an integer sequence A_1,...,A_N consisting of N terms, and N buttons.\nWhen the i-th (1 ≦ i ≦ N) button is pressed, the values of the i terms from the first through the i-th are all incremented by 1.\n\nThere is also another integer sequence B_1,...,B_N. Takahashi will push the buttons some number of times so that for every i, A_i will be a multiple of B_i.\n\nFind the minimum number of times Takahashi will press the buttons.\n\nConstraints\n\nAll input values are integers.\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9(1 ≦ i ≦ N)\n\n1 ≦ B_i ≦ 10^9(1 ≦ i ≦ N)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_N B_N\n\nOutput\n\nPrint an integer representing the minimum number of times Takahashi will press the buttons.\n\nSample Input 1\n\n3\n3 5\n2 7\n9 4\n\nSample Output 1\n\n7\n\nPress the first button twice, the second button twice and the third button three times.\n\nSample Input 2\n\n7\n3 1\n4 1\n5 9\n2 6\n5 3\n5 8\n9 7\n\nSample Output 2\n\n22", "sample_input": "3\n3 5\n2 7\n9 4\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03821", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are an integer sequence A_1,...,A_N consisting of N terms, and N buttons.\nWhen the i-th (1 ≦ i ≦ N) button is pressed, the values of the i terms from the first through the i-th are all incremented by 1.\n\nThere is also another integer sequence B_1,...,B_N. Takahashi will push the buttons some number of times so that for every i, A_i will be a multiple of B_i.\n\nFind the minimum number of times Takahashi will press the buttons.\n\nConstraints\n\nAll input values are integers.\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9(1 ≦ i ≦ N)\n\n1 ≦ B_i ≦ 10^9(1 ≦ i ≦ N)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_N B_N\n\nOutput\n\nPrint an integer representing the minimum number of times Takahashi will press the buttons.\n\nSample Input 1\n\n3\n3 5\n2 7\n9 4\n\nSample Output 1\n\n7\n\nPress the first button twice, the second button twice and the third button three times.\n\nSample Input 2\n\n7\n3 1\n4 1\n5 9\n2 6\n5 3\n5 8\n9 7\n\nSample Output 2\n\n22", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 682, "memory_kb": 69480}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s109249310", "group_id": "codeNet:p03821", "input_text": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(defun input (n)\n (let ((a (make-array 1 :element-type 'fixnum\n :fill-pointer 0\n :adjustable t))\n (b (make-array 1 :element-type 'fixnum\n :fill-pointer 0\n :adjustable t)))\n (dotimes (i n)\n (progn\n (vector-push-extend (read) a)\n (vector-push-extend (read) b)))\n (values a b)))\n\n(let ((n (read))\n (c 0))\n (multiple-value-bind (an bn) (input n)\n (loop for i from 0 below n\n for a = (aref an (- n i 1)) for b = (aref bn (- n i 1)) for x = 0\n do (progn\n (setq a (+ a c))\n (loop while (not (= (mod (+ a x) b) 0))\n do (setq x (1+ x)))\n (setq c (+ c x)))))\n (format t \"~A~%\" c))", "language": "Lisp", "metadata": {"date": 1521757082, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03821.html", "problem_id": "p03821", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03821/input.txt", "sample_output_relpath": "derived/input_output/data/p03821/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03821/Lisp/s109249310.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s109249310", "user_id": "u672956630"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n(defun input (n)\n (let ((a (make-array 1 :element-type 'fixnum\n :fill-pointer 0\n :adjustable t))\n (b (make-array 1 :element-type 'fixnum\n :fill-pointer 0\n :adjustable t)))\n (dotimes (i n)\n (progn\n (vector-push-extend (read) a)\n (vector-push-extend (read) b)))\n (values a b)))\n\n(let ((n (read))\n (c 0))\n (multiple-value-bind (an bn) (input n)\n (loop for i from 0 below n\n for a = (aref an (- n i 1)) for b = (aref bn (- n i 1)) for x = 0\n do (progn\n (setq a (+ a c))\n (loop while (not (= (mod (+ a x) b) 0))\n do (setq x (1+ x)))\n (setq c (+ c x)))))\n (format t \"~A~%\" c))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are an integer sequence A_1,...,A_N consisting of N terms, and N buttons.\nWhen the i-th (1 ≦ i ≦ N) button is pressed, the values of the i terms from the first through the i-th are all incremented by 1.\n\nThere is also another integer sequence B_1,...,B_N. Takahashi will push the buttons some number of times so that for every i, A_i will be a multiple of B_i.\n\nFind the minimum number of times Takahashi will press the buttons.\n\nConstraints\n\nAll input values are integers.\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9(1 ≦ i ≦ N)\n\n1 ≦ B_i ≦ 10^9(1 ≦ i ≦ N)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_N B_N\n\nOutput\n\nPrint an integer representing the minimum number of times Takahashi will press the buttons.\n\nSample Input 1\n\n3\n3 5\n2 7\n9 4\n\nSample Output 1\n\n7\n\nPress the first button twice, the second button twice and the third button three times.\n\nSample Input 2\n\n7\n3 1\n4 1\n5 9\n2 6\n5 3\n5 8\n9 7\n\nSample Output 2\n\n22", "sample_input": "3\n3 5\n2 7\n9 4\n"}, "reference_outputs": ["7\n"], "source_document_id": "p03821", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are an integer sequence A_1,...,A_N consisting of N terms, and N buttons.\nWhen the i-th (1 ≦ i ≦ N) button is pressed, the values of the i terms from the first through the i-th are all incremented by 1.\n\nThere is also another integer sequence B_1,...,B_N. Takahashi will push the buttons some number of times so that for every i, A_i will be a multiple of B_i.\n\nFind the minimum number of times Takahashi will press the buttons.\n\nConstraints\n\nAll input values are integers.\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9(1 ≦ i ≦ N)\n\n1 ≦ B_i ≦ 10^9(1 ≦ i ≦ N)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\nA_1 B_1\n:\nA_N B_N\n\nOutput\n\nPrint an integer representing the minimum number of times Takahashi will press the buttons.\n\nSample Input 1\n\n3\n3 5\n2 7\n9 4\n\nSample Output 1\n\n7\n\nPress the first button twice, the second button twice and the third button three times.\n\nSample Input 2\n\n7\n3 1\n4 1\n5 9\n2 6\n5 3\n5 8\n9 7\n\nSample Output 2\n\n22", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 817, "cpu_time_ms": 2105, "memory_kb": 61796}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s552711544", "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 (push i (aref graph (- (read-fixnum) 1))))\n (println\n (with-cache (:array (n) :element-type 'uint32 :initial-element #xffffffff)\n (sb-int:named-let recur ((v 0))\n (loop for i of-type uint32 from 0\n for child in (sort (aref graph v) #'> :key #'recur)\n maximize (+ i 1 (recur child))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563180725, "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/s552711544.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s552711544", "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 (push i (aref graph (- (read-fixnum) 1))))\n (println\n (with-cache (:array (n) :element-type 'uint32 :initial-element #xffffffff)\n (sb-int:named-let recur ((v 0))\n (loop for i of-type uint32 from 0\n for child in (sort (aref graph v) #'> :key #'recur)\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)) (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)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,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 (with-cache (:array (n) :element-type 'uint32 :initial-element #xffffffff)\n (labels ((recur (v)\n (declare (values uint32))\n (if (null (aref graph v))\n 0\n (progn\n (setf (aref graph v)\n (sort (aref graph v)\n (lambda (x y) (> (the uint32 x) (the uint32 y)))\n :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 (println (recur 0))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563082742, "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/s659428202.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s659428202", "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)\n (destructuring-bind (_ name bindings &body body) def-form\n (declare (ignore _))\n `(let ((,cache ,cache-form))\n (nlet ,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 (with-cache (:array (n) :element-type 'uint32 :initial-element #xffffffff)\n (labels ((recur (v)\n (declare (values uint32))\n (if (null (aref graph v))\n 0\n (progn\n (setf (aref graph v)\n (sort (aref graph v)\n (lambda (x y) (> (the uint32 x) (the uint32 y)))\n :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 (println (recur 0))))))\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)) (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(defconstant +mod+ 1000000007)\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n(defconstant +binom-size+ 1001)\n(defconstant +binom-mod+ +mod+)\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 (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;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\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 corresponding\n;; value to a hash-table when evaluating (ADD A B) for the first time; ADD\n;; returns the stored value when it is called with the same arguments\n;; (w.r.t. EQUAL) again.\n;;\n;; The storage for the cache can be hash-table or array. Let's see an example\n;; for array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form caches 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 doesn't take.)\n;;\n;; If you want to ignore some arguments, you can use `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; => 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 debug the memoized function by :DEBUG option:\n;; (with-cache (:array (10 10) :initial-element -1 :debug 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(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY\"\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dimensions-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\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 (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 \"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 ((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 #+sbcl 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(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;;;\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)\n (lambda (x y) (mod (+ x y) ,divisor)))\n \n (define-modify-macro mulfmod (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-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (a (read))\n (b (read))\n (c (read))\n (d (read)))\n (declare (uint16 n a b c d))\n (with-cache (:array (1001 1001) :initial-element #xffffffff :element-type 'uint32)\n (labels\n ((recur (x y)\n (declare (uint16 x y))\n (cond ((zerop x) 1)\n ((< y a) 0)\n (t\n (let ((res (recur x (- y 1)))\n (factor 1))\n (declare (uint32 res factor))\n (loop for i from 0 below (- c 1)\n while (<= (* i y) x)\n do (mulfmod factor (binom (- x (* i y)) y)))\n (loop for k from c to d\n while (<= (* k y) x)\n do (mulfmod factor (binom (- x (* (- k 1) y)) y))\n (incfmod res\n (mod* (recur (- x (* k y)) (- y 1))\n factor\n (aref *fact-inv* k))))\n res)))))\n (println (recur n b))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1565312187, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03832.html", "problem_id": "p03832", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03832/input.txt", "sample_output_relpath": "derived/input_output/data/p03832/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03832/Lisp/s918654092.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s918654092", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\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(defconstant +mod+ 1000000007)\n\n;;;\n;;; Binomial coefficient with mod\n;;; build: O(n)\n;;; query: O(1)\n;;;\n\n(defconstant +binom-size+ 1001)\n(defconstant +binom-mod+ +mod+)\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 (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;;; Memoization macro\n;;;\n\n;;\n;; Basic usage:\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 corresponding\n;; value to a hash-table when evaluating (ADD A B) for the first time; ADD\n;; returns the stored value when it is called with the same arguments\n;; (w.r.t. EQUAL) again.\n;;\n;; The storage for the cache can be hash-table or array. Let's see an example\n;; for array:\n;; (with-cache (:array (10 20 30) :initial-element -1 :element-type 'fixnum)\n;; (defun foo (a b c) ... ))\n;; This form caches 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 doesn't take.)\n;;\n;; If you want to ignore some arguments, you can use `*' in dimensions:\n;; (with-cache (:array (10 10 * 10) :initial-element -1)\n;; (defun foo (a b c d) ...)) ; => 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 debug the memoized function by :DEBUG option:\n;; (with-cache (:array (10 10) :initial-element -1 :debug 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(defmacro with-cache ((cache-type &rest cache-attribs) def-form)\n \"CACHE-TYPE := :HASH-TABLE | :ARRAY\"\n (assert (member cache-type '(:hash-table :array)))\n (let* ((dimensions-with-* (when (eql cache-type :array) (first cache-attribs)))\n (dimensions (remove '* dimensions-with-*))\n (rank (length dimensions))\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 (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 \"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 ((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 #+sbcl 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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(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;;;\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)\n (lambda (x y) (mod (+ x y) ,divisor)))\n \n (define-modify-macro mulfmod (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-mod-operations +mod+)\n\n(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (a (read))\n (b (read))\n (c (read))\n (d (read)))\n (declare (uint16 n a b c d))\n (with-cache (:array (1001 1001) :initial-element #xffffffff :element-type 'uint32)\n (labels\n ((recur (x y)\n (declare (uint16 x y))\n (cond ((zerop x) 1)\n ((< y a) 0)\n (t\n (let ((res (recur x (- y 1)))\n (factor 1))\n (declare (uint32 res factor))\n (loop for i from 0 below (- c 1)\n while (<= (* i y) x)\n do (mulfmod factor (binom (- x (* i y)) y)))\n (loop for k from c to d\n while (<= (* k y) x)\n do (mulfmod factor (binom (- x (* (- k 1) y)) y))\n (incfmod res\n (mod* (recur (- x (* k y)) (- y 1))\n factor\n (aref *fact-inv* k))))\n res)))))\n (println (recur n b))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nThere are N people, conveniently numbered 1 through N.\nWe want to divide them into some number of groups, under the following two conditions:\n\nEvery group contains between A and B people, inclusive.\n\nLet F_i be the number of the groups containing exactly i people. Then, for all i, either F_i=0 or C≤F_i≤D holds.\n\nFind the number of these ways to divide the people into groups.\nHere, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways.\nSince the number of these ways can be extremely large, print the count modulo 10^9+7.\n\nConstraints\n\n1≤N≤10^3\n\n1≤A≤B≤N\n\n1≤C≤D≤N\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN A B C D\n\nOutput\n\nPrint the number of ways to divide the people into groups under the conditions, modulo 10^9+7.\n\nSample Input 1\n\n3 1 3 1 2\n\nSample Output 1\n\n4\n\nThere are four ways to divide the people:\n\n(1,2),(3)\n\n(1,3),(2)\n\n(2,3),(1)\n\n(1,2,3)\n\nThe following way to divide the people does not count: (1),(2),(3). This is because it only satisfies the first condition and not the second.\n\nSample Input 2\n\n7 2 3 1 3\n\nSample Output 2\n\n105\n\nThe only ways to divide the people under the conditions are the ones where there are two groups of two people, and one group of three people.\nThere are 105 such ways.\n\nSample Input 3\n\n1000 1 1000 1 1000\n\nSample Output 3\n\n465231251\n\nSample Input 4\n\n10 3 4 2 5\n\nSample Output 4\n\n0\n\nThe answer can be 0.", "sample_input": "3 1 3 1 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03832", "source_text": "Score : 600 points\n\nProblem Statement\n\nThere are N people, conveniently numbered 1 through N.\nWe want to divide them into some number of groups, under the following two conditions:\n\nEvery group contains between A and B people, inclusive.\n\nLet F_i be the number of the groups containing exactly i people. Then, for all i, either F_i=0 or C≤F_i≤D holds.\n\nFind the number of these ways to divide the people into groups.\nHere, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways.\nSince the number of these ways can be extremely large, print the count modulo 10^9+7.\n\nConstraints\n\n1≤N≤10^3\n\n1≤A≤B≤N\n\n1≤C≤D≤N\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN A B C D\n\nOutput\n\nPrint the number of ways to divide the people into groups under the conditions, modulo 10^9+7.\n\nSample Input 1\n\n3 1 3 1 2\n\nSample Output 1\n\n4\n\nThere are four ways to divide the people:\n\n(1,2),(3)\n\n(1,3),(2)\n\n(2,3),(1)\n\n(1,2,3)\n\nThe following way to divide the people does not count: (1),(2),(3). This is because it only satisfies the first condition and not the second.\n\nSample Input 2\n\n7 2 3 1 3\n\nSample Output 2\n\n105\n\nThe only ways to divide the people under the conditions are the ones where there are two groups of two people, and one group of three people.\nThere are 105 such ways.\n\nSample Input 3\n\n1000 1 1000 1 1000\n\nSample Output 3\n\n465231251\n\nSample Input 4\n\n10 3 4 2 5\n\nSample Output 4\n\n0\n\nThe answer can be 0.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13289, "cpu_time_ms": 299, "memory_kb": 45416}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s057303273", "group_id": "codeNet:p03834", "input_text": "(princ(substitute #\\ #\\,(read-line)))", "language": "Lisp", "metadata": {"date": 1528263297, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03834.html", "problem_id": "p03834", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03834/input.txt", "sample_output_relpath": "derived/input_output/data/p03834/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03834/Lisp/s057303273.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s057303273", "user_id": "u657913472"}, "prompt_components": {"gold_output": "happy newyear enjoy\n", "input_to_evaluate": "(princ(substitute #\\ #\\,(read-line)))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nAs a New Year's gift, Dolphin received a string s of length 19.\n\nThe string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters].\n\nDolphin wants to convert the comma-separated string s into a space-separated string.\n\nWrite a program to perform the conversion for him.\n\nConstraints\n\nThe length of s is 19.\n\nThe sixth and fourteenth characters in s are ,.\n\nThe other characters in s are lowercase English letters.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string after the conversion.\n\nSample Input 1\n\nhappy,newyear,enjoy\n\nSample Output 1\n\nhappy newyear enjoy\n\nReplace all the commas in happy,newyear,enjoy with spaces to obtain happy newyear enjoy.\n\nSample Input 2\n\nhaiku,atcoder,tasks\n\nSample Output 2\n\nhaiku atcoder tasks\n\nSample Input 3\n\nabcde,fghihgf,edcba\n\nSample Output 3\n\nabcde fghihgf edcba", "sample_input": "happy,newyear,enjoy\n"}, "reference_outputs": ["happy newyear enjoy\n"], "source_document_id": "p03834", "source_text": "Score : 100 points\n\nProblem Statement\n\nAs a New Year's gift, Dolphin received a string s of length 19.\n\nThe string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters].\n\nDolphin wants to convert the comma-separated string s into a space-separated string.\n\nWrite a program to perform the conversion for him.\n\nConstraints\n\nThe length of s is 19.\n\nThe sixth and fourteenth characters in s are ,.\n\nThe other characters in s are lowercase English letters.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\ns\n\nOutput\n\nPrint the string after the conversion.\n\nSample Input 1\n\nhappy,newyear,enjoy\n\nSample Output 1\n\nhappy newyear enjoy\n\nReplace all the commas in happy,newyear,enjoy with spaces to obtain happy newyear enjoy.\n\nSample Input 2\n\nhaiku,atcoder,tasks\n\nSample Output 2\n\nhaiku atcoder tasks\n\nSample Input 3\n\nabcde,fghihgf,edcba\n\nSample Output 3\n\nabcde fghihgf edcba", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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:s887720824", "group_id": "codeNet:p03836", "input_text": "(defmacro rep (n &body body)\n `(loop repeat ,n do ,@body))\n(defun repc (n c)\n (let ((x nil)) (rep n (setq x (cons c x))) x))\n(defun solve (a b)\n (append (repc a #\\U) (repc b #\\R) (repc a #\\D) (repc (1+ b) #\\L)\n (repc (1+ a) #\\U) (repc (1+ b) #\\R) (repc 1 #\\D) (repc 1 #\\R)\n (repc (1+ a) #\\D) (repc (1+ b) #\\L) (repc 1 #\\U)))\n(let ((sx (read))\n (sy (read))\n (tx (read))\n (ty (read)))\n (format t \"~{~A~}~%\" (solve (- tx sx) (- ty sy))))", "language": "Lisp", "metadata": {"date": 1522719568, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03836.html", "problem_id": "p03836", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03836/input.txt", "sample_output_relpath": "derived/input_output/data/p03836/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03836/Lisp/s887720824.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s887720824", "user_id": "u672956630"}, "prompt_components": {"gold_output": "UURDDLLUUURRDRDDDLLU\n", "input_to_evaluate": "(defmacro rep (n &body body)\n `(loop repeat ,n do ,@body))\n(defun repc (n c)\n (let ((x nil)) (rep n (setq x (cons c x))) x))\n(defun solve (a b)\n (append (repc a #\\U) (repc b #\\R) (repc a #\\D) (repc (1+ b) #\\L)\n (repc (1+ a) #\\U) (repc (1+ b) #\\R) (repc 1 #\\D) (repc 1 #\\R)\n (repc (1+ a) #\\D) (repc (1+ b) #\\L) (repc 1 #\\U)))\n(let ((sx (read))\n (sy (read))\n (tx (read))\n (ty (read)))\n (format t \"~{~A~}~%\" (solve (- tx sx) (- ty sy))))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nDolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.\n\nCurrently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.\n\nHere, both the x- and y-coordinates before and after each movement must be integers.\n\nHe will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).\n\nHere, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).\n\nUnder this condition, find a shortest path for him.\n\nConstraints\n\n-1000 ≤ sx < tx ≤ 1000\n\n-1000 ≤ sy < ty ≤ 1000\n\nsx,sy,tx and ty are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nsx sy tx ty\n\nOutput\n\nPrint a string S that represents a shortest path for Dolphin.\n\nThe i-th character in S should correspond to his i-th movement.\n\nThe directions of the movements should be indicated by the following characters:\n\nU: Up\n\nD: Down\n\nL: Left\n\nR: Right\n\nIf there exist multiple shortest paths under the condition, print any of them.\n\nSample Input 1\n\n0 0 1 2\n\nSample Output 1\n\nUURDDLLUUURRDRDDDLLU\n\nOne possible shortest path is:\n\nGoing from (sx,sy) to (tx,ty) for the first time: (0,0) → (0,1) → (0,2) → (1,2)\n\nGoing from (tx,ty) to (sx,sy) for the first time: (1,2) → (1,1) → (1,0) → (0,0)\n\nGoing from (sx,sy) to (tx,ty) for the second time: (0,0) → (-1,0) → (-1,1) → (-1,2) → (-1,3) → (0,3) → (1,3) → (1,2)\n\nGoing from (tx,ty) to (sx,sy) for the second time: (1,2) → (2,2) → (2,1) → (2,0) → (2,-1) → (1,-1) → (0,-1) → (0,0)\n\nSample Input 2\n\n-2 -2 1 1\n\nSample Output 2\n\nUURRURRDDDLLDLLULUUURRURRDDDLLDL", "sample_input": "0 0 1 2\n"}, "reference_outputs": ["UURDDLLUUURRDRDDDLLU\n"], "source_document_id": "p03836", "source_text": "Score : 300 points\n\nProblem Statement\n\nDolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.\n\nCurrently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.\n\nHere, both the x- and y-coordinates before and after each movement must be integers.\n\nHe will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).\n\nHere, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).\n\nUnder this condition, find a shortest path for him.\n\nConstraints\n\n-1000 ≤ sx < tx ≤ 1000\n\n-1000 ≤ sy < ty ≤ 1000\n\nsx,sy,tx and ty are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nsx sy tx ty\n\nOutput\n\nPrint a string S that represents a shortest path for Dolphin.\n\nThe i-th character in S should correspond to his i-th movement.\n\nThe directions of the movements should be indicated by the following characters:\n\nU: Up\n\nD: Down\n\nL: Left\n\nR: Right\n\nIf there exist multiple shortest paths under the condition, print any of them.\n\nSample Input 1\n\n0 0 1 2\n\nSample Output 1\n\nUURDDLLUUURRDRDDDLLU\n\nOne possible shortest path is:\n\nGoing from (sx,sy) to (tx,ty) for the first time: (0,0) → (0,1) → (0,2) → (1,2)\n\nGoing from (tx,ty) to (sx,sy) for the first time: (1,2) → (1,1) → (1,0) → (0,0)\n\nGoing from (sx,sy) to (tx,ty) for the second time: (0,0) → (-1,0) → (-1,1) → (-1,2) → (-1,3) → (0,3) → (1,3) → (1,2)\n\nGoing from (tx,ty) to (sx,sy) for the second time: (1,2) → (2,2) → (2,1) → (2,0) → (2,-1) → (1,-1) → (0,-1) → (0,0)\n\nSample Input 2\n\n-2 -2 1 1\n\nSample Output 2\n\nUURRURRDDDLLDLLULUUURRURRDDDLLDL", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 471, "cpu_time_ms": 146, "memory_kb": 16736}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s122079009", "group_id": "codeNet:p03837", "input_text": "(defconstant +inf+ (ash 1 32))\n\n(defun rep-helper (args body &optional (top nil))\n (if (null args)\n body\n (let ((arg (first args)))\n (rep-helper\n (rest args)\n (append `(loop for ,(first arg) from ,(second arg) below ,(third arg)\n do) (if top body (list body)))))))\n\n(defmacro rep (args &body body)\n (rep-helper (reverse args) body t))\n\n(defun solve ()\n (let* ((n (read))\n (m (read))\n (d (make-array (list n n) :initial-element +inf+))\n (e (make-array (list n n) :initial-element +inf+)))\n (rep ((i 0 n))\n (setf (aref d i i) 0\n (aref e i i) 0))\n\n (loop repeat m\n do (let ((a (1- (read)))\n (b (1- (read)))\n (c (read)))\n (setf (aref d a b) c (aref d b a) c\n (aref e a b) c (aref e b a) c)))\n\n (rep ((k 0 n) (i 0 n) (j 0 n))\n (setf (aref d i j) (min (aref d i j) (+ (aref d i k) (aref d k j)))))\n\n (let ((a 0))\n (rep ((i 0 n) (j 0 i))\n (when (< (aref d i j) (aref e i j))\n (incf a)))\n (princ a) (terpri))))\n\n(solve)\n", "language": "Lisp", "metadata": {"date": 1483890939, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03837.html", "problem_id": "p03837", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03837/input.txt", "sample_output_relpath": "derived/input_output/data/p03837/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03837/Lisp/s122079009.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s122079009", "user_id": "u188771036"}, "prompt_components": {"gold_output": "1\n", "input_to_evaluate": "(defconstant +inf+ (ash 1 32))\n\n(defun rep-helper (args body &optional (top nil))\n (if (null args)\n body\n (let ((arg (first args)))\n (rep-helper\n (rest args)\n (append `(loop for ,(first arg) from ,(second arg) below ,(third arg)\n do) (if top body (list body)))))))\n\n(defmacro rep (args &body body)\n (rep-helper (reverse args) body t))\n\n(defun solve ()\n (let* ((n (read))\n (m (read))\n (d (make-array (list n n) :initial-element +inf+))\n (e (make-array (list n n) :initial-element +inf+)))\n (rep ((i 0 n))\n (setf (aref d i i) 0\n (aref e i i) 0))\n\n (loop repeat m\n do (let ((a (1- (read)))\n (b (1- (read)))\n (c (read)))\n (setf (aref d a b) c (aref d b a) c\n (aref e a b) c (aref e b a) c)))\n\n (rep ((k 0 n) (i 0 n) (j 0 n))\n (setf (aref d i j) (min (aref d i j) (+ (aref d i k) (aref d k j)))))\n\n (let ((a 0))\n (rep ((i 0 n) (j 0 i))\n (when (< (aref d i j) (aref e i j))\n (incf a)))\n (princ a) (terpri))))\n\n(solve)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nYou are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges.\n\nThe i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i.\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(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 ;; 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 (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 #>nodes\n (let ((indices (loop for i below (* n n)\n when (zerop (aref reserved i))\n collect i)))\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 = (pop indices)\n do (when (> i pos)\n (error \"Huh?\")\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 (pop indices)) 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": 1585316631, "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/s139846067.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s139846067", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (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 #>nodes\n (let ((indices (loop for i below (* n n)\n when (zerop (aref reserved i))\n collect i)))\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 = (pop indices)\n do (when (> i pos)\n (error \"Huh?\")\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 (pop indices)) 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 208, "memory_kb": 23912}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s938056868", "group_id": "codeNet:p03844", "input_text": "(let((a(read))(c(read-char))(b(read)))(princ(if(char= c #\\+)(+ a b)(- a b))))", "language": "Lisp", "metadata": {"date": 1528261099, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03844.html", "problem_id": "p03844", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03844/input.txt", "sample_output_relpath": "derived/input_output/data/p03844/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03844/Lisp/s938056868.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s938056868", "user_id": "u657913472"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(let((a(read))(c(read-char))(b(read)))(princ(if(char= c #\\+)(+ a b)(- a b))))", "problem_context": "Score : 100 points\n\nProblem Statement\n\nJoisino wants to evaluate the formula \"A op B\".\nHere, A and B are integers, and the binary operator op is either + or -.\nYour task is to evaluate the formula instead of her.\n\nConstraints\n\n1≦A,B≦10^9\n\nop is either + or -.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA op B\n\nOutput\n\nEvaluate the formula and print the result.\n\nSample Input 1\n\n1 + 2\n\nSample Output 1\n\n3\n\nSince 1 + 2 = 3, the output should be 3.\n\nSample Input 2\n\n5 - 7\n\nSample Output 2\n\n-2", "sample_input": "1 + 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03844", "source_text": "Score : 100 points\n\nProblem Statement\n\nJoisino wants to evaluate the formula \"A op B\".\nHere, A and B are integers, and the binary operator op is either + or -.\nYour task is to evaluate the formula instead of her.\n\nConstraints\n\n1≦A,B≦10^9\n\nop is either + or -.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nA op B\n\nOutput\n\nEvaluate the formula and print the result.\n\nSample Input 1\n\n1 + 2\n\nSample Output 1\n\n3\n\nSince 1 + 2 = 3, the output should be 3.\n\nSample Input 2\n\n5 - 7\n\nSample Output 2\n\n-2", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 94, "memory_kb": 9952}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s670923159", "group_id": "codeNet:p03845", "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* ((n (parse-integer (read-line)))\n (tin (map 'vector #'parse-integer (split (read-line) #\\Space)))\n (m (parse-integer (read-line)))\n (px (loop for i from 0 below m\n collect (split (read-line) #\\Space)))\n (s (reduce #'+ tin)))\n (loop for i in px\n for p = (1- (parse-integer (aref i 0)))\n do (format t \"~A~%\"\n (+ (- s (aref tin p))\n (parse-integer (aref i 1))))))", "language": "Lisp", "metadata": {"date": 1482114073, "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/s670923159.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s670923159", "user_id": "u275710783"}, "prompt_components": {"gold_output": "6\n9\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* ((n (parse-integer (read-line)))\n (tin (map 'vector #'parse-integer (split (read-line) #\\Space)))\n (m (parse-integer (read-line)))\n (px (loop for i from 0 below m\n collect (split (read-line) #\\Space)))\n (s (reduce #'+ tin)))\n (loop for i in px\n for p = (1- (parse-integer (aref i 0)))\n do (format t \"~A~%\"\n (+ (- s (aref tin p))\n (parse-integer (aref i 1))))))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 967, "cpu_time_ms": 1419, "memory_kb": 13664}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s776483937", "group_id": "codeNet:p03846", "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 (as (make-array n :element-type 'uint31 :initial-element 0))\n (res 1))\n (dotimes (i n)\n (incf (aref as (read-fixnum))))\n (when (oddp n)\n (unless (and (= 1 (aref as 0))\n (loop for x from 2 to (- n 1) by 2\n always (= 2 (aref as x))))\n (println 0)\n (return-from main)))\n (when (evenp n)\n (unless (loop for x from 1 to (- n 1) by 2\n always (= 2 (aref as x)))\n (println 0)\n (return-from main)))\n (loop repeat (floor n 2)\n do (setq res (mod (ash res 1) +mod+)))\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 \"5\n2 4 4 0 2\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n6 4 0 2 4 0 2\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n7 5 1 1 7 3 5 3\n\"\n \"16\n\")))\n", "language": "Lisp", "metadata": {"date": 1577705539, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03846.html", "problem_id": "p03846", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03846/input.txt", "sample_output_relpath": "derived/input_output/data/p03846/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03846/Lisp/s776483937.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s776483937", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (res 1))\n (dotimes (i n)\n (incf (aref as (read-fixnum))))\n (when (oddp n)\n (unless (and (= 1 (aref as 0))\n (loop for x from 2 to (- n 1) by 2\n always (= 2 (aref as x))))\n (println 0)\n (return-from main)))\n (when (evenp n)\n (unless (loop for x from 1 to (- n 1) by 2\n always (= 2 (aref as x)))\n (println 0)\n (return-from main)))\n (loop repeat (floor n 2)\n do (setq res (mod (ash res 1) +mod+)))\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 \"5\n2 4 4 0 2\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7\n6 4 0 2 4 0 2\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8\n7 5 1 1 7 3 5 3\n\"\n \"16\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nThere are N people, conveniently numbered 1 through N.\nThey were standing in a row yesterday, but now they are unsure of the order in which they were standing.\nHowever, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.\nAccording to their reports, the difference above for person i is A_i.\n\nBased on these reports, find the number of the possible orders in which they were standing.\nSince it can be extremely large, print the answer modulo 10^9+7.\nNote that the reports may be incorrect and thus there may be no consistent order.\nIn such a case, print 0.\n\nConstraints\n\n1≦N≦10^5\n\n0≦A_i≦N-1\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 orders in which they were standing, modulo 10^9+7.\n\nSample Input 1\n\n5\n2 4 4 0 2\n\nSample Output 1\n\n4\n\nThere are four possible orders, as follows:\n\n2,1,4,5,3\n\n2,5,4,1,3\n\n3,1,4,5,2\n\n3,5,4,1,2\n\nSample Input 2\n\n7\n6 4 0 2 4 0 2\n\nSample Output 2\n\n0\n\nAny order would be inconsistent with the reports, thus the answer is 0.\n\nSample Input 3\n\n8\n7 5 1 1 7 3 5 3\n\nSample Output 3\n\n16", "sample_input": "5\n2 4 4 0 2\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03846", "source_text": "Score : 300 points\n\nProblem Statement\n\nThere are N people, conveniently numbered 1 through N.\nThey were standing in a row yesterday, but now they are unsure of the order in which they were standing.\nHowever, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.\nAccording to their reports, the difference above for person i is A_i.\n\nBased on these reports, find the number of the possible orders in which they were standing.\nSince it can be extremely large, print the answer modulo 10^9+7.\nNote that the reports may be incorrect and thus there may be no consistent order.\nIn such a case, print 0.\n\nConstraints\n\n1≦N≦10^5\n\n0≦A_i≦N-1\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 orders in which they were standing, modulo 10^9+7.\n\nSample Input 1\n\n5\n2 4 4 0 2\n\nSample Output 1\n\n4\n\nThere are four possible orders, as follows:\n\n2,1,4,5,3\n\n2,5,4,1,3\n\n3,1,4,5,2\n\n3,5,4,1,2\n\nSample Input 2\n\n7\n6 4 0 2 4 0 2\n\nSample Output 2\n\n0\n\nAny order would be inconsistent with the reports, thus the answer is 0.\n\nSample Input 3\n\n8\n7 5 1 1 7 3 5 3\n\nSample Output 3\n\n16", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4407, "cpu_time_ms": 211, "memory_kb": 22760}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s430852718", "group_id": "codeNet:p03847", "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;;;\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 (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 (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(defun matrix-rotate (matrix rot)\n \"Counterclockwise rotates a 2-dimensional array by 90 * ROT degrees. This\nfunction is non-destructive.\"\n (declare ((array * (* *)) matrix)\n (integer rot))\n (destructuring-bind (h w) (array-dimensions matrix)\n (declare ((integer 0 #.most-positive-fixnum) h w))\n (let* ((rot (mod rot 4))\n (new-h (if (evenp rot) h w))\n (new-w (if (evenp rot) w h))\n (res (make-array (list new-h new-w) :element-type (array-element-type matrix))))\n (declare ((integer 0 3) rot))\n (case rot\n (0 (dotimes (i h)\n (dotimes (j w)\n (setf (aref res i j) (aref matrix i j)))))\n (1 (dotimes (i h)\n (dotimes (j w)\n (setf (aref res (- w 1 j) i) (aref matrix i j)))))\n (2 (dotimes (i h)\n (dotimes (j w)\n (setf (aref res (- h 1 i) (- w 1 j)) (aref matrix i j)))))\n (3 (dotimes (i h)\n (dotimes (j w)\n (setf (aref res j (- h 1 i)) (aref matrix i j))))))\n res)))\n\n(declaim (inline print-matrix))\n(defun print-matrix (array &key (separator #\\ ) (key #'identity) (row-start 0) row-end (col-start 0) col-end)\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 do (unless (= j col-start)\n (princ separator))\n (write (funcall key (aref array i j))))\n (terpri))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 test (n)\n (labels ((feasible-p (u v)\n (loop for a from 0 to (ceiling v 2)\n for b = (- v a)\n when (= (logxor a b) u)\n do (return t))))\n (let ((res (make-array (list (+ n 1) (+ n 1)) :element-type 'base-char)))\n (dotimes (u (+ n 1))\n (dotimes (v (+ n 1))\n (setf (aref res u v)\n (if (feasible-p u v) #\\# #\\.))))\n res)))\n\n(defun xortest (x)\n (loop for a from 0 to (floor x 2)\n for b = (- x a)\n do (print (logxor a b))))\n\n(declaim ((simple-array uint31 (*)) *power3*))\n(defparameter *power3* (make-array 100 :element-type 'uint31 :initial-element 1))\n(dotimes (i (- (length *power3*) 1))\n (setf (aref *power3* (+ i 1))\n (mod* 3 (aref *power3* i))))\n\n(with-cache (:hash-table :test #'eql :key #'identity)\n (defun solve (x)\n (declare (uint62 x)\n (values uint31))\n (if (= x 0)\n 0\n (let ((exp2 (integer-length (- x 1))))\n (if (= (ash 1 exp2) x)\n (mod+ 1 (solve (- x 1)))\n (mod+ (aref *power3* (- exp2 1))\n (- +mod+ (solve (- (ash 1 exp2) x 1)))\n (solve (- x (ash 1 (- exp2 1))))))))))\n\n(defun main ()\n (let* ((n (read)))\n (println\n (solve (+ 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 \"3\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1422\n\"\n \"52277\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1000000000000000000\n\"\n \"787014179\n\")))\n", "language": "Lisp", "metadata": {"date": 1574827001, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03847.html", "problem_id": "p03847", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03847/input.txt", "sample_output_relpath": "derived/input_output/data/p03847/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03847/Lisp/s430852718.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s430852718", "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 ;; 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;;;\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 (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 (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(defun matrix-rotate (matrix rot)\n \"Counterclockwise rotates a 2-dimensional array by 90 * ROT degrees. This\nfunction is non-destructive.\"\n (declare ((array * (* *)) matrix)\n (integer rot))\n (destructuring-bind (h w) (array-dimensions matrix)\n (declare ((integer 0 #.most-positive-fixnum) h w))\n (let* ((rot (mod rot 4))\n (new-h (if (evenp rot) h w))\n (new-w (if (evenp rot) w h))\n (res (make-array (list new-h new-w) :element-type (array-element-type matrix))))\n (declare ((integer 0 3) rot))\n (case rot\n (0 (dotimes (i h)\n (dotimes (j w)\n (setf (aref res i j) (aref matrix i j)))))\n (1 (dotimes (i h)\n (dotimes (j w)\n (setf (aref res (- w 1 j) i) (aref matrix i j)))))\n (2 (dotimes (i h)\n (dotimes (j w)\n (setf (aref res (- h 1 i) (- w 1 j)) (aref matrix i j)))))\n (3 (dotimes (i h)\n (dotimes (j w)\n (setf (aref res j (- h 1 i)) (aref matrix i j))))))\n res)))\n\n(declaim (inline print-matrix))\n(defun print-matrix (array &key (separator #\\ ) (key #'identity) (row-start 0) row-end (col-start 0) col-end)\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 do (unless (= j col-start)\n (princ separator))\n (write (funcall key (aref array i j))))\n (terpri))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 test (n)\n (labels ((feasible-p (u v)\n (loop for a from 0 to (ceiling v 2)\n for b = (- v a)\n when (= (logxor a b) u)\n do (return t))))\n (let ((res (make-array (list (+ n 1) (+ n 1)) :element-type 'base-char)))\n (dotimes (u (+ n 1))\n (dotimes (v (+ n 1))\n (setf (aref res u v)\n (if (feasible-p u v) #\\# #\\.))))\n res)))\n\n(defun xortest (x)\n (loop for a from 0 to (floor x 2)\n for b = (- x a)\n do (print (logxor a b))))\n\n(declaim ((simple-array uint31 (*)) *power3*))\n(defparameter *power3* (make-array 100 :element-type 'uint31 :initial-element 1))\n(dotimes (i (- (length *power3*) 1))\n (setf (aref *power3* (+ i 1))\n (mod* 3 (aref *power3* i))))\n\n(with-cache (:hash-table :test #'eql :key #'identity)\n (defun solve (x)\n (declare (uint62 x)\n (values uint31))\n (if (= x 0)\n 0\n (let ((exp2 (integer-length (- x 1))))\n (if (= (ash 1 exp2) x)\n (mod+ 1 (solve (- x 1)))\n (mod+ (aref *power3* (- exp2 1))\n (- +mod+ (solve (- (ash 1 exp2) x 1)))\n (solve (- x (ash 1 (- exp2 1))))))))))\n\n(defun main ()\n (let* ((n (read)))\n (println\n (solve (+ 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 \"3\n\"\n \"5\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1422\n\"\n \"52277\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"1000000000000000000\n\"\n \"787014179\n\")))\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v.\nHere, xor denotes the bitwise exclusive OR.\nSince it can be extremely large, compute the answer modulo 10^9+7.\n\nConstraints\n\n1≦N≦10^{18}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of the possible pairs of integers u and v, modulo 10^9+7.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n5\n\nThe five possible pairs of u and v are:\n\nu=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\nu=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.)\n\nu=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.)\n\nu=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.)\n\nu=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.)\n\nSample Input 2\n\n1422\n\nSample Output 2\n\n52277\n\nSample Input 3\n\n1000000000000000000\n\nSample Output 3\n\n787014179", "sample_input": "3\n"}, "reference_outputs": ["5\n"], "source_document_id": "p03847", "source_text": "Score : 600 points\n\nProblem Statement\n\nYou are given a positive integer N.\nFind the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v.\nHere, xor denotes the bitwise exclusive OR.\nSince it can be extremely large, compute the answer modulo 10^9+7.\n\nConstraints\n\n1≦N≦10^{18}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN\n\nOutput\n\nPrint the number of the possible pairs of integers u and v, modulo 10^9+7.\n\nSample Input 1\n\n3\n\nSample Output 1\n\n5\n\nThe five possible pairs of u and v are:\n\nu=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\n\nu=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.)\n\nu=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.)\n\nu=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.)\n\nu=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.)\n\nSample Input 2\n\n1422\n\nSample Output 2\n\n52277\n\nSample Input 3\n\n1000000000000000000\n\nSample Output 3\n\n787014179", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 19572, "cpu_time_ms": 378, "memory_kb": 45540}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s882319769", "group_id": "codeNet:p03853", "input_text": "(dotimes(i(+(read)(*(read)0)))(format t\"~A~%~A~%\"(setq s(read-line))s))", "language": "Lisp", "metadata": {"date": 1537947415, "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/s882319769.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s882319769", "user_id": "u657913472"}, "prompt_components": {"gold_output": "*.\n*.\n.*\n.*\n", "input_to_evaluate": "(dotimes(i(+(read)(*(read)0)))(format t\"~A~%~A~%\"(setq s(read-line))s))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 135, "memory_kb": 13408}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s295233814", "group_id": "codeNet:p03857", "input_text": "(declaim (optimize (speed 0) (debug 3) (safety 3)))\n\n(defun make-union-find (n)\n (let ((x (make-array n)))\n (loop for i from 0 below n\n do (setf (aref x i) i))\n x))\n\n(defun lookup (uf n)\n (if (= (aref uf n) n)\n n\n (setf (aref uf n)\n\t (lookup uf (aref uf n)))))\n\n(defun unite (uf n m)\n (setf (aref uf (lookup uf n))\n\t(lookup uf m)))\n\n(defun force (uf)\n (loop for x from 0 below (length uf)\n do (lookup uf x)))\n\n(defun main ()\n (let* ((n (read))\n\t (k (read))\n\t (l (read))\n\t (road (make-union-find n))\n\t (rail (make-union-find n)))\n (loop repeat k\n do (let ((p (1- (read)))\n\t\t(q (1- (read))))\n\t (unite road p q)))\n (loop repeat l\n do (let ((r (1- (read)))\n\t\t(s (1- (read))))\n\t (unite rail r s)))\n (force road)\n (force rail)\n\n (let ((table (make-hash-table)))\n (labels ((idx (i) (+ (* (lookup road i) n)\n\t\t\t (lookup rail i))))\n\t(loop for i from 0 below n\n\t do (if (gethash (idx i) table)\n\t\t (incf (gethash (idx i) table))\n\t\t (setf (gethash (idx i) table) 1)))\n\t(loop for i from 0 below n\n\t do (format t \"~a \" (gethash (idx i) table)))\n\t(terpri)))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1481424523, "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/s295233814.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s295233814", "user_id": "u693548378"}, "prompt_components": {"gold_output": "1 2 2 1\n", "input_to_evaluate": "(declaim (optimize (speed 0) (debug 3) (safety 3)))\n\n(defun make-union-find (n)\n (let ((x (make-array n)))\n (loop for i from 0 below n\n do (setf (aref x i) i))\n x))\n\n(defun lookup (uf n)\n (if (= (aref uf n) n)\n n\n (setf (aref uf n)\n\t (lookup uf (aref uf n)))))\n\n(defun unite (uf n m)\n (setf (aref uf (lookup uf n))\n\t(lookup uf m)))\n\n(defun force (uf)\n (loop for x from 0 below (length uf)\n do (lookup uf x)))\n\n(defun main ()\n (let* ((n (read))\n\t (k (read))\n\t (l (read))\n\t (road (make-union-find n))\n\t (rail (make-union-find n)))\n (loop repeat k\n do (let ((p (1- (read)))\n\t\t(q (1- (read))))\n\t (unite road p q)))\n (loop repeat l\n do (let ((r (1- (read)))\n\t\t(s (1- (read))))\n\t (unite rail r s)))\n (force road)\n (force rail)\n\n (let ((table (make-hash-table)))\n (labels ((idx (i) (+ (* (lookup road i) n)\n\t\t\t (lookup rail i))))\n\t(loop for i from 0 below n\n\t do (if (gethash (idx i) table)\n\t\t (incf (gethash (idx i) table))\n\t\t (setf (gethash (idx i) table) 1)))\n\t(loop for i from 0 below n\n\t do (format t \"~a \" (gethash (idx i) table)))\n\t(terpri)))))\n\n(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1133, "cpu_time_ms": 1694, "memory_kb": 71168}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s597362457", "group_id": "codeNet:p03858", "input_text": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n\n(defun make-union-find (n)\n (let ((x (make-array n)))\n (loop for i from 0 below n\n do (setf (aref x i) i))\n x))\n\n(defun lookup (uf n)\n (if (= (aref uf n) n)\n n\n (setf (aref uf n)\n\t (lookup uf (aref uf n)))))\n\n(defun unite (uf n m)\n (setf (aref uf (lookup uf n))\n\t(lookup uf m)))\n\n(defun force (uf)\n (loop for x from 0 below (length uf)\n do (lookup uf x)))\n\n(defun .x (p) (first p))\n(defun .y (p) (second p))\n(defun sum (p) (+ (.x p) (.y p)))\n(defun diff (p) (- (.x p) (.y p)))\n\n(defun mdist (p q)\n (+ (abs (- (.x p) (.x q)))\n (abs (- (.y p) (.y q)))))\n\n(defun main ()\n (let* ((n (read))\n\t (a (1- (read)))\n\t (b (1- (read)))\n\t (ps (loop repeat n collect (list (read) (read))))\n\t (rad (mdist (nth a ps) (nth b ps)))\n\t (uf (make-union-find n))\n\t (stbl (make-hash-table))\n\t (dtbl (make-hash-table)))\n (loop for p in ps\n do (push p (gethash (sum p) stbl))\n do (push p (gethash (diff p) dtbl)))\n\n (loop for p in ps\n for i from 0\n do (loop for q in (gethash (+ (sum p) rad) stbl)\n\t for j from 0\n\t when (and (<= (.x p) (.x q))\n\t\t (<= (.y p) (.y q)))\n\t do (unite uf i j))\n do (loop for q in (gethash (- (sum p) rad) stbl)\n\t for j from 0\n\t when (and (>= (.x p) (.x q))\n\t\t (>= (.y p) (.y q)))\n\t do (unite uf i j))\n do (loop for q in (gethash (- (diff p) rad) dtbl)\n\t for j from 0\n\t when (and (>= (.x p) (.x q))\n\t\t (<= (.y p) (.y q)))\n\t do (unite uf i j))\n do (loop for q in (gethash (+ (diff p) rad) dtbl)\n\t for j from 0\n\t when (and (<= (.x p) (.x q))\n\t\t (>= (.y p) (.y q)))\n\t do (unite uf i j)))\n\n (force uf)\n (format t \"~a~%\" (loop for i from 0 below n\n\t\t\twhen (= (lookup uf i) (lookup uf a))\n\t\t\tsum 1))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1481427457, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03858.html", "problem_id": "p03858", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03858/input.txt", "sample_output_relpath": "derived/input_output/data/p03858/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03858/Lisp/s597362457.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s597362457", "user_id": "u693548378"}, "prompt_components": {"gold_output": "4\n", "input_to_evaluate": "(declaim (optimize (speed 3) (debug 0) (safety 0)))\n\n(defun make-union-find (n)\n (let ((x (make-array n)))\n (loop for i from 0 below n\n do (setf (aref x i) i))\n x))\n\n(defun lookup (uf n)\n (if (= (aref uf n) n)\n n\n (setf (aref uf n)\n\t (lookup uf (aref uf n)))))\n\n(defun unite (uf n m)\n (setf (aref uf (lookup uf n))\n\t(lookup uf m)))\n\n(defun force (uf)\n (loop for x from 0 below (length uf)\n do (lookup uf x)))\n\n(defun .x (p) (first p))\n(defun .y (p) (second p))\n(defun sum (p) (+ (.x p) (.y p)))\n(defun diff (p) (- (.x p) (.y p)))\n\n(defun mdist (p q)\n (+ (abs (- (.x p) (.x q)))\n (abs (- (.y p) (.y q)))))\n\n(defun main ()\n (let* ((n (read))\n\t (a (1- (read)))\n\t (b (1- (read)))\n\t (ps (loop repeat n collect (list (read) (read))))\n\t (rad (mdist (nth a ps) (nth b ps)))\n\t (uf (make-union-find n))\n\t (stbl (make-hash-table))\n\t (dtbl (make-hash-table)))\n (loop for p in ps\n do (push p (gethash (sum p) stbl))\n do (push p (gethash (diff p) dtbl)))\n\n (loop for p in ps\n for i from 0\n do (loop for q in (gethash (+ (sum p) rad) stbl)\n\t for j from 0\n\t when (and (<= (.x p) (.x q))\n\t\t (<= (.y p) (.y q)))\n\t do (unite uf i j))\n do (loop for q in (gethash (- (sum p) rad) stbl)\n\t for j from 0\n\t when (and (>= (.x p) (.x q))\n\t\t (>= (.y p) (.y q)))\n\t do (unite uf i j))\n do (loop for q in (gethash (- (diff p) rad) dtbl)\n\t for j from 0\n\t when (and (>= (.x p) (.x q))\n\t\t (<= (.y p) (.y q)))\n\t do (unite uf i j))\n do (loop for q in (gethash (+ (diff p) rad) dtbl)\n\t for j from 0\n\t when (and (<= (.x p) (.x q))\n\t\t (>= (.y p) (.y q)))\n\t do (unite uf i j)))\n\n (force uf)\n (format t \"~a~%\" (loop for i from 0 below n\n\t\t\twhen (= (lookup uf i) (lookup uf a))\n\t\t\tsum 1))))\n\n(main)\n", "problem_context": "Score : 900 points\n\nProblem Statement\n\nThere are N pinholes on the xy-plane. The i-th pinhole is located at (x_i,y_i).\n\nWe will denote the Manhattan distance between the i-th and j-th pinholes as d(i,j)(=|x_i-x_j|+|y_i-y_j|).\n\nYou have a peculiar pair of compasses, called Manhattan Compass.\nThis instrument always points at two of the pinholes.\nThe two legs of the compass are indistinguishable, thus we do not distinguish the following two states: the state where the compass points at the p-th and q-th pinholes, and the state where it points at the q-th and p-th pinholes.\n\nWhen the compass points at the p-th and q-th pinholes and d(p,q)=d(p,r), one of the legs can be moved so that the compass will point at the p-th and r-th pinholes.\n\nInitially, the compass points at the a-th and b-th pinholes.\nFind the number of the pairs of pinholes that can be pointed by the compass.\n\nConstraints\n\n2≦N≦10^5\n\n1≦x_i, y_i≦10^9\n\n1≦a < b≦N\n\nWhen i ≠ j, (x_i, y_i) ≠ (x_j, y_j)\n\nx_i and y_i are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN a b\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the number of the pairs of pinholes that can be pointed by the compass.\n\nSample Input 1\n\n5 1 2\n1 1\n4 3\n6 1\n5 5\n4 8\n\nSample Output 1\n\n4\n\nInitially, the compass points at the first and second pinholes.\n\nSince d(1,2) = d(1,3), the compass can be moved so that it will point at the first and third pinholes.\n\nSince d(1,3) = d(3,4), the compass can also point at the third and fourth pinholes.\n\nSince d(1,2) = d(2,5), the compass can also point at the second and fifth pinholes.\n\nNo other pairs of pinholes can be pointed by the compass, thus the answer is 4.\n\nSample Input 2\n\n6 2 3\n1 3\n5 3\n3 5\n8 4\n4 7\n2 5\n\nSample Output 2\n\n4\n\nSample Input 3\n\n8 1 2\n1 5\n4 3\n8 2\n4 7\n8 8\n3 3\n6 6\n4 8\n\nSample Output 3\n\n7", "sample_input": "5 1 2\n1 1\n4 3\n6 1\n5 5\n4 8\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03858", "source_text": "Score : 900 points\n\nProblem Statement\n\nThere are N pinholes on the xy-plane. The i-th pinhole is located at (x_i,y_i).\n\nWe will denote the Manhattan distance between the i-th and j-th pinholes as d(i,j)(=|x_i-x_j|+|y_i-y_j|).\n\nYou have a peculiar pair of compasses, called Manhattan Compass.\nThis instrument always points at two of the pinholes.\nThe two legs of the compass are indistinguishable, thus we do not distinguish the following two states: the state where the compass points at the p-th and q-th pinholes, and the state where it points at the q-th and p-th pinholes.\n\nWhen the compass points at the p-th and q-th pinholes and d(p,q)=d(p,r), one of the legs can be moved so that the compass will point at the p-th and r-th pinholes.\n\nInitially, the compass points at the a-th and b-th pinholes.\nFind the number of the pairs of pinholes that can be pointed by the compass.\n\nConstraints\n\n2≦N≦10^5\n\n1≦x_i, y_i≦10^9\n\n1≦a < b≦N\n\nWhen i ≠ j, (x_i, y_i) ≠ (x_j, y_j)\n\nx_i and y_i are integers.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN a b\nx_1 y_1\n:\nx_N y_N\n\nOutput\n\nPrint the number of the pairs of pinholes that can be pointed by the compass.\n\nSample Input 1\n\n5 1 2\n1 1\n4 3\n6 1\n5 5\n4 8\n\nSample Output 1\n\n4\n\nInitially, the compass points at the first and second pinholes.\n\nSince d(1,2) = d(1,3), the compass can be moved so that it will point at the first and third pinholes.\n\nSince d(1,3) = d(3,4), the compass can also point at the third and fourth pinholes.\n\nSince d(1,2) = d(2,5), the compass can also point at the second and fifth pinholes.\n\nNo other pairs of pinholes can be pointed by the compass, thus the answer is 4.\n\nSample Input 2\n\n6 2 3\n1 3\n5 3\n3 5\n8 4\n4 7\n2 5\n\nSample Output 2\n\n4\n\nSample Input 3\n\n8 1 2\n1 5\n4 3\n8 2\n4 7\n8 8\n3 3\n6 6\n4 8\n\nSample Output 3\n\n7", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1822, "cpu_time_ms": 3158, "memory_kb": 69600}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s230608673", "group_id": "codeNet:p03860", "input_text": "(format t \"~A~A~A\" \"A\" (subseq (read-line) 8 9) \"C\")", "language": "Lisp", "metadata": {"date": 1554086215, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03860.html", "problem_id": "p03860", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03860/input.txt", "sample_output_relpath": "derived/input_output/data/p03860/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03860/Lisp/s230608673.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s230608673", "user_id": "u610490393"}, "prompt_components": {"gold_output": "ABC\n", "input_to_evaluate": "(format t \"~A~A~A\" \"A\" (subseq (read-line) 8 9) \"C\")", "problem_context": "Score : 100 points\n\nProblem Statement\n\nSnuke is going to open a contest named \"AtCoder s Contest\".\nHere, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.\n\nSnuke has decided to abbreviate the name of the contest as \"AxC\".\nHere, x is the uppercase English letter at the beginning of s.\n\nGiven the name of the contest, print the abbreviation of the name.\n\nConstraints\n\nThe length of s is between 1 and 100, inclusive.\n\nThe first character in s is an uppercase English letter.\n\nThe second and subsequent characters in s are lowercase English letters.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nAtCoder s Contest\n\nOutput\n\nPrint the abbreviation of the name of the contest.\n\nSample Input 1\n\nAtCoder Beginner Contest\n\nSample Output 1\n\nABC\n\nThe contest in which you are participating now.\n\nSample Input 2\n\nAtCoder Snuke Contest\n\nSample Output 2\n\nASC\n\nThis contest does not actually exist.\n\nSample Input 3\n\nAtCoder X Contest\n\nSample Output 3\n\nAXC", "sample_input": "AtCoder Beginner Contest\n"}, "reference_outputs": ["ABC\n"], "source_document_id": "p03860", "source_text": "Score : 100 points\n\nProblem Statement\n\nSnuke is going to open a contest named \"AtCoder s Contest\".\nHere, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.\n\nSnuke has decided to abbreviate the name of the contest as \"AxC\".\nHere, x is the uppercase English letter at the beginning of s.\n\nGiven the name of the contest, print the abbreviation of the name.\n\nConstraints\n\nThe length of s is between 1 and 100, inclusive.\n\nThe first character in s is an uppercase English letter.\n\nThe second and subsequent characters in s are lowercase English letters.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nAtCoder s Contest\n\nOutput\n\nPrint the abbreviation of the name of the contest.\n\nSample Input 1\n\nAtCoder Beginner Contest\n\nSample Output 1\n\nABC\n\nThe contest in which you are participating now.\n\nSample Input 2\n\nAtCoder Snuke Contest\n\nSample Output 2\n\nASC\n\nThis contest does not actually exist.\n\nSample Input 3\n\nAtCoder X Contest\n\nSample Output 3\n\nAXC", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 5, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s519218109", "group_id": "codeNet:p03861", "input_text": " (defun f (n x)\n (if (= -1 n) 0 (1+ (floor (/ n x)))))\n \n (let ((a (read))\n (b (read))\n (c (read)))\n (princ (- (f b c) (f (1- a) c))))", "language": "Lisp", "metadata": {"date": 1550073038, "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/s519218109.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s519218109", "user_id": "u994767958"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": " (defun f (n x)\n (if (= -1 n) 0 (1+ (floor (/ n x)))))\n \n (let ((a (read))\n (b (read))\n (c (read)))\n (princ (- (f b c) (f (1- 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 154, "memory_kb": 13028}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s616003558", "group_id": "codeNet:p03861", "input_text": "(defun f (n x)\n (if (= -1 n) 0 (1+ (floor (/ n x)))))\n\n(let ((a (read))\n (b (read))\n (c (read)))\n (princ (- (f b c) (f (1- a c)))))", "language": "Lisp", "metadata": {"date": 1550072894, "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/s616003558.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s616003558", "user_id": "u994767958"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(defun f (n x)\n (if (= -1 n) 0 (1+ (floor (/ n x)))))\n\n(let ((a (read))\n (b (read))\n (c (read)))\n (princ (- (f b c) (f (1- 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 133, "memory_kb": 14944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s144767226", "group_id": "codeNet:p03864", "input_text": "#include \n#include \n#include \n#include \n\nusing namespace std;\n\nint main(void){\n int N, x;\n long long int a[100000], b[100000]={};\n\n cin >> N >> x;\n\n for (int i = 0; i < N; ++i) {\n cin >> a[i];\n }\n\n for (int i = 0; i < N - 1; ++i) {\n b[i] = a[i]+a[i+1]-x;\n }\n\n unsigned long long int result=0;\n\n for (int i = 0; i < N - 1; ++i) {\n if (b[i]>0){\n result+=b[i];\n // cout <<\"b[\"<< i <<\"]:\"<< b[i]<<\"\\n\"\n // <<\"result:\"<< result<< \"\\n\";\n b[i+1]-=(b[i]\n#include \n#include \n#include \n\nusing namespace std;\n\nint main(void){\n int N, x;\n long long int a[100000], b[100000]={};\n\n cin >> N >> x;\n\n for (int i = 0; i < N; ++i) {\n cin >> a[i];\n }\n\n for (int i = 0; i < N - 1; ++i) {\n b[i] = a[i]+a[i+1]-x;\n }\n\n unsigned long long int result=0;\n\n for (int i = 0; i < N - 1; ++i) {\n if (b[i]>0){\n result+=b[i];\n // cout <<\"b[\"<< i <<\"]:\"<< b[i]<<\"\\n\"\n // <<\"result:\"<< result<< \"\\n\";\n b[i+1]-=(b[i] (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 ((anum 0)\n (bnum 0))\n (declare (uint31 anum bnum))\n (sb-int:named-let recur ((as as) (bs bs))\n (cond ((and (null as) (null bs)))\n ((null as)\n (mulfmod res anum)\n (decf anum)\n (recur as (cdr bs)))\n ((null bs)\n (mulfmod res bnum)\n (decf bnum)\n (recur (cdr as) bs))\n ((uint32< (car as) (car bs))\n (if (zerop bnum)\n (incf anum)\n (progn (mulfmod res bnum)\n (decf bnum)))\n (recur (cdr as) bs))\n (t\n (if (zerop anum)\n (incf bnum)\n (progn (mulfmod res anum)\n (decf anum)))\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": 1572141920, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03868.html", "problem_id": "p03868", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03868/input.txt", "sample_output_relpath": "derived/input_output/data/p03868/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03868/Lisp/s319272545.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s319272545", "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 ((anum 0)\n (bnum 0))\n (declare (uint31 anum bnum))\n (sb-int:named-let recur ((as as) (bs bs))\n (cond ((and (null as) (null bs)))\n ((null as)\n (mulfmod res anum)\n (decf anum)\n (recur as (cdr bs)))\n ((null bs)\n (mulfmod res bnum)\n (decf bnum)\n (recur (cdr as) bs))\n ((uint32< (car as) (car bs))\n (if (zerop bnum)\n (incf anum)\n (progn (mulfmod res bnum)\n (decf bnum)))\n (recur (cdr as) bs))\n (t\n (if (zerop anum)\n (incf bnum)\n (progn (mulfmod res anum)\n (decf anum)))\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": "p03868", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7159, "cpu_time_ms": 180, "memory_kb": 24936}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s665469121", "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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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;;; 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(defun quicksort! (vector)\n \"Destructively sorts VECTOR w.r.t. ORDER\"\n (declare #.OPT\n ((simple-array uint31 (*)) 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 (aref vector l)\n (aref vector (ash (+ l r) -1))\n (aref vector r)\n #'<)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (< (aref vector l) pivot)\n do (incf l 1))\n (loop while (< 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 0 (- (length vector) 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(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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": 1572142785, "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/s665469121.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s665469121", "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(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"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;;; 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(defun quicksort! (vector)\n \"Destructively sorts VECTOR w.r.t. ORDER\"\n (declare #.OPT\n ((simple-array uint31 (*)) 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 (aref vector l)\n (aref vector (ash (+ l r) -1))\n (aref vector r)\n #'<)))\n (declare ((integer 0 #.most-positive-fixnum) l r))\n (loop (loop while (< (aref vector l) pivot)\n do (incf l 1))\n (loop while (< 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 0 (- (length vector) 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(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8561, "cpu_time_ms": 299, "memory_kb": 33380}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s256617409", "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 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": 1572119644, "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/s256617409.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s256617409", "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 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7343, "cpu_time_ms": 2104, "memory_kb": 49888}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s830664892", "group_id": "codeNet:p03894", "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 \"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 (q (read))\n (as (make-array q :element-type 'uint31))\n (bs (make-array q :element-type 'uint31))\n (perm-r (make-array n :element-type 'uint31))\n (perm-l (make-array n :element-type 'uint31))\n (res (make-array n :element-type 'bit :initial-element 0)))\n (dotimes (i q)\n (setf (aref as i) (- (read-fixnum) 1)\n (aref bs i) (- (read-fixnum) 1)))\n (dotimes (i n)\n (setf (aref perm-r i) i\n (aref perm-l i) i))\n #>perm-r\n #>as\n #>bs\n (dotimes (i q)\n (rotatef (aref perm-r (aref as i))\n (aref perm-r (aref bs i))))\n (let ((pos1 0))\n (dotimes (i (+ q 1))\n (setf (aref res (aref perm-r pos1)) 1)\n (when (> pos1 0)\n (setf (aref res (aref perm-r (- pos1 1))) 1))\n (when (< pos1 (- n 1))\n (setf (aref res (aref perm-r (+ pos1 1))) 1))\n (when (< i q)\n (let* ((a (aref as i))\n (b (aref bs i)))\n (cond ((= pos1 a) (setq pos1 b))\n ((= pos1 b) (setq pos1 a)))\n (rotatef (aref perm-r a) (aref perm-r b))))))\n (println (count 1 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 \"10 3\n1 3\n2 4\n4 5\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20 3\n1 7\n8 20\n1 19\n\"\n \"5\n\")))\n", "language": "Lisp", "metadata": {"date": 1579242811, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03894.html", "problem_id": "p03894", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03894/input.txt", "sample_output_relpath": "derived/input_output/data/p03894/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03894/Lisp/s830664892.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s830664892", "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 (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 (q (read))\n (as (make-array q :element-type 'uint31))\n (bs (make-array q :element-type 'uint31))\n (perm-r (make-array n :element-type 'uint31))\n (perm-l (make-array n :element-type 'uint31))\n (res (make-array n :element-type 'bit :initial-element 0)))\n (dotimes (i q)\n (setf (aref as i) (- (read-fixnum) 1)\n (aref bs i) (- (read-fixnum) 1)))\n (dotimes (i n)\n (setf (aref perm-r i) i\n (aref perm-l i) i))\n #>perm-r\n #>as\n #>bs\n (dotimes (i q)\n (rotatef (aref perm-r (aref as i))\n (aref perm-r (aref bs i))))\n (let ((pos1 0))\n (dotimes (i (+ q 1))\n (setf (aref res (aref perm-r pos1)) 1)\n (when (> pos1 0)\n (setf (aref res (aref perm-r (- pos1 1))) 1))\n (when (< pos1 (- n 1))\n (setf (aref res (aref perm-r (+ pos1 1))) 1))\n (when (< i q)\n (let* ((a (aref as i))\n (b (aref bs i)))\n (cond ((= pos1 a) (setq pos1 b))\n ((= pos1 b) (setq pos1 a)))\n (rotatef (aref perm-r a) (aref perm-r b))))))\n (println (count 1 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 \"10 3\n1 3\n2 4\n4 5\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"20 3\n1 7\n8 20\n1 19\n\"\n \"5\n\")))\n", "problem_context": "Score : 100 points\n\nProblem Statement\n\nYou have N cups and 1 ball.\n\nThe cups are arranged in a row, from left to right.\n\nYou turned down all the cups, then inserted the ball into the leftmost cup.\n\nThen, you will perform the following Q operations:\n\nThe i-th operation: swap the positions of the A_i-th and B_i-th cups from the left. If one of these cups contains the ball, the ball will also move.\n\nSince you are a magician, you can cast a magic described below:\n\nMagic: When the ball is contained in the i-th cup from the left, teleport the ball into the adjacent cup (that is, the (i-1)-th or (i+1)-th cup, if they exist).\n\nThe magic can be cast before the first operation, between two operations, or after the last operation, but you are allowed to cast it at most once during the whole process.\n\nFind the number of cups with a possibility of containing the ball after all the operations and possibly casting the magic.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq A_i < B_i \\leq N\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN Q\nA_1 B_1\nA_2 B_2\n:\nA_Q B_Q\n\nOutput\n\nPrint the number of cups with a possibility of eventually containing the ball.\n\nSample Input 1\n\n10 3\n1 3\n2 4\n4 5\n\nSample Output 1\n\n4\n\nSample Input 2\n\n20 3\n1 7\n8 20\n1 19\n\nSample Output 2\n\n5", "sample_input": "10 3\n1 3\n2 4\n4 5\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03894", "source_text": "Score : 100 points\n\nProblem Statement\n\nYou have N cups and 1 ball.\n\nThe cups are arranged in a row, from left to right.\n\nYou turned down all the cups, then inserted the ball into the leftmost cup.\n\nThen, you will perform the following Q operations:\n\nThe i-th operation: swap the positions of the A_i-th and B_i-th cups from the left. If one of these cups contains the ball, the ball will also move.\n\nSince you are a magician, you can cast a magic described below:\n\nMagic: When the ball is contained in the i-th cup from the left, teleport the ball into the adjacent cup (that is, the (i-1)-th or (i+1)-th cup, if they exist).\n\nThe magic can be cast before the first operation, between two operations, or after the last operation, but you are allowed to cast it at most once during the whole process.\n\nFind the number of cups with a possibility of containing the ball after all the operations and possibly casting the magic.\n\nConstraints\n\n2 \\leq N \\leq 10^5\n\n1 \\leq Q \\leq 10^5\n\n1 \\leq A_i < B_i \\leq N\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN Q\nA_1 B_1\nA_2 B_2\n:\nA_Q B_Q\n\nOutput\n\nPrint the number of cups with a possibility of eventually containing the ball.\n\nSample Input 1\n\n10 3\n1 3\n2 4\n4 5\n\nSample Output 1\n\n4\n\nSample Input 2\n\n20 3\n1 7\n8 20\n1 19\n\nSample Output 2\n\n5", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6040, "cpu_time_ms": 242, "memory_kb": 29284}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s835979061", "group_id": "codeNet:p03912", "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;; 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 main ()\n (declare (inline sort))\n (let* ((n (read))\n (m (read))\n (xs (make-array n :element-type 'uint32))\n (mod-table (make-array m :element-type 'list :initial-element nil))\n (res 0))\n (dotimes (i n) (setf (aref xs i) (read-fixnum)))\n (setf xs (sort xs #'<))\n (loop for x across xs\n do (push x (aref mod-table (mod x m))))\n (labels ((frob (list pairs rest)\n (cond ((null list)\n (values pairs rest))\n ((null (cdr list))\n (frob (cdr list) pairs (cons (car list) rest)))\n (t (let ((num1 (car list))\n (num2 (cadr list)))\n (if (= num1 num2)\n (frob (cddr list) (cons num1 (cons num2 pairs)) rest)\n (frob (cdr list) pairs (cons (car list) rest))))))))\n (loop for rem from 1 below m\n while (< rem (- m rem))\n do (multiple-value-bind (pairs1 rest1) (frob (aref mod-table rem) nil nil)\n (multiple-value-bind (pairs2 rest2) (frob (aref mod-table (- m rem)) nil nil)\n ;; guarantees |rest1| <= |rest2|\n (let ((minlen (min (length rest1) (length rest2))))\n (when (> (length rest1) (length rest2))\n (rotatef pairs1 pairs2)\n (rotatef rest1 rest2))\n (incf res minlen)\n (setf rest2 (nthcdr minlen rest2))\n (dolist (_ rest2)\n (unless (null pairs1)\n (incf res)\n (pop pairs1)))\n (incf res (floor (length pairs1) 2))\n (incf res (floor (length pairs2) 2))))))\n (incf res (floor (length (aref mod-table 0)) 2))\n (when (evenp m)\n (incf res (floor (length (aref mod-table (floor m 2))) 2)))\n (println res))))\n\n#-swank(main)\n", "language": "Lisp", "metadata": {"date": 1561757726, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03912.html", "problem_id": "p03912", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03912/input.txt", "sample_output_relpath": "derived/input_output/data/p03912/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03912/Lisp/s835979061.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s835979061", "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;; 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 main ()\n (declare (inline sort))\n (let* ((n (read))\n (m (read))\n (xs (make-array n :element-type 'uint32))\n (mod-table (make-array m :element-type 'list :initial-element nil))\n (res 0))\n (dotimes (i n) (setf (aref xs i) (read-fixnum)))\n (setf xs (sort xs #'<))\n (loop for x across xs\n do (push x (aref mod-table (mod x m))))\n (labels ((frob (list pairs rest)\n (cond ((null list)\n (values pairs rest))\n ((null (cdr list))\n (frob (cdr list) pairs (cons (car list) rest)))\n (t (let ((num1 (car list))\n (num2 (cadr list)))\n (if (= num1 num2)\n (frob (cddr list) (cons num1 (cons num2 pairs)) rest)\n (frob (cdr list) pairs (cons (car list) rest))))))))\n (loop for rem from 1 below m\n while (< rem (- m rem))\n do (multiple-value-bind (pairs1 rest1) (frob (aref mod-table rem) nil nil)\n (multiple-value-bind (pairs2 rest2) (frob (aref mod-table (- m rem)) nil nil)\n ;; guarantees |rest1| <= |rest2|\n (let ((minlen (min (length rest1) (length rest2))))\n (when (> (length rest1) (length rest2))\n (rotatef pairs1 pairs2)\n (rotatef rest1 rest2))\n (incf res minlen)\n (setf rest2 (nthcdr minlen rest2))\n (dolist (_ rest2)\n (unless (null pairs1)\n (incf res)\n (pop pairs1)))\n (incf res (floor (length pairs1) 2))\n (incf res (floor (length pairs2) 2))))))\n (incf res (floor (length (aref mod-table 0)) 2))\n (when (evenp m)\n (incf res (floor (length (aref mod-table (floor m 2))) 2)))\n (println res))))\n\n#-swank(main)\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nTakahashi is playing with N cards.\n\nThe i-th card has an integer X_i on it.\n\nTakahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:\n\nThe integers on the two cards are the same.\n\nThe sum of the integers on the two cards is a multiple of M.\n\nFind the maximum number of pairs that can be created.\n\nNote that a card cannot be used in more than one pair.\n\nConstraints\n\n2≦N≦10^5\n\n1≦M≦10^5\n\n1≦X_i≦10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\nX_1 X_2 ... X_N\n\nOutput\n\nPrint the maximum number of pairs that can be created.\n\nSample Input 1\n\n7 5\n3 1 4 1 5 9 2\n\nSample Output 1\n\n3\n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not maximized with this.\n\nSample Input 2\n\n15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 99 99\n\nSample Output 2\n\n6", "sample_input": "7 5\n3 1 4 1 5 9 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03912", "source_text": "Score : 700 points\n\nProblem Statement\n\nTakahashi is playing with N cards.\n\nThe i-th card has an integer X_i on it.\n\nTakahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:\n\nThe integers on the two cards are the same.\n\nThe sum of the integers on the two cards is a multiple of M.\n\nFind the maximum number of pairs that can be created.\n\nNote that a card cannot be used in more than one pair.\n\nConstraints\n\n2≦N≦10^5\n\n1≦M≦10^5\n\n1≦X_i≦10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\nX_1 X_2 ... X_N\n\nOutput\n\nPrint the maximum number of pairs that can be created.\n\nSample Input 1\n\n7 5\n3 1 4 1 5 9 2\n\nSample Output 1\n\n3\n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not maximized with this.\n\nSample Input 2\n\n15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 99 99\n\nSample Output 2\n\n6", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4650, "cpu_time_ms": 295, "memory_kb": 35168}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s948788378", "group_id": "codeNet:p03922", "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 (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.\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 \"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 (list)\n (declare (list list))\n (let ((res 0))\n (map-run-length (lambda (_ count)\n (incf res (ash count -1)))\n list)\n res))\n\n(defun main ()\n (declare (inline sort sb-impl::stable-sort-list))\n (let* ((n (read))\n (m (read))\n (counts (make-array m :element-type 'uint31 :initial-element 0))\n (lists (make-array m :element-type 'list :initial-element nil))\n (res 0))\n (declare (uint62 res))\n (dotimes (i n)\n (let ((x (read-fixnum)))\n (push x (aref lists (mod x m)))\n (incf (aref counts (mod x m)))))\n (dotimes (i m)\n (setf (aref lists i)\n (sort (aref lists i)\n (lambda (x y)\n (< (the fixnum x) (the fixnum y))))))\n (loop for x1 from 1 below (ceiling m 2)\n for x2 = (- m x1)\n for count1 = (aref counts x1)\n for count2 = (aref counts x2)\n do (if (>= count1 count2)\n (progn\n (incf res count2)\n (incf res (min (floor (- count1 count2) 2)\n (calc (aref lists x1)))))\n (progn\n (incf res count1)\n (incf res (min (floor (- count2 count1) 2)\n (calc (aref lists x2)))))))\n (incf res (floor (aref counts 0) 2))\n (when (evenp m)\n (incf res (floor (aref counts (floor m 2)) 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 #+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 \"7 5\n3 1 4 1 5 9 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 99 99\n\"\n \"6\n\")))\n", "language": "Lisp", "metadata": {"date": 1595905319, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03922.html", "problem_id": "p03922", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03922/input.txt", "sample_output_relpath": "derived/input_output/data/p03922/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03922/Lisp/s948788378.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s948788378", "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(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.\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 \"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 (list)\n (declare (list list))\n (let ((res 0))\n (map-run-length (lambda (_ count)\n (incf res (ash count -1)))\n list)\n res))\n\n(defun main ()\n (declare (inline sort sb-impl::stable-sort-list))\n (let* ((n (read))\n (m (read))\n (counts (make-array m :element-type 'uint31 :initial-element 0))\n (lists (make-array m :element-type 'list :initial-element nil))\n (res 0))\n (declare (uint62 res))\n (dotimes (i n)\n (let ((x (read-fixnum)))\n (push x (aref lists (mod x m)))\n (incf (aref counts (mod x m)))))\n (dotimes (i m)\n (setf (aref lists i)\n (sort (aref lists i)\n (lambda (x y)\n (< (the fixnum x) (the fixnum y))))))\n (loop for x1 from 1 below (ceiling m 2)\n for x2 = (- m x1)\n for count1 = (aref counts x1)\n for count2 = (aref counts x2)\n do (if (>= count1 count2)\n (progn\n (incf res count2)\n (incf res (min (floor (- count1 count2) 2)\n (calc (aref lists x1)))))\n (progn\n (incf res count1)\n (incf res (min (floor (- count2 count1) 2)\n (calc (aref lists x2)))))))\n (incf res (floor (aref counts 0) 2))\n (when (evenp m)\n (incf res (floor (aref counts (floor m 2)) 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 #+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 \"7 5\n3 1 4 1 5 9 2\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 99 99\n\"\n \"6\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nTakahashi is playing with N cards.\n\nThe i-th card has an integer X_i on it.\n\nTakahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:\n\nThe integers on the two cards are the same.\n\nThe sum of the integers on the two cards is a multiple of M.\n\nFind the maximum number of pairs that can be created.\n\nNote that a card cannot be used in more than one pair.\n\nConstraints\n\n2≦N≦10^5\n\n1≦M≦10^5\n\n1≦X_i≦10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\nX_1 X_2 ... X_N\n\nOutput\n\nPrint the maximum number of pairs that can be created.\n\nSample Input 1\n\n7 5\n3 1 4 1 5 9 2\n\nSample Output 1\n\n3\n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not maximized with this.\n\nSample Input 2\n\n15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 99 99\n\nSample Output 2\n\n6", "sample_input": "7 5\n3 1 4 1 5 9 2\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03922", "source_text": "Score : 700 points\n\nProblem Statement\n\nTakahashi is playing with N cards.\n\nThe i-th card has an integer X_i on it.\n\nTakahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:\n\nThe integers on the two cards are the same.\n\nThe sum of the integers on the two cards is a multiple of M.\n\nFind the maximum number of pairs that can be created.\n\nNote that a card cannot be used in more than one pair.\n\nConstraints\n\n2≦N≦10^5\n\n1≦M≦10^5\n\n1≦X_i≦10^5\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN M\nX_1 X_2 ... X_N\n\nOutput\n\nPrint the maximum number of pairs that can be created.\n\nSample Input 1\n\n7 5\n3 1 4 1 5 9 2\n\nSample Output 1\n\n3\n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not maximized with this.\n\nSample Input 2\n\n15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 99 99\n\nSample Output 2\n\n6", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7687, "cpu_time_ms": 51, "memory_kb": 27920}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s049138857", "group_id": "codeNet:p03931", "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;;; 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;;;\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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (k (read))\n (as (make-array n :element-type 'uint8))\n (dp (make-array (list (+ n 1) (+ n 1) 256)\n :element-type 'uint31\n :initial-element 0)))\n (declare (uint8 n k))\n (setf (aref dp 0 0 0) 1)\n (dotimes (i n)\n (setf (aref as i) (read)))\n (dotimes (x n)\n (let ((a (aref as x)))\n (dotimes (y (+ n 1))\n (dotimes (z 256)\n (when (< y n)\n (incfmod (aref dp (+ x 1) (+ y 1) (logxor z a))\n (aref dp x y z)))\n (incfmod (aref dp (+ x 1) y z) (aref dp x y z))))))\n (let ((res 0))\n (declare (uint31 res))\n (dotimes (y (+ n 1))\n (incfmod res\n (mod* (aref *fact* y) (aref dp n y k))))\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 2 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 10\n8 7 5\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"25 127\n5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125\n\"\n \"235924722\n\")))\n", "language": "Lisp", "metadata": {"date": 1580970272, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03931.html", "problem_id": "p03931", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03931/input.txt", "sample_output_relpath": "derived/input_output/data/p03931/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03931/Lisp/s049138857.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s049138857", "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;;;\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;;;\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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (k (read))\n (as (make-array n :element-type 'uint8))\n (dp (make-array (list (+ n 1) (+ n 1) 256)\n :element-type 'uint31\n :initial-element 0)))\n (declare (uint8 n k))\n (setf (aref dp 0 0 0) 1)\n (dotimes (i n)\n (setf (aref as i) (read)))\n (dotimes (x n)\n (let ((a (aref as x)))\n (dotimes (y (+ n 1))\n (dotimes (z 256)\n (when (< y n)\n (incfmod (aref dp (+ x 1) (+ y 1) (logxor z a))\n (aref dp x y z)))\n (incfmod (aref dp (+ x 1) y z) (aref dp x y z))))))\n (let ((res 0))\n (declare (uint31 res))\n (dotimes (y (+ n 1))\n (incfmod res\n (mod* (aref *fact* y) (aref dp n y k))))\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 2 3\n\"\n \"3\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 10\n8 7 5\n\"\n \"6\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"25 127\n5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125\n\"\n \"235924722\n\")))\n", "problem_context": "Max Score: $400$ Points\n\nProblem Statement\n\nSample testcase 3 has a mistake, so we erased this case and rejudged all solutions of this problem. (21:01)\n\nSnuke got a sequence $a$ of length $n$ from AtCoder company. All elements in $a$ are distinct.\n\nHe made a sequence $b$, but actually, he is not remembered it.\n\nHowever, he is remembered a few things about sequence $b$.\n\nAll elements in $b$ are distinct.\n\nAll elements in $b$ is in $a$.\n\n$b_1 \\oplus b_2 \\oplus \\cdots \\oplus b_r = k$. ($r$ is length of sequence $b$) [$\\oplus$ means XOR]\n\nFor example, if $a = { 1, 2, 3 }$ and $k = 1$, he can make $b = { 1 }, { 2, 3 }, { 3, 2 }$.\n\nHe wants to restore sequence $b$, but he says that there are too many ways and he can't restore it.\nPlease calculate the ways to make $b$ and help him.\n\nSince the answer can be large, print the answer modulo $1,000,000,007$.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\n$n \\ k$\n$a_1 \\ a_2 \\ \\cdots \\ a_n$\n\nOutput\n\nPrint the number of ways to make sequence $b$.\n\nPrint the answer modulo $1,000,000,007$.\n\nConstraints\n\n$1 \\le n \\le 100$\n\n$1 \\le a_i, k \\le 255$\n\n$i \\neq j \\Rightarrow a_i \\neq a_j$\n\nSubtasks\n\nSubtask 1 [ $50$ points ]\n\n$1 \\le n \\le 4$\n\nSubtask 2 [ $170$ points ]\n\n$1 \\le n \\le 20$\n\nSubtask 3 [ $180$ points ]\n\nThere are no additional constraints.\n\nSample Input 1\n\n3 1\n1 2 3\n\nSample Output 1\n\n3\n\nYou can make 3 patterns: $b = \\{ 1 \\}, \\{ 2, 3 \\}, \\{ 3, 2 \\}$\n\nSample Input 2\n\n3 10\n8 7 5\n\nSample Output 2\n\n6\n\nYou can make 6 patterns: $b = \\{ 5, 7, 8 \\}, \\{ 5, 8, 7 \\}, \\{ 7, 5, 8 \\}, \\{ 7, 8, 5 \\}, \\{ 8, 5, 7 \\}, \\{ 8, 7, 5 \\}$.\n\nSample Input 4\n\n25 127\n5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125\n\nSample Output 4\n\n235924722\n\nPlease output answer mod $1,000,000,007$.\n\nwriter: E869120", "sample_input": "3 1\n1 2 3\n"}, "reference_outputs": ["3\n"], "source_document_id": "p03931", "source_text": "Max Score: $400$ Points\n\nProblem Statement\n\nSample testcase 3 has a mistake, so we erased this case and rejudged all solutions of this problem. (21:01)\n\nSnuke got a sequence $a$ of length $n$ from AtCoder company. All elements in $a$ are distinct.\n\nHe made a sequence $b$, but actually, he is not remembered it.\n\nHowever, he is remembered a few things about sequence $b$.\n\nAll elements in $b$ are distinct.\n\nAll elements in $b$ is in $a$.\n\n$b_1 \\oplus b_2 \\oplus \\cdots \\oplus b_r = k$. ($r$ is length of sequence $b$) [$\\oplus$ means XOR]\n\nFor example, if $a = { 1, 2, 3 }$ and $k = 1$, he can make $b = { 1 }, { 2, 3 }, { 3, 2 }$.\n\nHe wants to restore sequence $b$, but he says that there are too many ways and he can't restore it.\nPlease calculate the ways to make $b$ and help him.\n\nSince the answer can be large, print the answer modulo $1,000,000,007$.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\n$n \\ k$\n$a_1 \\ a_2 \\ \\cdots \\ a_n$\n\nOutput\n\nPrint the number of ways to make sequence $b$.\n\nPrint the answer modulo $1,000,000,007$.\n\nConstraints\n\n$1 \\le n \\le 100$\n\n$1 \\le a_i, k \\le 255$\n\n$i \\neq j \\Rightarrow a_i \\neq a_j$\n\nSubtasks\n\nSubtask 1 [ $50$ points ]\n\n$1 \\le n \\le 4$\n\nSubtask 2 [ $170$ points ]\n\n$1 \\le n \\le 20$\n\nSubtask 3 [ $180$ points ]\n\nThere are no additional constraints.\n\nSample Input 1\n\n3 1\n1 2 3\n\nSample Output 1\n\n3\n\nYou can make 3 patterns: $b = \\{ 1 \\}, \\{ 2, 3 \\}, \\{ 3, 2 \\}$\n\nSample Input 2\n\n3 10\n8 7 5\n\nSample Output 2\n\n6\n\nYou can make 6 patterns: $b = \\{ 5, 7, 8 \\}, \\{ 5, 8, 7 \\}, \\{ 7, 5, 8 \\}, \\{ 7, 8, 5 \\}, \\{ 8, 5, 7 \\}, \\{ 8, 7, 5 \\}$.\n\nSample Input 4\n\n25 127\n5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125\n\nSample Output 4\n\n235924722\n\nPlease output answer mod $1,000,000,007$.\n\nwriter: E869120", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 8192, "cpu_time_ms": 300, "memory_kb": 41440}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s686402658", "group_id": "codeNet:p03932", "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 \"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;;;\n;;; Minimum cost flow (Primal-Dual, O(FElogV))\n;;;\n\n(setf *print-circle* t)\n\n;; COST-TYPE and +INF-COST+ may be changed. (A supposed use case is to adopt\n;; bignum).\n(deftype cost-type () '(signed-byte 32))\n(defconstant +inf-cost+ #x7fffffff)\n(assert (and (typep +inf-cost+ 'cost-type)\n (subtypep 'cost-type 'integer)))\n\n(defstruct (edge (:constructor %make-edge))\n (to nil :type (integer 0 #.most-positive-fixnum))\n (capacity 0 :type (integer 0 #.most-positive-fixnum))\n (cost 0 :type cost-type)\n (reversed nil :type (or null edge)))\n\n(defun push-edge (from-idx to-idx capacity cost graph)\n \"FROM-IDX, TO-IDX := index of vertex\nGRAPH := vector of list of all the edges that goes from the vertex\"\n (declare ((simple-array list (*)) graph)\n (cost-type cost))\n (let* ((dep (%make-edge :to to-idx :capacity capacity :cost cost))\n (ret (%make-edge :to from-idx :capacity 0 :cost (- cost) :reversed dep)))\n (setf (edge-reversed dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n;; binary heap for Dijkstra's algorithm\n(defstruct (fheap (:constructor make-fheap\n (size\n &aux (costs (make-array (1+ size) :element-type 'cost-type))\n (vertices (make-array (1+ size) :element-type 'fixnum)))))\n (costs nil :type (simple-array cost-type (*)))\n (vertices nil :type (simple-array fixnum (*)))\n (position 1 :type (integer 1 #.most-positive-fixnum)))\n\n(defun fheap-push (cost vertex fheap)\n (declare (optimize (speed 3)))\n (symbol-macrolet ((position (fheap-position fheap)))\n (when (>= position (length (fheap-costs fheap)))\n (setf (fheap-costs fheap)\n (adjust-array (fheap-costs fheap) (* position 2))\n (fheap-vertices fheap)\n (adjust-array (fheap-vertices fheap) (* position 2))))\n (let ((costs (fheap-costs fheap))\n (vertices (fheap-vertices fheap)))\n (labels ((update (pos)\n (declare (optimize (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (< (aref costs pos) (aref costs parent-pos))\n (rotatef (aref costs pos) (aref costs parent-pos))\n (rotatef (aref vertices pos) (aref vertices parent-pos))\n (update parent-pos))))))\n (setf (aref costs position) cost\n (aref vertices position) vertex)\n (update position)\n (incf position)\n fheap))))\n\n(defun fheap-pop (fheap)\n (declare #.OPT)\n (symbol-macrolet ((position (fheap-position fheap)))\n (let ((costs (fheap-costs fheap))\n (vertices (fheap-vertices fheap)))\n (labels ((update (pos)\n (declare (optimize (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 (< (aref costs child-pos1) (aref costs child-pos2))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))\n (update child-pos1))\n (unless (< (aref costs pos) (aref costs child-pos2))\n (rotatef (aref costs pos) (aref costs child-pos2))\n (rotatef (aref vertices pos) (aref vertices child-pos2))\n (update child-pos2)))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))))))))\n (multiple-value-prog1 (values (aref costs 1) (aref vertices 1))\n (decf position)\n (setf (aref costs 1) (aref costs position)\n (aref vertices 1) (aref vertices position))\n (update 1))))))\n\n(declaim (inline fheap-empty-p))\n(defun fheap-empty-p (fheap)\n (= (fheap-position fheap) 1))\n\n(declaim (inline fheap-reinitialize))\n(defun fheap-reinitialize (heap)\n (setf (fheap-position heap) 1)\n heap)\n\n(define-condition not-enough-capacity-error (error)\n ((graph :initarg :graph :reader not-enough-capacity-error-graph)\n (flow :initarg :flow :reader not-enough-capacity-error-flow))\n (:report\n (lambda (c s)\n (format s \"Cannot send ~A units of flow on graph ~A due to not enough capacity.\"\n (not-enough-capacity-error-flow c)\n (not-enough-capacity-error-graph c)))))\n\n(defun min-cost-flow! (src-idx dest-idx flow graph &key density)\n \"Returns the minimum cost to send FLOW units from SRC-IDX to DEST-IDX in\nGRAPH. Destructively modifies GRAPH.\n\nDENSITY := nil | the number of edges (assumed to be (size of GRAPH)*2 if NIL)\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) flow)\n ((simple-array list (*)) graph))\n (macrolet ((the-cost-type (form)\n (reduce (lambda (x y) `(,(car form) (the cost-type ,x) (the cost-type ,y)))\n\t\t (cdr form))))\n (let* ((size (length graph))\n (density (or density (* size 2)))\n (prev-vertices (make-array size :element-type 'fixnum :initial-element 0))\n (prev-edges (make-array size :element-type 'edge))\n (potential (make-array size :element-type 'cost-type :initial-element 0))\n (dist (make-array size :element-type 'cost-type))\n (pqueue (make-fheap density))\n (res 0))\n (declare (fixnum density)\n (cost-type res))\n (loop while (> flow 0)\n do (fill dist +inf-cost+)\n (setf (aref dist src-idx) 0)\n (fheap-reinitialize pqueue)\n (fheap-push 0 src-idx pqueue)\n (loop until (fheap-empty-p pqueue)\n do (multiple-value-bind (cost v) (fheap-pop pqueue)\n (declare (cost-type cost)\n (fixnum v))\n (when (<= cost (aref dist v))\n (dolist (edge (aref graph v))\n (let* ((next-v (edge-to edge))\n (next-cost (the-cost-type\n (+ (aref dist v)\n (edge-cost edge)\n (aref potential v)\n (- (aref potential next-v))))))\n (when (and (> (edge-capacity edge) 0)\n (> (aref dist next-v) next-cost))\n (setf (aref dist next-v) next-cost\n (aref prev-vertices next-v) v\n (aref prev-edges next-v) edge)\n (fheap-push next-cost next-v pqueue)))))))\n (when (= (aref dist dest-idx) +inf-cost+)\n (error 'not-enough-capacity-error :flow flow :graph graph))\n (let ((max-flow flow))\n (declare (fixnum max-flow))\n (dotimes (v size)\n (setf (aref potential v)\n (min +inf-cost+\n (+ (aref potential v) (aref dist v)))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (setf max-flow (min max-flow (edge-capacity (aref prev-edges v)))))\n (decf flow max-flow)\n (incf res (the cost-type (* max-flow (aref potential dest-idx))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (decf (edge-capacity (aref prev-edges v)) max-flow)\n (incf (edge-capacity (edge-reversed (aref prev-edges v))) max-flow))))\n res)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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* ((h (read))\n (w (read))\n (as (make-array (list h w) :element-type 'uint31))\n (graph (make-array (* h w 2) :element-type 'list :initial-element nil)))\n (declare (uint16 h w))\n (labels ((encode (y x dir)\n (let ((res (if (eql dir :in)\n (* 2 (+ (* w y) x))\n (+ (* 2 (+ (* w y) x)) 1))))\n res)))\n (dotimes (i h)\n (dotimes (j w)\n (let ((a (read-fixnum)))\n (setf (aref as i j) a)\n (push-edge (encode i j :in)\n (encode i j :out)\n 1\n (- 100000 a)\n graph))))\n (labels ((connect (i1 j1 i2 j2)\n (when (and (< i2 h) (< j2 w))\n (push-edge (encode i1 j1 :out) (encode i2 j2 :in) 1 0 graph))))\n (dotimes (i h)\n (dotimes (j w)\n (connect i j i (+ j 1))\n (connect i j (+ i 1) j))))\n (println (+ (aref as 0 0)\n (aref as (- h 1) (- w 1))\n (- (* 100000 (* 2 (+ h w -3)))\n (min-cost-flow! (encode 0 0 :out)\n (encode (- h 1) (- w 1) :in)\n 2 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 \"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 \"200 200~%\")\n (dotimes (i 200)\n (dotimes (j 200)\n (println (random 100001) out)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; 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 0 5\n2 2 3\n4 2 4\n\"\n \"21\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\"\n \"97\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 0 5\n2 2 3\n4 2 4\n\"\n \"21\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\"\n \"97\n\")))\n", "language": "Lisp", "metadata": {"date": 1577571426, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03932.html", "problem_id": "p03932", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03932/input.txt", "sample_output_relpath": "derived/input_output/data/p03932/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03932/Lisp/s686402658.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s686402658", "user_id": "u352600849"}, "prompt_components": {"gold_output": "21\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 \"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;;;\n;;; Minimum cost flow (Primal-Dual, O(FElogV))\n;;;\n\n(setf *print-circle* t)\n\n;; COST-TYPE and +INF-COST+ may be changed. (A supposed use case is to adopt\n;; bignum).\n(deftype cost-type () '(signed-byte 32))\n(defconstant +inf-cost+ #x7fffffff)\n(assert (and (typep +inf-cost+ 'cost-type)\n (subtypep 'cost-type 'integer)))\n\n(defstruct (edge (:constructor %make-edge))\n (to nil :type (integer 0 #.most-positive-fixnum))\n (capacity 0 :type (integer 0 #.most-positive-fixnum))\n (cost 0 :type cost-type)\n (reversed nil :type (or null edge)))\n\n(defun push-edge (from-idx to-idx capacity cost graph)\n \"FROM-IDX, TO-IDX := index of vertex\nGRAPH := vector of list of all the edges that goes from the vertex\"\n (declare ((simple-array list (*)) graph)\n (cost-type cost))\n (let* ((dep (%make-edge :to to-idx :capacity capacity :cost cost))\n (ret (%make-edge :to from-idx :capacity 0 :cost (- cost) :reversed dep)))\n (setf (edge-reversed dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n;; binary heap for Dijkstra's algorithm\n(defstruct (fheap (:constructor make-fheap\n (size\n &aux (costs (make-array (1+ size) :element-type 'cost-type))\n (vertices (make-array (1+ size) :element-type 'fixnum)))))\n (costs nil :type (simple-array cost-type (*)))\n (vertices nil :type (simple-array fixnum (*)))\n (position 1 :type (integer 1 #.most-positive-fixnum)))\n\n(defun fheap-push (cost vertex fheap)\n (declare (optimize (speed 3)))\n (symbol-macrolet ((position (fheap-position fheap)))\n (when (>= position (length (fheap-costs fheap)))\n (setf (fheap-costs fheap)\n (adjust-array (fheap-costs fheap) (* position 2))\n (fheap-vertices fheap)\n (adjust-array (fheap-vertices fheap) (* position 2))))\n (let ((costs (fheap-costs fheap))\n (vertices (fheap-vertices fheap)))\n (labels ((update (pos)\n (declare (optimize (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (< (aref costs pos) (aref costs parent-pos))\n (rotatef (aref costs pos) (aref costs parent-pos))\n (rotatef (aref vertices pos) (aref vertices parent-pos))\n (update parent-pos))))))\n (setf (aref costs position) cost\n (aref vertices position) vertex)\n (update position)\n (incf position)\n fheap))))\n\n(defun fheap-pop (fheap)\n (declare #.OPT)\n (symbol-macrolet ((position (fheap-position fheap)))\n (let ((costs (fheap-costs fheap))\n (vertices (fheap-vertices fheap)))\n (labels ((update (pos)\n (declare (optimize (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 (< (aref costs child-pos1) (aref costs child-pos2))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))\n (update child-pos1))\n (unless (< (aref costs pos) (aref costs child-pos2))\n (rotatef (aref costs pos) (aref costs child-pos2))\n (rotatef (aref vertices pos) (aref vertices child-pos2))\n (update child-pos2)))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))))))))\n (multiple-value-prog1 (values (aref costs 1) (aref vertices 1))\n (decf position)\n (setf (aref costs 1) (aref costs position)\n (aref vertices 1) (aref vertices position))\n (update 1))))))\n\n(declaim (inline fheap-empty-p))\n(defun fheap-empty-p (fheap)\n (= (fheap-position fheap) 1))\n\n(declaim (inline fheap-reinitialize))\n(defun fheap-reinitialize (heap)\n (setf (fheap-position heap) 1)\n heap)\n\n(define-condition not-enough-capacity-error (error)\n ((graph :initarg :graph :reader not-enough-capacity-error-graph)\n (flow :initarg :flow :reader not-enough-capacity-error-flow))\n (:report\n (lambda (c s)\n (format s \"Cannot send ~A units of flow on graph ~A due to not enough capacity.\"\n (not-enough-capacity-error-flow c)\n (not-enough-capacity-error-graph c)))))\n\n(defun min-cost-flow! (src-idx dest-idx flow graph &key density)\n \"Returns the minimum cost to send FLOW units from SRC-IDX to DEST-IDX in\nGRAPH. Destructively modifies GRAPH.\n\nDENSITY := nil | the number of edges (assumed to be (size of GRAPH)*2 if NIL)\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) flow)\n ((simple-array list (*)) graph))\n (macrolet ((the-cost-type (form)\n (reduce (lambda (x y) `(,(car form) (the cost-type ,x) (the cost-type ,y)))\n\t\t (cdr form))))\n (let* ((size (length graph))\n (density (or density (* size 2)))\n (prev-vertices (make-array size :element-type 'fixnum :initial-element 0))\n (prev-edges (make-array size :element-type 'edge))\n (potential (make-array size :element-type 'cost-type :initial-element 0))\n (dist (make-array size :element-type 'cost-type))\n (pqueue (make-fheap density))\n (res 0))\n (declare (fixnum density)\n (cost-type res))\n (loop while (> flow 0)\n do (fill dist +inf-cost+)\n (setf (aref dist src-idx) 0)\n (fheap-reinitialize pqueue)\n (fheap-push 0 src-idx pqueue)\n (loop until (fheap-empty-p pqueue)\n do (multiple-value-bind (cost v) (fheap-pop pqueue)\n (declare (cost-type cost)\n (fixnum v))\n (when (<= cost (aref dist v))\n (dolist (edge (aref graph v))\n (let* ((next-v (edge-to edge))\n (next-cost (the-cost-type\n (+ (aref dist v)\n (edge-cost edge)\n (aref potential v)\n (- (aref potential next-v))))))\n (when (and (> (edge-capacity edge) 0)\n (> (aref dist next-v) next-cost))\n (setf (aref dist next-v) next-cost\n (aref prev-vertices next-v) v\n (aref prev-edges next-v) edge)\n (fheap-push next-cost next-v pqueue)))))))\n (when (= (aref dist dest-idx) +inf-cost+)\n (error 'not-enough-capacity-error :flow flow :graph graph))\n (let ((max-flow flow))\n (declare (fixnum max-flow))\n (dotimes (v size)\n (setf (aref potential v)\n (min +inf-cost+\n (+ (aref potential v) (aref dist v)))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (setf max-flow (min max-flow (edge-capacity (aref prev-edges v)))))\n (decf flow max-flow)\n (incf res (the cost-type (* max-flow (aref potential dest-idx))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (decf (edge-capacity (aref prev-edges v)) max-flow)\n (incf (edge-capacity (edge-reversed (aref prev-edges v))) max-flow))))\n res)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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* ((h (read))\n (w (read))\n (as (make-array (list h w) :element-type 'uint31))\n (graph (make-array (* h w 2) :element-type 'list :initial-element nil)))\n (declare (uint16 h w))\n (labels ((encode (y x dir)\n (let ((res (if (eql dir :in)\n (* 2 (+ (* w y) x))\n (+ (* 2 (+ (* w y) x)) 1))))\n res)))\n (dotimes (i h)\n (dotimes (j w)\n (let ((a (read-fixnum)))\n (setf (aref as i j) a)\n (push-edge (encode i j :in)\n (encode i j :out)\n 1\n (- 100000 a)\n graph))))\n (labels ((connect (i1 j1 i2 j2)\n (when (and (< i2 h) (< j2 w))\n (push-edge (encode i1 j1 :out) (encode i2 j2 :in) 1 0 graph))))\n (dotimes (i h)\n (dotimes (j w)\n (connect i j i (+ j 1))\n (connect i j (+ i 1) j))))\n (println (+ (aref as 0 0)\n (aref as (- h 1) (- w 1))\n (- (* 100000 (* 2 (+ h w -3)))\n (min-cost-flow! (encode 0 0 :out)\n (encode (- h 1) (- w 1) :in)\n 2 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 \"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 \"200 200~%\")\n (dotimes (i 200)\n (dotimes (j 200)\n (println (random 100001) out)))))\n\n#+swank\n(defun bench (&optional (out (make-broadcast-stream)))\n (time (run *dat-pathname* out)))\n\n;; 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 0 5\n2 2 3\n4 2 4\n\"\n \"21\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\"\n \"97\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 0 5\n2 2 3\n4 2 4\n\"\n \"21\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\"\n \"97\n\")))\n", "problem_context": "Max Score: $600$ Points\n\nProblem Statement\n\nSigma and his brother Sugim are in the $H \\times W$ grid. They wants to buy some souvenirs.\n\nTheir start position is upper-left cell, and the goal position is lower-right cell.\n\nSome cells has a souvenir shop. At $i$-th row and $j$-th column, there is $a_{i, j}$ souvenirs.\n\nIn one move, they can go left, right, down, and up cell.\n\nBut they have little time, so they can move only $H+W-2$ times.\n\nThey wanted to buy souvenirs as many as possible, but they had no computer, so they couldn't get the maximal numbers of souvenirs.\n\nWrite a program and calculate the maximum souvenirs they can get, and help them.\n\nInput\n\nThe input is given from standard input in the following format.\n\n$H \\ W$\n$a_{1, 1} \\ a_{1, 2} \\ \\cdots \\ a_{1, W}$\n$a_{2, 1} \\ a_{2, 2} \\ \\cdots \\ a_{2, W}$\n$\\vdots \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\vdots \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\vdots$\n$a_{H, 1} \\ a_{H, 2} \\ \\cdots \\ a_{H, W}$\n\nOutput\n\nPrint the maximum number of souvenirs they can get.\n\nConstraints\n\n$1 \\le H, W \\le 200$\n\n$0 \\le a_{i, j} \\le 10^5$\n\nSubtasks\n\nSubtask 1 [ 50 points ]\n\nThe testcase in the subtask satisfies $1 \\le H \\le 2$.\n\nSubtask 2 [ 80 points ]\n\nThe testcase in the subtask satisfies $1 \\le H \\le 3$.\n\nSubtask 3 [ 120 points ]\n\nThe testcase in the subtask satisfies $1 \\le H, W \\le 7$.\n\nSubtask 4 [ 150 points ]\n\nThe testcase in the subtask satisfies $1 \\le H, W \\le 30$.\n\nSubtask 5 [ 200 points ]\n\nThere are no additional constraints.\n\nSample Input 1\n\n3 3\n1 0 5\n2 2 3\n4 2 4\n\nSample Output 1\n\n21\n\nThe cell at $i$-th row and $j$-th column is denoted $(i, j)$.\n\nIn this case, one of the optimal solution is this:\n\nSigma moves $(1, 1) -> (1, 2) -> (1, 3) -> (2, 3) -> (3, 3)$.\n\nSugim moves $(1, 1) -> (2, 1) -> (3, 1) -> (3, 2) -> (3, 3)$.\n\nThen, they can get $21$ souvernirs.\n\nSample Input 2\n\n6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\nSample Output 2\n\n97\n\nWriter : square1001", "sample_input": "3 3\n1 0 5\n2 2 3\n4 2 4\n"}, "reference_outputs": ["21\n"], "source_document_id": "p03932", "source_text": "Max Score: $600$ Points\n\nProblem Statement\n\nSigma and his brother Sugim are in the $H \\times W$ grid. They wants to buy some souvenirs.\n\nTheir start position is upper-left cell, and the goal position is lower-right cell.\n\nSome cells has a souvenir shop. At $i$-th row and $j$-th column, there is $a_{i, j}$ souvenirs.\n\nIn one move, they can go left, right, down, and up cell.\n\nBut they have little time, so they can move only $H+W-2$ times.\n\nThey wanted to buy souvenirs as many as possible, but they had no computer, so they couldn't get the maximal numbers of souvenirs.\n\nWrite a program and calculate the maximum souvenirs they can get, and help them.\n\nInput\n\nThe input is given from standard input in the following format.\n\n$H \\ W$\n$a_{1, 1} \\ a_{1, 2} \\ \\cdots \\ a_{1, W}$\n$a_{2, 1} \\ a_{2, 2} \\ \\cdots \\ a_{2, W}$\n$\\vdots \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\vdots \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\vdots$\n$a_{H, 1} \\ a_{H, 2} \\ \\cdots \\ a_{H, W}$\n\nOutput\n\nPrint the maximum number of souvenirs they can get.\n\nConstraints\n\n$1 \\le H, W \\le 200$\n\n$0 \\le a_{i, j} \\le 10^5$\n\nSubtasks\n\nSubtask 1 [ 50 points ]\n\nThe testcase in the subtask satisfies $1 \\le H \\le 2$.\n\nSubtask 2 [ 80 points ]\n\nThe testcase in the subtask satisfies $1 \\le H \\le 3$.\n\nSubtask 3 [ 120 points ]\n\nThe testcase in the subtask satisfies $1 \\le H, W \\le 7$.\n\nSubtask 4 [ 150 points ]\n\nThe testcase in the subtask satisfies $1 \\le H, W \\le 30$.\n\nSubtask 5 [ 200 points ]\n\nThere are no additional constraints.\n\nSample Input 1\n\n3 3\n1 0 5\n2 2 3\n4 2 4\n\nSample Output 1\n\n21\n\nThe cell at $i$-th row and $j$-th column is denoted $(i, j)$.\n\nIn this case, one of the optimal solution is this:\n\nSigma moves $(1, 1) -> (1, 2) -> (1, 3) -> (2, 3) -> (3, 3)$.\n\nSugim moves $(1, 1) -> (2, 1) -> (3, 1) -> (3, 2) -> (3, 3)$.\n\nThen, they can get $21$ souvernirs.\n\nSample Input 2\n\n6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\nSample Output 2\n\n97\n\nWriter : square1001", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14834, "cpu_time_ms": 371, "memory_kb": 49892}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s363110820", "group_id": "codeNet:p03932", "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 \"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;;;\n;;; Minimum cost flow (Primal-Dual, O(FElogV))\n;;;\n\n(setf *print-circle* t)\n\n;; COST-TYPE and +INF-COST+ may be changed. (A supposed use case is to adopt\n;; bignum).\n(deftype cost-type () 'fixnum)\n(defconstant +inf-cost+ most-positive-fixnum)\n(assert (and (typep +inf-cost+ 'cost-type)\n (subtypep 'cost-type 'integer)))\n\n(defstruct (edge (:constructor %make-edge))\n (to nil :type (integer 0 #.most-positive-fixnum))\n (capacity 0 :type (integer 0 #.most-positive-fixnum))\n (cost 0 :type cost-type)\n (reversed nil :type (or null edge)))\n\n(defun push-edge (from-idx to-idx capacity cost graph)\n \"FROM-IDX, TO-IDX := index of vertex\nGRAPH := vector of list of all the edges that goes from the vertex\"\n (declare ((simple-array list (*)) graph)\n (cost-type cost))\n (let* ((dep (%make-edge :to to-idx :capacity capacity :cost cost))\n (ret (%make-edge :to from-idx :capacity 0 :cost (- cost) :reversed dep)))\n (setf (edge-reversed dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n;; binary heap for Dijkstra's algorithm\n(defstruct (fheap (:constructor make-fheap\n (size\n &aux (costs (make-array (1+ size) :element-type 'cost-type))\n (vertices (make-array (1+ size) :element-type 'fixnum)))))\n (costs nil :type (simple-array cost-type (*)))\n (vertices nil :type (simple-array fixnum (*)))\n (position 1 :type (integer 1 #.most-positive-fixnum)))\n\n(defun fheap-push (cost vertex fheap)\n (declare (optimize (speed 3)))\n (symbol-macrolet ((position (fheap-position fheap)))\n (when (>= position (length (fheap-costs fheap)))\n (setf (fheap-costs fheap)\n (adjust-array (fheap-costs fheap) (* position 2))\n (fheap-vertices fheap)\n (adjust-array (fheap-vertices fheap) (* position 2))))\n (let ((costs (fheap-costs fheap))\n (vertices (fheap-vertices fheap)))\n (labels ((update (pos)\n (declare (optimize (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (< (aref costs pos) (aref costs parent-pos))\n (rotatef (aref costs pos) (aref costs parent-pos))\n (rotatef (aref vertices pos) (aref vertices parent-pos))\n (update parent-pos))))))\n (setf (aref costs position) cost\n (aref vertices position) vertex)\n (update position)\n (incf position)\n fheap))))\n\n(defun fheap-pop (fheap)\n (declare (optimize (speed 3)))\n (symbol-macrolet ((position (fheap-position fheap)))\n (let ((costs (fheap-costs fheap))\n (vertices (fheap-vertices fheap)))\n (labels ((update (pos)\n (declare (optimize (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 (< (aref costs child-pos1) (aref costs child-pos2))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))\n (update child-pos1))\n (unless (< (aref costs pos) (aref costs child-pos2))\n (rotatef (aref costs pos) (aref costs child-pos2))\n (rotatef (aref vertices pos) (aref vertices child-pos2))\n (update child-pos2)))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))))))))\n (multiple-value-prog1 (values (aref costs 1) (aref vertices 1))\n (decf position)\n (setf (aref costs 1) (aref costs position)\n (aref vertices 1) (aref vertices position))\n (update 1))))))\n\n(declaim (inline fheap-empty-p))\n(defun fheap-empty-p (fheap)\n (= (fheap-position fheap) 1))\n\n(declaim (inline fheap-reinitialize))\n(defun fheap-reinitialize (heap)\n (setf (fheap-position heap) 1)\n heap)\n\n(define-condition not-enough-capacity-error (error)\n ((graph :initarg :graph :reader not-enough-capacity-error-graph)\n (flow :initarg :flow :reader not-enough-capacity-error-flow))\n (:report\n (lambda (c s)\n (format s \"Cannot send ~A units of flow on graph ~A due to not enough capacity.\"\n (not-enough-capacity-error-flow c)\n (not-enough-capacity-error-graph c)))))\n\n(defun min-cost-flow! (src-idx dest-idx flow graph &key density)\n \"Returns the minimum cost to send FLOW units from SRC-IDX to DEST-IDX in\nGRAPH. Destructively modifies GRAPH.\n\nDENSITY := nil | the number of edges (assumed to be (size of GRAPH)*2 if NIL)\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) flow)\n ((simple-array list (*)) graph))\n (macrolet ((the-cost-type (form)\n (reduce (lambda (x y) `(,(car form) (the cost-type ,x) (the cost-type ,y)))\n\t\t (cdr form))))\n (let* ((size (length graph))\n (density (or density (* size 2)))\n (prev-vertices (make-array size :element-type 'fixnum :initial-element 0))\n (prev-edges (make-array size :element-type 'edge))\n (potential (make-array size :element-type 'cost-type :initial-element 0))\n (dist (make-array size :element-type 'cost-type))\n (pqueue (make-fheap density))\n (res 0))\n (declare (fixnum density)\n (cost-type res))\n (loop while (> flow 0)\n do (fill dist +inf-cost+)\n (setf (aref dist src-idx) 0)\n (fheap-reinitialize pqueue)\n (fheap-push 0 src-idx pqueue)\n (loop until (fheap-empty-p pqueue)\n do (multiple-value-bind (cost v) (fheap-pop pqueue)\n (declare (cost-type cost)\n (fixnum v))\n (when (<= cost (aref dist v))\n (dolist (edge (aref graph v))\n (let* ((next-v (edge-to edge))\n (next-cost (the-cost-type\n (+ (aref dist v)\n (edge-cost edge)\n (aref potential v)\n (- (aref potential next-v))))))\n (when (and (> (edge-capacity edge) 0)\n (> (aref dist next-v) next-cost))\n (setf (aref dist next-v) next-cost\n (aref prev-vertices next-v) v\n (aref prev-edges next-v) edge)\n (fheap-push next-cost next-v pqueue)))))))\n (when (= (aref dist dest-idx) +inf-cost+)\n (error 'not-enough-capacity-error :flow flow :graph graph))\n (let ((max-flow flow))\n (declare (fixnum max-flow))\n (dotimes (v size)\n (setf (aref potential v)\n (min +inf-cost+\n (+ (aref potential v) (aref dist v)))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (setf max-flow (min max-flow (edge-capacity (aref prev-edges v)))))\n (decf flow max-flow)\n (incf res (the cost-type (* max-flow (aref potential dest-idx))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (decf (edge-capacity (aref prev-edges v)) max-flow)\n (incf (edge-capacity (edge-reversed (aref prev-edges v))) max-flow))))\n res)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (as (make-array (list h w) :element-type 'uint31))\n (graph (make-array (* h w 2) :element-type 'list :initial-element nil)))\n (declare (uint16 h w))\n (labels ((encode (y x dir)\n (let ((res (if (eql dir :in)\n (* 2 (+ (* w y) x))\n (+ (* 2 (+ (* w y) x)) 1))))\n res)))\n (dotimes (i h)\n (dotimes (j w)\n (let ((a (read-fixnum)))\n (setf (aref as i j) a)\n (push-edge (encode i j :in)\n (encode i j :out)\n 1\n (- a)\n graph))))\n (labels ((connect (i1 j1 i2 j2)\n (when (and (< i2 h) (< j2 w))\n (push-edge (encode i1 j1 :out) (encode i2 j2 :in) 1 0 graph))))\n (dotimes (i h)\n (dotimes (j w)\n (connect i j i (+ j 1))\n (connect i j (+ i 1) j))))\n (println (+ (aref as 0 0)\n (aref as (- h 1) (- w 1))\n (- (min-cost-flow! (encode 0 0 :out)\n (encode (- h 1) (- w 1) :in)\n 2 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 \"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\n1 0 5\n2 2 3\n4 2 4\n\"\n \"21\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\"\n \"97\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 0 5\n2 2 3\n4 2 4\n\"\n \"21\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\"\n \"97\n\")))\n", "language": "Lisp", "metadata": {"date": 1577570222, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03932.html", "problem_id": "p03932", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03932/input.txt", "sample_output_relpath": "derived/input_output/data/p03932/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03932/Lisp/s363110820.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s363110820", "user_id": "u352600849"}, "prompt_components": {"gold_output": "21\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 \"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;;;\n;;; Minimum cost flow (Primal-Dual, O(FElogV))\n;;;\n\n(setf *print-circle* t)\n\n;; COST-TYPE and +INF-COST+ may be changed. (A supposed use case is to adopt\n;; bignum).\n(deftype cost-type () 'fixnum)\n(defconstant +inf-cost+ most-positive-fixnum)\n(assert (and (typep +inf-cost+ 'cost-type)\n (subtypep 'cost-type 'integer)))\n\n(defstruct (edge (:constructor %make-edge))\n (to nil :type (integer 0 #.most-positive-fixnum))\n (capacity 0 :type (integer 0 #.most-positive-fixnum))\n (cost 0 :type cost-type)\n (reversed nil :type (or null edge)))\n\n(defun push-edge (from-idx to-idx capacity cost graph)\n \"FROM-IDX, TO-IDX := index of vertex\nGRAPH := vector of list of all the edges that goes from the vertex\"\n (declare ((simple-array list (*)) graph)\n (cost-type cost))\n (let* ((dep (%make-edge :to to-idx :capacity capacity :cost cost))\n (ret (%make-edge :to from-idx :capacity 0 :cost (- cost) :reversed dep)))\n (setf (edge-reversed dep) ret)\n (push dep (aref graph from-idx))\n (push ret (aref graph to-idx))))\n\n;; binary heap for Dijkstra's algorithm\n(defstruct (fheap (:constructor make-fheap\n (size\n &aux (costs (make-array (1+ size) :element-type 'cost-type))\n (vertices (make-array (1+ size) :element-type 'fixnum)))))\n (costs nil :type (simple-array cost-type (*)))\n (vertices nil :type (simple-array fixnum (*)))\n (position 1 :type (integer 1 #.most-positive-fixnum)))\n\n(defun fheap-push (cost vertex fheap)\n (declare (optimize (speed 3)))\n (symbol-macrolet ((position (fheap-position fheap)))\n (when (>= position (length (fheap-costs fheap)))\n (setf (fheap-costs fheap)\n (adjust-array (fheap-costs fheap) (* position 2))\n (fheap-vertices fheap)\n (adjust-array (fheap-vertices fheap) (* position 2))))\n (let ((costs (fheap-costs fheap))\n (vertices (fheap-vertices fheap)))\n (labels ((update (pos)\n (declare (optimize (safety 0)))\n (unless (= pos 1)\n (let ((parent-pos (ash pos -1)))\n (when (< (aref costs pos) (aref costs parent-pos))\n (rotatef (aref costs pos) (aref costs parent-pos))\n (rotatef (aref vertices pos) (aref vertices parent-pos))\n (update parent-pos))))))\n (setf (aref costs position) cost\n (aref vertices position) vertex)\n (update position)\n (incf position)\n fheap))))\n\n(defun fheap-pop (fheap)\n (declare (optimize (speed 3)))\n (symbol-macrolet ((position (fheap-position fheap)))\n (let ((costs (fheap-costs fheap))\n (vertices (fheap-vertices fheap)))\n (labels ((update (pos)\n (declare (optimize (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 (< (aref costs child-pos1) (aref costs child-pos2))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))\n (update child-pos1))\n (unless (< (aref costs pos) (aref costs child-pos2))\n (rotatef (aref costs pos) (aref costs child-pos2))\n (rotatef (aref vertices pos) (aref vertices child-pos2))\n (update child-pos2)))\n (unless (< (aref costs pos) (aref costs child-pos1))\n (rotatef (aref costs pos) (aref costs child-pos1))\n (rotatef (aref vertices pos) (aref vertices child-pos1))))))))\n (multiple-value-prog1 (values (aref costs 1) (aref vertices 1))\n (decf position)\n (setf (aref costs 1) (aref costs position)\n (aref vertices 1) (aref vertices position))\n (update 1))))))\n\n(declaim (inline fheap-empty-p))\n(defun fheap-empty-p (fheap)\n (= (fheap-position fheap) 1))\n\n(declaim (inline fheap-reinitialize))\n(defun fheap-reinitialize (heap)\n (setf (fheap-position heap) 1)\n heap)\n\n(define-condition not-enough-capacity-error (error)\n ((graph :initarg :graph :reader not-enough-capacity-error-graph)\n (flow :initarg :flow :reader not-enough-capacity-error-flow))\n (:report\n (lambda (c s)\n (format s \"Cannot send ~A units of flow on graph ~A due to not enough capacity.\"\n (not-enough-capacity-error-flow c)\n (not-enough-capacity-error-graph c)))))\n\n(defun min-cost-flow! (src-idx dest-idx flow graph &key density)\n \"Returns the minimum cost to send FLOW units from SRC-IDX to DEST-IDX in\nGRAPH. Destructively modifies GRAPH.\n\nDENSITY := nil | the number of edges (assumed to be (size of GRAPH)*2 if NIL)\"\n (declare (optimize (speed 3))\n ((integer 0 #.most-positive-fixnum) flow)\n ((simple-array list (*)) graph))\n (macrolet ((the-cost-type (form)\n (reduce (lambda (x y) `(,(car form) (the cost-type ,x) (the cost-type ,y)))\n\t\t (cdr form))))\n (let* ((size (length graph))\n (density (or density (* size 2)))\n (prev-vertices (make-array size :element-type 'fixnum :initial-element 0))\n (prev-edges (make-array size :element-type 'edge))\n (potential (make-array size :element-type 'cost-type :initial-element 0))\n (dist (make-array size :element-type 'cost-type))\n (pqueue (make-fheap density))\n (res 0))\n (declare (fixnum density)\n (cost-type res))\n (loop while (> flow 0)\n do (fill dist +inf-cost+)\n (setf (aref dist src-idx) 0)\n (fheap-reinitialize pqueue)\n (fheap-push 0 src-idx pqueue)\n (loop until (fheap-empty-p pqueue)\n do (multiple-value-bind (cost v) (fheap-pop pqueue)\n (declare (cost-type cost)\n (fixnum v))\n (when (<= cost (aref dist v))\n (dolist (edge (aref graph v))\n (let* ((next-v (edge-to edge))\n (next-cost (the-cost-type\n (+ (aref dist v)\n (edge-cost edge)\n (aref potential v)\n (- (aref potential next-v))))))\n (when (and (> (edge-capacity edge) 0)\n (> (aref dist next-v) next-cost))\n (setf (aref dist next-v) next-cost\n (aref prev-vertices next-v) v\n (aref prev-edges next-v) edge)\n (fheap-push next-cost next-v pqueue)))))))\n (when (= (aref dist dest-idx) +inf-cost+)\n (error 'not-enough-capacity-error :flow flow :graph graph))\n (let ((max-flow flow))\n (declare (fixnum max-flow))\n (dotimes (v size)\n (setf (aref potential v)\n (min +inf-cost+\n (+ (aref potential v) (aref dist v)))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (setf max-flow (min max-flow (edge-capacity (aref prev-edges v)))))\n (decf flow max-flow)\n (incf res (the cost-type (* max-flow (aref potential dest-idx))))\n (do ((v dest-idx (aref prev-vertices v)))\n ((= v src-idx))\n (decf (edge-capacity (aref prev-edges v)) max-flow)\n (incf (edge-capacity (edge-reversed (aref prev-edges v))) max-flow))))\n res)))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (as (make-array (list h w) :element-type 'uint31))\n (graph (make-array (* h w 2) :element-type 'list :initial-element nil)))\n (declare (uint16 h w))\n (labels ((encode (y x dir)\n (let ((res (if (eql dir :in)\n (* 2 (+ (* w y) x))\n (+ (* 2 (+ (* w y) x)) 1))))\n res)))\n (dotimes (i h)\n (dotimes (j w)\n (let ((a (read-fixnum)))\n (setf (aref as i j) a)\n (push-edge (encode i j :in)\n (encode i j :out)\n 1\n (- a)\n graph))))\n (labels ((connect (i1 j1 i2 j2)\n (when (and (< i2 h) (< j2 w))\n (push-edge (encode i1 j1 :out) (encode i2 j2 :in) 1 0 graph))))\n (dotimes (i h)\n (dotimes (j w)\n (connect i j i (+ j 1))\n (connect i j (+ i 1) j))))\n (println (+ (aref as 0 0)\n (aref as (- h 1) (- w 1))\n (- (min-cost-flow! (encode 0 0 :out)\n (encode (- h 1) (- w 1) :in)\n 2 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 \"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\n1 0 5\n2 2 3\n4 2 4\n\"\n \"21\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\"\n \"97\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"3 3\n1 0 5\n2 2 3\n4 2 4\n\"\n \"21\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\"\n \"97\n\")))\n", "problem_context": "Max Score: $600$ Points\n\nProblem Statement\n\nSigma and his brother Sugim are in the $H \\times W$ grid. They wants to buy some souvenirs.\n\nTheir start position is upper-left cell, and the goal position is lower-right cell.\n\nSome cells has a souvenir shop. At $i$-th row and $j$-th column, there is $a_{i, j}$ souvenirs.\n\nIn one move, they can go left, right, down, and up cell.\n\nBut they have little time, so they can move only $H+W-2$ times.\n\nThey wanted to buy souvenirs as many as possible, but they had no computer, so they couldn't get the maximal numbers of souvenirs.\n\nWrite a program and calculate the maximum souvenirs they can get, and help them.\n\nInput\n\nThe input is given from standard input in the following format.\n\n$H \\ W$\n$a_{1, 1} \\ a_{1, 2} \\ \\cdots \\ a_{1, W}$\n$a_{2, 1} \\ a_{2, 2} \\ \\cdots \\ a_{2, W}$\n$\\vdots \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\vdots \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\vdots$\n$a_{H, 1} \\ a_{H, 2} \\ \\cdots \\ a_{H, W}$\n\nOutput\n\nPrint the maximum number of souvenirs they can get.\n\nConstraints\n\n$1 \\le H, W \\le 200$\n\n$0 \\le a_{i, j} \\le 10^5$\n\nSubtasks\n\nSubtask 1 [ 50 points ]\n\nThe testcase in the subtask satisfies $1 \\le H \\le 2$.\n\nSubtask 2 [ 80 points ]\n\nThe testcase in the subtask satisfies $1 \\le H \\le 3$.\n\nSubtask 3 [ 120 points ]\n\nThe testcase in the subtask satisfies $1 \\le H, W \\le 7$.\n\nSubtask 4 [ 150 points ]\n\nThe testcase in the subtask satisfies $1 \\le H, W \\le 30$.\n\nSubtask 5 [ 200 points ]\n\nThere are no additional constraints.\n\nSample Input 1\n\n3 3\n1 0 5\n2 2 3\n4 2 4\n\nSample Output 1\n\n21\n\nThe cell at $i$-th row and $j$-th column is denoted $(i, j)$.\n\nIn this case, one of the optimal solution is this:\n\nSigma moves $(1, 1) -> (1, 2) -> (1, 3) -> (2, 3) -> (3, 3)$.\n\nSugim moves $(1, 1) -> (2, 1) -> (3, 1) -> (3, 2) -> (3, 3)$.\n\nThen, they can get $21$ souvernirs.\n\nSample Input 2\n\n6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\nSample Output 2\n\n97\n\nWriter : square1001", "sample_input": "3 3\n1 0 5\n2 2 3\n4 2 4\n"}, "reference_outputs": ["21\n"], "source_document_id": "p03932", "source_text": "Max Score: $600$ Points\n\nProblem Statement\n\nSigma and his brother Sugim are in the $H \\times W$ grid. They wants to buy some souvenirs.\n\nTheir start position is upper-left cell, and the goal position is lower-right cell.\n\nSome cells has a souvenir shop. At $i$-th row and $j$-th column, there is $a_{i, j}$ souvenirs.\n\nIn one move, they can go left, right, down, and up cell.\n\nBut they have little time, so they can move only $H+W-2$ times.\n\nThey wanted to buy souvenirs as many as possible, but they had no computer, so they couldn't get the maximal numbers of souvenirs.\n\nWrite a program and calculate the maximum souvenirs they can get, and help them.\n\nInput\n\nThe input is given from standard input in the following format.\n\n$H \\ W$\n$a_{1, 1} \\ a_{1, 2} \\ \\cdots \\ a_{1, W}$\n$a_{2, 1} \\ a_{2, 2} \\ \\cdots \\ a_{2, W}$\n$\\vdots \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\vdots \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\vdots$\n$a_{H, 1} \\ a_{H, 2} \\ \\cdots \\ a_{H, W}$\n\nOutput\n\nPrint the maximum number of souvenirs they can get.\n\nConstraints\n\n$1 \\le H, W \\le 200$\n\n$0 \\le a_{i, j} \\le 10^5$\n\nSubtasks\n\nSubtask 1 [ 50 points ]\n\nThe testcase in the subtask satisfies $1 \\le H \\le 2$.\n\nSubtask 2 [ 80 points ]\n\nThe testcase in the subtask satisfies $1 \\le H \\le 3$.\n\nSubtask 3 [ 120 points ]\n\nThe testcase in the subtask satisfies $1 \\le H, W \\le 7$.\n\nSubtask 4 [ 150 points ]\n\nThe testcase in the subtask satisfies $1 \\le H, W \\le 30$.\n\nSubtask 5 [ 200 points ]\n\nThere are no additional constraints.\n\nSample Input 1\n\n3 3\n1 0 5\n2 2 3\n4 2 4\n\nSample Output 1\n\n21\n\nThe cell at $i$-th row and $j$-th column is denoted $(i, j)$.\n\nIn this case, one of the optimal solution is this:\n\nSigma moves $(1, 1) -> (1, 2) -> (1, 3) -> (2, 3) -> (3, 3)$.\n\nSugim moves $(1, 1) -> (2, 1) -> (3, 1) -> (3, 2) -> (3, 3)$.\n\nThen, they can get $21$ souvernirs.\n\nSample Input 2\n\n6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8\n\nSample Output 2\n\n97\n\nWriter : square1001", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 14679, "cpu_time_ms": 2104, "memory_kb": 51940}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s259235935", "group_id": "codeNet:p03934", "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;;; 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 ((unsigned-byte 62) a b))\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 (a b)\n \"Is the operator to compute and update LAZY value. A is the current LAZY value\nand B is operand.\"\n (declare ((unsigned-byte 62) 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 (acc x size)\n \"Is the operator to update ACCUMULATOR (and VALUE) based on LAZY value. ACC is\nthe current ACCUMULATOR value and X is the LAZY value. SIZE is the length of the\nspecified interval.\"\n (declare ((unsigned-byte 62) acc x)\n (ignorable size))\n (+ acc x))\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 (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-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 (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(defun make-itreap (size &key initial-element)\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 (or initial-element +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 (update-count node)\n (update-accumulator 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 the elements in ITREAP.\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) index))\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 #.OPT\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(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 itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) 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(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the range ITREAP[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 (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-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 (force-down itreap)\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(defun itreap-update (itreap operand l r)\n \"Updates ITREAP[i] := (OP ITREAP[i] OPERAND) for all i in [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 (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(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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (q (read))\n (dp (make-itreap n :initial-element 0)))\n (declare (uint31 n q))\n (dotimes (_ q)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (declare (uint31 a) (uint62 b))\n (loop until (zerop b)\n for min of-type uint62 = (itreap-query dp 0 a)\n for argmin of-type uint31 = (itreap-range-bisect-left dp min #'>)\n when (zerop argmin)\n do (multiple-value-bind (quot rem) (floor b a)\n (itreap-update dp quot 0 a)\n (itreap-update dp 1 0 rem)\n (setq b 0))\n else\n do (let ((min2 (itreap-ref dp (- argmin 1))))\n (declare (uint62 min2))\n (multiple-value-bind (quot rem) (floor b (- a argmin))\n (declare (uint62 quot rem))\n (cond ((or (< (+ min quot) min2)\n (and (= (+ min quot) min2) (zerop rem)))\n (itreap-update dp quot argmin a)\n (itreap-update dp 1 argmin (+ argmin rem))\n (setq b 0))\n ((= (+ min quot) min2)\n (itreap-update dp quot argmin a)\n (setq b rem))\n (t\n (assert (> (+ min quot) min2))\n (itreap-update dp (- min2 min) argmin a)\n (decf b (* (- min2 min) (- a argmin))))))))))\n (itreap-map #'println 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 \"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 \"9 3\n5 11\n8 4\n4 7\n\"\n \"4\n4\n4\n4\n2\n2\n1\n1\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 6\n3 5\n6 11\n1 6\n4 7\n5 2\n2 5\n\"\n \"10\n10\n5\n5\n4\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 6\n1 1\n2 1\n3 1\n1 1\n5 1\n3 1\n\"\n \"2\n2\n1\n1\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n10 10\n9 20\n8 30\n7 40\n6 50\n5 60\n4 70\n3 80\n2 90\n1 100\n\"\n \"223\n123\n77\n50\n33\n21\n12\n7\n3\n1\n\")))\n", "language": "Lisp", "metadata": {"date": 1580974839, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03934.html", "problem_id": "p03934", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03934/input.txt", "sample_output_relpath": "derived/input_output/data/p03934/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03934/Lisp/s259235935.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s259235935", "user_id": "u352600849"}, "prompt_components": {"gold_output": "4\n4\n4\n4\n2\n2\n1\n1\n0\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;;; 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 ((unsigned-byte 62) a b))\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 (a b)\n \"Is the operator to compute and update LAZY value. A is the current LAZY value\nand B is operand.\"\n (declare ((unsigned-byte 62) 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 (acc x size)\n \"Is the operator to update ACCUMULATOR (and VALUE) based on LAZY value. ACC is\nthe current ACCUMULATOR value and X is the LAZY value. SIZE is the length of the\nspecified interval.\"\n (declare ((unsigned-byte 62) acc x)\n (ignorable size))\n (+ acc x))\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 (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-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 (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(defun make-itreap (size &key initial-element)\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 (or initial-element +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 (update-count node)\n (update-accumulator 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 the elements in ITREAP.\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) index))\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 #.OPT\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(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 itreap-ref (itreap index)\n \"Returns the element ITREAP[INDEX].\"\n (declare #.OPT\n ((integer 0 #.most-positive-fixnum) 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(defun itreap-query (itreap l r)\n \"Queries the `sum' (w.r.t. OP) of the range ITREAP[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 (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-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 (force-down itreap)\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(defun itreap-update (itreap operand l r)\n \"Updates ITREAP[i] := (OP ITREAP[i] OPERAND) for all i in [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 (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(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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (q (read))\n (dp (make-itreap n :initial-element 0)))\n (declare (uint31 n q))\n (dotimes (_ q)\n (let ((a (read-fixnum))\n (b (read-fixnum)))\n (declare (uint31 a) (uint62 b))\n (loop until (zerop b)\n for min of-type uint62 = (itreap-query dp 0 a)\n for argmin of-type uint31 = (itreap-range-bisect-left dp min #'>)\n when (zerop argmin)\n do (multiple-value-bind (quot rem) (floor b a)\n (itreap-update dp quot 0 a)\n (itreap-update dp 1 0 rem)\n (setq b 0))\n else\n do (let ((min2 (itreap-ref dp (- argmin 1))))\n (declare (uint62 min2))\n (multiple-value-bind (quot rem) (floor b (- a argmin))\n (declare (uint62 quot rem))\n (cond ((or (< (+ min quot) min2)\n (and (= (+ min quot) min2) (zerop rem)))\n (itreap-update dp quot argmin a)\n (itreap-update dp 1 argmin (+ argmin rem))\n (setq b 0))\n ((= (+ min quot) min2)\n (itreap-update dp quot argmin a)\n (setq b rem))\n (t\n (assert (> (+ min quot) min2))\n (itreap-update dp (- min2 min) argmin a)\n (decf b (* (- min2 min) (- a argmin))))))))))\n (itreap-map #'println 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 \"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 \"9 3\n5 11\n8 4\n4 7\n\"\n \"4\n4\n4\n4\n2\n2\n1\n1\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 6\n3 5\n6 11\n1 6\n4 7\n5 2\n2 5\n\"\n \"10\n10\n5\n5\n4\n2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 6\n1 1\n2 1\n3 1\n1 1\n5 1\n3 1\n\"\n \"2\n2\n1\n1\n0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"10 10\n10 10\n9 20\n8 30\n7 40\n6 50\n5 60\n4 70\n3 80\n2 90\n1 100\n\"\n \"223\n123\n77\n50\n33\n21\n12\n7\n3\n1\n\")))\n", "problem_context": "Max Score: $1200$ Points\n\nProblem statement\n\nThere are $N$ customers in a restaurant. Each customer is numbered $1$ through $N$.\n\nA sushi chef carried out $Q$ operations for customers.\n\nThe $i$-th operation is follows:\n\nThe sushi chef chooses a customer whose number of dishes of sushi eaten is minimum, in customer $1, 2, 3, \\dots, a_i$. If there are multiple customers who are minimum numbers of dishes, he selects the minimum-numbered customers.\n\nHe puts a dish of sushi on the selected seats.\n\nA customer who have selected for professional eats this sushi.\n\nRepeat 1-3, $b_i$ times.\n\nPlease calculate the number of dishes of sushi that have been eaten by each customer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\n$N \\ Q$\n$a_1 \\ b_1$\n$a_2 \\ b_2$\n$ : \\ : $\n$a_Q \\ b_Q$\n\nOutput\n\nYou have to print $N$ lines.\n\nThe $i$-th line should contain the number of dishes of sushi had eaten for customer $i (1 \\le i \\le N)$.\n\nConstraints\n\n$3 \\le N, Q \\le 100,000$\n\n$1 \\le a_i \\le N$\n\n$1 \\le b_i \\le 10^{12}$\n\nAny final results do not exceed $2 \\times 10^{13}$.\n\nSubtasks\n\nSubtask 1 [ $60$ points ]\n\n$N, Q \\le 100$\n\n$b_i = 1$\n\nSubtask 2 [ $400$ points ]\n\n$N, Q \\le 100$\n\n$b_i \\le 10^{12}$\n\nSubtask 3 [ $240$ points ]\n\n$N, Q \\le 100,000$\n\n$b_i = 1$\n\nSubtask 4 [ $500$ points ]\n\nThere are no additional constraints.\n\nSample Input 1\n\n9 3\n5 11\n8 4\n4 7\n\nSample Output 1\n\n4\n4\n4\n4\n2\n2\n1\n1\n0\n\nThe change of the number of dishes of sushi have eaten is following:\n\nCustomer 1\n\nCustomer 2\n\nCustomer 3\n\nCustomer 4\n\nCustomer 5\n\nCustomer 6\n\nCustomer 7\n\nCustomer 8\n\nCustomer 9\n\n1st Operation\n\n3\n\n2\n\n2\n\n2\n\n2\n\n0\n\n0\n\n0\n\n0\n\n2nd Operation\n\n3\n\n2\n\n2\n\n2\n\n2\n\n2\n\n1\n\n1\n\n0\n\n3rd Operation\n\n4\n\n4\n\n4\n\n4\n\n2\n\n2\n\n1\n\n1\n\n0\n\nSample Input 2\n\n6 6\n3 5\n6 11\n1 6\n4 7\n5 2\n2 5\n\nSample Output 2\n\n10\n10\n5\n5\n4\n2\n\nSample Input 3\n\n5 6\n1 1\n2 1\n3 1\n1 1\n5 1\n3 1\n\nSample Output 3\n\n2\n2\n1\n1\n0\n\nSample Input 4\n\n10 10\n10 10\n9 20\n8 30\n7 40\n6 50\n5 60\n4 70\n3 80\n2 90\n1 100\n\nSample Output 4\n\n223\n123\n77\n50\n33\n21\n12\n7\n3\n1\n\nWriter: E869120", "sample_input": "9 3\n5 11\n8 4\n4 7\n"}, "reference_outputs": ["4\n4\n4\n4\n2\n2\n1\n1\n0\n"], "source_document_id": "p03934", "source_text": "Max Score: $1200$ Points\n\nProblem statement\n\nThere are $N$ customers in a restaurant. Each customer is numbered $1$ through $N$.\n\nA sushi chef carried out $Q$ operations for customers.\n\nThe $i$-th operation is follows:\n\nThe sushi chef chooses a customer whose number of dishes of sushi eaten is minimum, in customer $1, 2, 3, \\dots, a_i$. If there are multiple customers who are minimum numbers of dishes, he selects the minimum-numbered customers.\n\nHe puts a dish of sushi on the selected seats.\n\nA customer who have selected for professional eats this sushi.\n\nRepeat 1-3, $b_i$ times.\n\nPlease calculate the number of dishes of sushi that have been eaten by each customer.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\n$N \\ Q$\n$a_1 \\ b_1$\n$a_2 \\ b_2$\n$ : \\ : $\n$a_Q \\ b_Q$\n\nOutput\n\nYou have to print $N$ lines.\n\nThe $i$-th line should contain the number of dishes of sushi had eaten for customer $i (1 \\le i \\le N)$.\n\nConstraints\n\n$3 \\le N, Q \\le 100,000$\n\n$1 \\le a_i \\le N$\n\n$1 \\le b_i \\le 10^{12}$\n\nAny final results do not exceed $2 \\times 10^{13}$.\n\nSubtasks\n\nSubtask 1 [ $60$ points ]\n\n$N, Q \\le 100$\n\n$b_i = 1$\n\nSubtask 2 [ $400$ points ]\n\n$N, Q \\le 100$\n\n$b_i \\le 10^{12}$\n\nSubtask 3 [ $240$ points ]\n\n$N, Q \\le 100,000$\n\n$b_i = 1$\n\nSubtask 4 [ $500$ points ]\n\nThere are no additional constraints.\n\nSample Input 1\n\n9 3\n5 11\n8 4\n4 7\n\nSample Output 1\n\n4\n4\n4\n4\n2\n2\n1\n1\n0\n\nThe change of the number of dishes of sushi have eaten is following:\n\nCustomer 1\n\nCustomer 2\n\nCustomer 3\n\nCustomer 4\n\nCustomer 5\n\nCustomer 6\n\nCustomer 7\n\nCustomer 8\n\nCustomer 9\n\n1st Operation\n\n3\n\n2\n\n2\n\n2\n\n2\n\n0\n\n0\n\n0\n\n0\n\n2nd Operation\n\n3\n\n2\n\n2\n\n2\n\n2\n\n2\n\n1\n\n1\n\n0\n\n3rd Operation\n\n4\n\n4\n\n4\n\n4\n\n2\n\n2\n\n1\n\n1\n\n0\n\nSample Input 2\n\n6 6\n3 5\n6 11\n1 6\n4 7\n5 2\n2 5\n\nSample Output 2\n\n10\n10\n5\n5\n4\n2\n\nSample Input 3\n\n5 6\n1 1\n2 1\n3 1\n1 1\n5 1\n3 1\n\nSample Output 3\n\n2\n2\n1\n1\n0\n\nSample Input 4\n\n10 10\n10 10\n9 20\n8 30\n7 40\n6 50\n5 60\n4 70\n3 80\n2 90\n1 100\n\nSample Output 4\n\n223\n123\n77\n50\n33\n21\n12\n7\n3\n1\n\nWriter: E869120", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 20563, "cpu_time_ms": 1066, "memory_kb": 67560}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s754610630", "group_id": "codeNet:p03937", "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* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0)))\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 ((no ()\n (write-line \"Impossible\")\n (return-from main)))\n (sb-int:named-let recur ((y 0) (x 0))\n (dbg y x)\n (cond ((and (= y (- h 1))\n (= x (- w 1)))\n (write-line \"Possible\"))\n ((and (< y (- h 1))\n (= 1 (aref plan (+ y 1) x)))\n (if (and (< x (- w 1))\n (= 1 (aref plan y (+ x 1))))\n (no)\n (recur (+ y 1) x)))\n ((and (< x (- w 1))\n (= 1 (aref plan y (+ x 1))))\n (if (and (< y (- h 1))\n (= 1 (aref plan (+ y 1) x)))\n (no)\n (recur y (+ x 1))))\n (t (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:/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 \"4 5\n##...\n.##..\n..##.\n...##\n\"\n \"Possible\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3\n###\n..#\n###\n#..\n###\n\"\n \"Impossible\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 5\n##...\n.###.\n.###.\n...##\n\"\n \"Impossible\n\")))\n\n", "language": "Lisp", "metadata": {"date": 1578130259, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03937.html", "problem_id": "p03937", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03937/input.txt", "sample_output_relpath": "derived/input_output/data/p03937/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03937/Lisp/s754610630.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s754610630", "user_id": "u352600849"}, "prompt_components": {"gold_output": "Possible\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* ((h (read))\n (w (read))\n (plan (make-array (list h w) :element-type 'bit :initial-element 0)))\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 ((no ()\n (write-line \"Impossible\")\n (return-from main)))\n (sb-int:named-let recur ((y 0) (x 0))\n (dbg y x)\n (cond ((and (= y (- h 1))\n (= x (- w 1)))\n (write-line \"Possible\"))\n ((and (< y (- h 1))\n (= 1 (aref plan (+ y 1) x)))\n (if (and (< x (- w 1))\n (= 1 (aref plan y (+ x 1))))\n (no)\n (recur (+ y 1) x)))\n ((and (< x (- w 1))\n (= 1 (aref plan y (+ x 1))))\n (if (and (< y (- h 1))\n (= 1 (aref plan (+ y 1) x)))\n (no)\n (recur y (+ x 1))))\n (t (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:/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 \"4 5\n##...\n.##..\n..##.\n...##\n\"\n \"Possible\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"5 3\n###\n..#\n###\n#..\n###\n\"\n \"Impossible\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 5\n##...\n.###.\n.###.\n...##\n\"\n \"Impossible\n\")))\n\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\n#nck {\nwidth: 30px;\nheight: auto;\n}\n\nWe have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).\n\nYou are given a matrix of characters a_{ij} (1 \\leq i \\leq H, 1 \\leq j \\leq W). After Shik completes all moving actions, a_{ij} is # if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is .. Please determine whether it is possible that Shik only uses right and down moves in all steps.\n\nConstraints\n\n2 \\leq H, W \\leq 8\n\na_{i,j} is either # or ..\n\nThere exists a valid sequence of moves for Shik to generate the map a.\n\nInput\n\nThe input 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\nIf it is possible that Shik only uses right and down moves, print Possible. Otherwise, print Impossible.\n\nSample Input 1\n\n4 5\n##...\n.##..\n..##.\n...##\n\nSample Output 1\n\nPossible\n\nThe matrix can be generated by a 7-move sequence: right, down, right, down, right, down, and right.\n\nSample Input 2\n\n5 3\n###\n..#\n###\n#..\n###\n\nSample Output 2\n\nImpossible\n\nSample Input 3\n\n4 5\n##...\n.###.\n.###.\n...##\n\nSample Output 3\n\nImpossible", "sample_input": "4 5\n##...\n.##..\n..##.\n...##\n"}, "reference_outputs": ["Possible\n"], "source_document_id": "p03937", "source_text": "Score : 200 points\n\nProblem Statement\n\n#nck {\nwidth: 30px;\nheight: auto;\n}\n\nWe have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).\n\nYou are given a matrix of characters a_{ij} (1 \\leq i \\leq H, 1 \\leq j \\leq W). After Shik completes all moving actions, a_{ij} is # if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is .. Please determine whether it is possible that Shik only uses right and down moves in all steps.\n\nConstraints\n\n2 \\leq H, W \\leq 8\n\na_{i,j} is either # or ..\n\nThere exists a valid sequence of moves for Shik to generate the map a.\n\nInput\n\nThe input 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\nIf it is possible that Shik only uses right and down moves, print Possible. Otherwise, print Impossible.\n\nSample Input 1\n\n4 5\n##...\n.##..\n..##.\n...##\n\nSample Output 1\n\nPossible\n\nThe matrix can be generated by a 7-move sequence: right, down, right, down, right, down, and right.\n\nSample Input 2\n\n5 3\n###\n..#\n###\n#..\n###\n\nSample Output 2\n\nImpossible\n\nSample Input 3\n\n4 5\n##...\n.###.\n.###.\n...##\n\nSample Output 3\n\nImpossible", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4874, "cpu_time_ms": 173, "memory_kb": 21352}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s497264213", "group_id": "codeNet:p03943", "input_text": "(let ((abc (vector (read) (read) (read))))\n (loop for i below 3\n for res = (= (svref abc i) (+ (svref abc (mod (1+ i) 3))\n (svref abc (mod (+ 2 i) 3))))\n if res\n do (return (format t \"~A~%\" \"Yes\"))\n finally (format t \"~A~%\" \"No\")))", "language": "Lisp", "metadata": {"date": 1505366395, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s497264213.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s497264213", "user_id": "u140665374"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(let ((abc (vector (read) (read) (read))))\n (loop for i below 3\n for res = (= (svref abc i) (+ (svref abc (mod (1+ i) 3))\n (svref abc (mod (+ 2 i) 3))))\n if res\n do (return (format t \"~A~%\" \"Yes\"))\n finally (format t \"~A~%\" \"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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 297, "cpu_time_ms": 128, "memory_kb": 14052}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s402234067", "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 (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 (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": 1581568557, "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/s402234067.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s402234067", "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 (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 (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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7407, "cpu_time_ms": 490, "memory_kb": 58856}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s051595774", "group_id": "codeNet:p03962", "input_text": "(princ(length(remove-duplicates(list(read)(read)(read)))))", "language": "Lisp", "metadata": {"date": 1528185758, "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/s051595774.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s051595774", "user_id": "u657913472"}, "prompt_components": {"gold_output": "3\n", "input_to_evaluate": "(princ(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 23, "memory_kb": 3812}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s043051224", "group_id": "codeNet:p03963", "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 (n k)\n (* k (expt (1- k) (1- n))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (k (read)))\n (princ (solve n k))\n (fresh-line)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1600643789, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03963.html", "problem_id": "p03963", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03963/input.txt", "sample_output_relpath": "derived/input_output/data/p03963/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03963/Lisp/s043051224.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s043051224", "user_id": "u425762225"}, "prompt_components": {"gold_output": "2\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 (n k)\n (* k (expt (1- k) (1- n))))\n\n\n(defun main ()\n (declare #.OPT)\n (let ((n (read))\n (k (read)))\n (princ (solve n k))\n (fresh-line)))\n\n#-swank (main)\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N balls placed in a row.\nAtCoDeer the deer is painting each of these in one of the K colors of his paint cans.\nFor aesthetic reasons, any two adjacent balls must be painted in different colors.\n\nFind the number of the possible ways to paint the balls.\n\nConstraints\n\n1≦N≦1000\n\n2≦K≦1000\n\nThe correct answer is at most 2^{31}-1.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of the possible ways to paint the balls.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n2\n\nWe will denote the colors by 0 and 1. There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1, or paint the left in color 1 and the right in color 0.\n\nSample Input 2\n\n1 10\n\nSample Output 2\n\n10\n\nSince there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten.", "sample_input": "2 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03963", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N balls placed in a row.\nAtCoDeer the deer is painting each of these in one of the K colors of his paint cans.\nFor aesthetic reasons, any two adjacent balls must be painted in different colors.\n\nFind the number of the possible ways to paint the balls.\n\nConstraints\n\n1≦N≦1000\n\n2≦K≦1000\n\nThe correct answer is at most 2^{31}-1.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of the possible ways to paint the balls.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n2\n\nWe will denote the colors by 0 and 1. There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1, or paint the left in color 1 and the right in color 0.\n\nSample Input 2\n\n1 10\n\nSample Output 2\n\n10\n\nSince there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 7788, "cpu_time_ms": 39, "memory_kb": 26356}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s607225723", "group_id": "codeNet:p03963", "input_text": "(let ((n (read))\n (k (read)))\n\n (format t \"~A~%\"\n (* k (expt (1- k) (1- n)))))\n", "language": "Lisp", "metadata": {"date": 1594437227, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "problem_description_relpath": "problem_descriptions/p03963.html", "problem_id": "p03963", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03963/input.txt", "sample_output_relpath": "derived/input_output/data/p03963/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03963/Lisp/s607225723.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s607225723", "user_id": "u336541610"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "(let ((n (read))\n (k (read)))\n\n (format t \"~A~%\"\n (* k (expt (1- k) (1- n)))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N balls placed in a row.\nAtCoDeer the deer is painting each of these in one of the K colors of his paint cans.\nFor aesthetic reasons, any two adjacent balls must be painted in different colors.\n\nFind the number of the possible ways to paint the balls.\n\nConstraints\n\n1≦N≦1000\n\n2≦K≦1000\n\nThe correct answer is at most 2^{31}-1.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of the possible ways to paint the balls.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n2\n\nWe will denote the colors by 0 and 1. There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1, or paint the left in color 1 and the right in color 0.\n\nSample Input 2\n\n1 10\n\nSample Output 2\n\n10\n\nSince there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten.", "sample_input": "2 2\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03963", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N balls placed in a row.\nAtCoDeer the deer is painting each of these in one of the K colors of his paint cans.\nFor aesthetic reasons, any two adjacent balls must be painted in different colors.\n\nFind the number of the possible ways to paint the balls.\n\nConstraints\n\n1≦N≦1000\n\n2≦K≦1000\n\nThe correct answer is at most 2^{31}-1.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K\n\nOutput\n\nPrint the number of the possible ways to paint the balls.\n\nSample Input 1\n\n2 2\n\nSample Output 1\n\n2\n\nWe will denote the colors by 0 and 1. There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1, or paint the left in color 1 and the right in color 0.\n\nSample Input 2\n\n1 10\n\nSample Output 2\n\n10\n\nSince there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 24, "memory_kb": 24024}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s309949387", "group_id": "codeNet:p03971", "input_text": "(let ((n (read))\n (a (read))\n (b (read))\n (s (read-line))\n (ninzuu 0)\n (bi 0))\n (loop for i below n do\n (progn\n (case (char-code (char s i))\n (97 (if (< ninzuu (+ a b))\n (progn\n (format t \"Yes~%\")\n (incf ninzuu)\n )\n (format t \"No~%\")))\n (98 (if (and (< ninzuu (+ a b)) (<= bi b))\n (progn\n (format t \"Yes~%\")\n (incf ninzuu)\n (incf bi)\n )\n (format t \"No~%\")))\n (99 (format t \"No~%\"))\n )\n )\n )\n)", "language": "Lisp", "metadata": {"date": 1596203978, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s309949387.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s309949387", "user_id": "u136500538"}, "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 (s (read-line))\n (ninzuu 0)\n (bi 0))\n (loop for i below n do\n (progn\n (case (char-code (char s i))\n (97 (if (< ninzuu (+ a b))\n (progn\n (format t \"Yes~%\")\n (incf ninzuu)\n )\n (format t \"No~%\")))\n (98 (if (and (< ninzuu (+ a b)) (<= bi b))\n (progn\n (format t \"Yes~%\")\n (incf ninzuu)\n (incf bi)\n )\n (format t \"No~%\")))\n (99 (format t \"No~%\"))\n )\n )\n )\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 723, "cpu_time_ms": 172, "memory_kb": 24892}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s214987504", "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 w :element-type 'uint32))\n (qs (make-array h :element-type 'uint32)))\n (dotimes (i w)\n (setf (aref ps i) (read-fixnum)))\n (dotimes (j h)\n (setf (aref qs j) (read-fixnum)))\n (setf ps (sort ps #'<)\n qs (sort qs #'<))\n (let ((x (+ w 1))\n (y (+ h 1))\n (i 0)\n (j 0)\n (res 0))\n (declare (uint64 y x i j res))\n (loop\n (cond ((and (= i w) (= j h))\n (println res)\n (return-from main))\n ((= i w)\n (incf res (* (aref qs j) x))\n (decf y)\n (incf j))\n ((= j w)\n (incf res (* (aref ps i) y))\n (decf x)\n (incf i))\n (t\n (if (< (aref qs j) (aref ps i))\n (progn (incf res (* (aref qs j) x))\n (decf y)\n (incf j))\n (progn (incf res (* (aref ps i) y))\n (decf x)\n (incf i)))))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1567108100, "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/s214987504.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s214987504", "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 w :element-type 'uint32))\n (qs (make-array h :element-type 'uint32)))\n (dotimes (i w)\n (setf (aref ps i) (read-fixnum)))\n (dotimes (j h)\n (setf (aref qs j) (read-fixnum)))\n (setf ps (sort ps #'<)\n qs (sort qs #'<))\n (let ((x (+ w 1))\n (y (+ h 1))\n (i 0)\n (j 0)\n (res 0))\n (declare (uint64 y x i j res))\n (loop\n (cond ((and (= i w) (= j h))\n (println res)\n (return-from main))\n ((= i w)\n (incf res (* (aref qs j) x))\n (decf y)\n (incf j))\n ((= j w)\n (incf res (* (aref ps i) y))\n (decf x)\n (incf i))\n (t\n (if (< (aref qs j) (aref ps i))\n (progn (incf res (* (aref qs j) x))\n (decf y)\n (incf j))\n (progn (incf res (* (aref ps i) y))\n (decf x)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 427, "memory_kb": 47080}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s913091581", "group_id": "codeNet:p03986", "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-line)))\n (println\n (sb-int:named-let recur ((pos 0) (unclosed-s 0) (res (length x)))\n (declare (uint31 pos unclosed-s res))\n (cond ((= pos (length x))\n res)\n ((char= #\\S (aref x pos))\n (recur (+ pos 1) (+ unclosed-s 1) res))\n ((zerop unclosed-s)\n (recur (+ pos 1) unclosed-s res))\n (t\n (recur (+ pos 1) (- unclosed-s 1) (- 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:/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 \"TSTTSS\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"SSTTST\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"TSSTTTSS\n\"\n \"4\n\")))\n", "language": "Lisp", "metadata": {"date": 1578128873, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03986.html", "problem_id": "p03986", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03986/input.txt", "sample_output_relpath": "derived/input_output/data/p03986/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03986/Lisp/s913091581.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s913091581", "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(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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-line)))\n (println\n (sb-int:named-let recur ((pos 0) (unclosed-s 0) (res (length x)))\n (declare (uint31 pos unclosed-s res))\n (cond ((= pos (length x))\n res)\n ((char= #\\S (aref x pos))\n (recur (+ pos 1) (+ unclosed-s 1) res))\n ((zerop unclosed-s)\n (recur (+ pos 1) unclosed-s res))\n (t\n (recur (+ pos 1) (- unclosed-s 1) (- 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:/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 \"TSTTSS\n\"\n \"4\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"SSTTST\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"TSSTTTSS\n\"\n \"4\n\")))\n", "problem_context": "Score : 300 points\n\nProblem Statement\n\nWe have a string X, which has an even number of characters. Half the characters are S, and the other half are T.\n\nTakahashi, who hates the string ST, will perform the following operation 10^{10000} times:\n\nAmong the occurrences of ST in X as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing.\n\nFind the eventual length of X.\n\nConstraints\n\n2 ≦ |X| ≦ 200,000\n\nThe length of X is even.\n\nHalf the characters in X are S, and the other half are T.\n\nPartial Scores\n\nIn test cases worth 200 points, |X| ≦ 200.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the eventual length of X.\n\nSample Input 1\n\nTSTTSS\n\nSample Output 1\n\n4\n\nIn the 1-st operation, the 2-nd and 3-rd characters of TSTTSS are removed.\nX becomes TTSS, and since it does not contain ST anymore, nothing is done in the remaining 10^{10000}-1 operations.\nThus, the answer is 4.\n\nSample Input 2\n\nSSTTST\n\nSample Output 2\n\n0\n\nX will eventually become an empty string: SSTTST ⇒ STST ⇒ ST ⇒ ``.\n\nSample Input 3\n\nTSSTTTSS\n\nSample Output 3\n\n4\n\nX will become: TSSTTTSS ⇒ TSTTSS ⇒ TTSS.", "sample_input": "TSTTSS\n"}, "reference_outputs": ["4\n"], "source_document_id": "p03986", "source_text": "Score : 300 points\n\nProblem Statement\n\nWe have a string X, which has an even number of characters. Half the characters are S, and the other half are T.\n\nTakahashi, who hates the string ST, will perform the following operation 10^{10000} times:\n\nAmong the occurrences of ST in X as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing.\n\nFind the eventual length of X.\n\nConstraints\n\n2 ≦ |X| ≦ 200,000\n\nThe length of X is even.\n\nHalf the characters in X are S, and the other half are T.\n\nPartial Scores\n\nIn test cases worth 200 points, |X| ≦ 200.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nX\n\nOutput\n\nPrint the eventual length of X.\n\nSample Input 1\n\nTSTTSS\n\nSample Output 1\n\n4\n\nIn the 1-st operation, the 2-nd and 3-rd characters of TSTTSS are removed.\nX becomes TTSS, and since it does not contain ST anymore, nothing is done in the remaining 10^{10000}-1 operations.\nThus, the answer is 4.\n\nSample Input 2\n\nSSTTST\n\nSample Output 2\n\n0\n\nX will eventually become an empty string: SSTTST ⇒ STST ⇒ ST ⇒ ``.\n\nSample Input 3\n\nTSSTTTSS\n\nSample Output 3\n\n4\n\nX will become: TSSTTTSS ⇒ TSTTSS ⇒ TTSS.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4207, "cpu_time_ms": 83, "memory_kb": 13028}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s366624090", "group_id": "codeNet:p03993", "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 make-cons (a b)\n (if (> a b) (cons b a)\n (cons a b)))\n\n(defun main (lst)\n (- (length lst)\n (length\n (remove-duplicates\n (loop for i from 1\n for j in lst\n collect (make-cons i j))\n :test #'equal))))\n\n(princ (main (read-times (read))))\n", "language": "Lisp", "metadata": {"date": 1589147524, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p03993.html", "problem_id": "p03993", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p03993/input.txt", "sample_output_relpath": "derived/input_output/data/p03993/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p03993/Lisp/s366624090.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s366624090", "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 make-cons (a b)\n (if (> a b) (cons b a)\n (cons a b)))\n\n(defun main (lst)\n (- (length lst)\n (length\n (remove-duplicates\n (loop for i from 1\n for j in lst\n collect (make-cons i j))\n :test #'equal))))\n\n(princ (main (read-times (read))))\n", "problem_context": "Score : 200 points\n\nProblem Statement\n\nThere are N rabbits, numbered 1 through N.\n\nThe i-th (1≤i≤N) rabbit likes rabbit a_i.\nNote that no rabbit can like itself, that is, a_i≠i.\n\nFor a pair of rabbits i and j (i<j), we call the pair (i,j) a friendly pair if the following condition is met.\n\nRabbit i likes rabbit j and rabbit j likes rabbit i.\n\nCalculate the number of the friendly pairs.\n\nConstraints\n\n2≤N≤10^5\n\n1≤a_i≤N\n\na_i≠i\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 friendly pairs.\n\nSample Input 1\n\n4\n2 1 4 3\n\nSample Output 1\n\n2\n\nThere are two friendly pairs: (1,2) and (3,4).\n\nSample Input 2\n\n3\n2 3 1\n\nSample Output 2\n\n0\n\nThere are no friendly pairs.\n\nSample Input 3\n\n5\n5 5 5 5 1\n\nSample Output 3\n\n1\n\nThere is one friendly pair: (1,5).", "sample_input": "4\n2 1 4 3\n"}, "reference_outputs": ["2\n"], "source_document_id": "p03993", "source_text": "Score : 200 points\n\nProblem Statement\n\nThere are N rabbits, numbered 1 through N.\n\nThe i-th (1≤i≤N) rabbit likes rabbit a_i.\nNote that no rabbit can like itself, that is, a_i≠i.\n\nFor a pair of rabbits i and j (i<j), we call the pair (i,j) a friendly pair if the following condition is met.\n\nRabbit i likes rabbit j and rabbit j likes rabbit i.\n\nCalculate the number of the friendly pairs.\n\nConstraints\n\n2≤N≤10^5\n\n1≤a_i≤N\n\na_i≠i\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 friendly pairs.\n\nSample Input 1\n\n4\n2 1 4 3\n\nSample Output 1\n\n2\n\nThere are two friendly pairs: (1,2) and (3,4).\n\nSample Input 2\n\n3\n2 3 1\n\nSample Output 2\n\n0\n\nThere are no friendly pairs.\n\nSample Input 3\n\n5\n5 5 5 5 1\n\nSample Output 3\n\n1\n\nThere is one friendly pair: (1,5).", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 251, "memory_kb": 62524}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s113448293", "group_id": "codeNet:p03997", "input_text": "(defun main ()\n (let ((a (read))\n (b (read))\n (h (read)))\n (format t \"~D~%\" (/ (* (+ a b) h) 2))))\n\n(main)", "language": "Lisp", "metadata": {"date": 1576912439, "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/s113448293.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s113448293", "user_id": "u115747274"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(defun main ()\n (let ((a (read))\n (b (read))\n (h (read)))\n (format t \"~D~%\" (/ (* (+ a b) h) 2))))\n\n(main)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 11, "memory_kb": 3428}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s897270626", "group_id": "codeNet:p03997", "input_text": "(let ((a (read))\n (b (read))\n (h (read)))\n\n (format t \"~A~%\"\n (/ (* (+ a b) h) 2)))\n", "language": "Lisp", "metadata": {"date": 1572221360, "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/s897270626.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s897270626", "user_id": "u336541610"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (h (read)))\n\n (format t \"~A~%\"\n (/ (* (+ a b) h) 2)))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 28, "memory_kb": 4192}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s658613983", "group_id": "codeNet:p03997", "input_text": "(let ((a (read))\n (b (read))\n (h (read)))\n (princ (/ (* (+ a b) h) 2)))", "language": "Lisp", "metadata": {"date": 1555384183, "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/s658613983.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s658613983", "user_id": "u610490393"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(let ((a (read))\n (b (read))\n (h (read)))\n (princ (/ (* (+ a b) h) 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 89, "memory_kb": 8672}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s888485304", "group_id": "codeNet:p03997", "input_text": "(princ(/(*(+(read)(read))(read))2))", "language": "Lisp", "metadata": {"date": 1550553909, "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/s888485304.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s888485304", "user_id": "u994767958"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(princ(/(*(+(read)(read))(read))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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 35, "cpu_time_ms": 5, "memory_kb": 2792}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s365870825", "group_id": "codeNet:p03997", "input_text": "(format t\"~A~%\"(/(*(+(read)(read))(read))2))", "language": "Lisp", "metadata": {"date": 1528180791, "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/s365870825.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s365870825", "user_id": "u657913472"}, "prompt_components": {"gold_output": "7\n", "input_to_evaluate": "(format t\"~A~%\"(/(*(+(read)(read))(read))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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 21, "memory_kb": 3808}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s410229604", "group_id": "codeNet:p03999", "input_text": "(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 ;; (print pos-list)\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 ;; (format t \"~%~A: ~A~%~%\" x tmp)\n (setq result (+ result (reduce #'+ tmp)))\n )))\n (princ result)))", "language": "Lisp", "metadata": {"date": 1590895395, "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/s410229604.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s410229604", "user_id": "u631655863"}, "prompt_components": {"gold_output": "176\n", "input_to_evaluate": "(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 ;; (print pos-list)\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 ;; (format t \"~%~A: ~A~%~%\" x tmp)\n (setq result (+ result (reduce #'+ tmp)))\n )))\n (princ 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 1773, "cpu_time_ms": 160, "memory_kb": 19044}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s948466210", "group_id": "codeNet:p04000", "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(defmacro dx (form)\n (let ((tmp (gensym)))\n `(let ((,tmp ,form))\n (declare (dynamic-extent ,tmp))\n ,tmp)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (n (read))\n (table (make-hash-table :test #'equal :size n))\n (res (make-array 10 :element-type 'uint32 :initial-element 0)))\n (declare (uint31 h w n))\n (dotimes (i n)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (declare (uint32 a b))\n (setf (gethash (cons a b) table) t)))\n (labels ((frob (y x)\n (declare (int32 y x))\n (if (or (< y 0) (< x 0))\n 0\n (let ((res 0)\n (pair (cons 0 0)))\n (declare (uint32 res)\n ((cons fixnum fixnum) pair)\n (sb-impl::truly-dynamic-extent pair))\n (setf (car pair) y (cdr pair) x)\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 1) (cdr pair) x)\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 2) (cdr pair) x)\n (when (gethash pair table) (incf res))\n (setf (car pair) y (cdr pair) (+ x 1))\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 1) (cdr pair) (+ x 1))\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 2) (cdr pair) (+ x 1))\n (when (gethash pair table) (incf res))\n (setf (car pair) y (cdr pair) (+ x 2))\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 1) (cdr pair) (+ x 2))\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 2) (cdr pair) (+ x 2))\n (when (gethash pair table) (incf res))\n res))))\n (loop for (y . x) of-type (uint32 . uint32) being each hash-key of table\n do (when (< (+ y 2) h)\n (when (< (+ x 2) w)\n (incf (aref res (frob y x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob y (- x 1)))))\n (incf (aref res (frob y (- x 2)))))\n (when (< (+ y 1) h)\n (when (< (+ x 2) w)\n (incf (aref res (frob (- y 1) x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob (- y 1) (- x 1)))))\n (incf (aref res (frob (- y 1) (- x 2)))))\n (when (< (+ x 2) w)\n (incf (aref res (frob (- y 2) x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob (- y 2) (- x 1)))))\n (incf (aref res (frob (- y 2) (- x 2)))))\n (loop for i from 1 to 9\n do (setf (aref res i) (/ (aref res i) i)))\n (println (- (* (- h 2) (- w 2))\n (reduce #'+ res :start 1)))\n (loop for i from 1 to 9\n do (println (aref res i))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563414589, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04000.html", "problem_id": "p04000", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04000/input.txt", "sample_output_relpath": "derived/input_output/data/p04000/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04000/Lisp/s948466210.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s948466210", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\n0\n0\n2\n4\n0\n0\n0\n0\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(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(defmacro dx (form)\n (let ((tmp (gensym)))\n `(let ((,tmp ,form))\n (declare (dynamic-extent ,tmp))\n ,tmp)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (n (read))\n (table (make-hash-table :test #'equal :size n))\n (res (make-array 10 :element-type 'uint32 :initial-element 0)))\n (declare (uint31 h w n))\n (dotimes (i n)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (declare (uint32 a b))\n (setf (gethash (cons a b) table) t)))\n (labels ((frob (y x)\n (declare (int32 y x))\n (if (or (< y 0) (< x 0))\n 0\n (let ((res 0)\n (pair (cons 0 0)))\n (declare (uint32 res)\n ((cons fixnum fixnum) pair)\n (sb-impl::truly-dynamic-extent pair))\n (setf (car pair) y (cdr pair) x)\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 1) (cdr pair) x)\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 2) (cdr pair) x)\n (when (gethash pair table) (incf res))\n (setf (car pair) y (cdr pair) (+ x 1))\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 1) (cdr pair) (+ x 1))\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 2) (cdr pair) (+ x 1))\n (when (gethash pair table) (incf res))\n (setf (car pair) y (cdr pair) (+ x 2))\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 1) (cdr pair) (+ x 2))\n (when (gethash pair table) (incf res))\n (setf (car pair) (+ y 2) (cdr pair) (+ x 2))\n (when (gethash pair table) (incf res))\n res))))\n (loop for (y . x) of-type (uint32 . uint32) being each hash-key of table\n do (when (< (+ y 2) h)\n (when (< (+ x 2) w)\n (incf (aref res (frob y x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob y (- x 1)))))\n (incf (aref res (frob y (- x 2)))))\n (when (< (+ y 1) h)\n (when (< (+ x 2) w)\n (incf (aref res (frob (- y 1) x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob (- y 1) (- x 1)))))\n (incf (aref res (frob (- y 1) (- x 2)))))\n (when (< (+ x 2) w)\n (incf (aref res (frob (- y 2) x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob (- y 2) (- x 1)))))\n (incf (aref res (frob (- y 2) (- x 2)))))\n (loop for i from 1 to 9\n do (setf (aref res i) (/ (aref res i) i)))\n (println (- (* (- h 2) (- w 2))\n (reduce #'+ res :start 1)))\n (loop for i from 1 to 9\n do (println (aref res i))))))\n\n#-swank (main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a grid with H rows and W columns. At first, all cells were painted white.\n\nSnuke painted N of these cells. The i-th ( 1 \\leq i \\leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.\n\nCompute the following:\n\nFor each integer j ( 0 \\leq j \\leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?\n\nConstraints\n\n3 \\leq H \\leq 10^9\n\n3 \\leq W \\leq 10^9\n\n0 \\leq N \\leq min(10^5,H×W)\n\n1 \\leq a_i \\leq H (1 \\leq i \\leq N)\n\n1 \\leq b_i \\leq W (1 \\leq i \\leq N)\n\n(a_i, b_i) \\neq (a_j, b_j) (i \\neq j)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nH W N\na_1 b_1\n:\na_N b_N\n\nOutput\n\nPrint 10 lines.\nThe (j+1)-th ( 0 \\leq j \\leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.\n\nSample Input 1\n\n4 5 8\n1 1\n1 4\n1 5\n2 3\n3 1\n3 2\n3 4\n4 4\n\nSample Output 1\n\n0\n0\n0\n2\n4\n0\n0\n0\n0\n0\n\nThere are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.\n\nSample Input 2\n\n10 10 20\n1 1\n1 4\n1 9\n2 5\n3 10\n4 2\n4 7\n5 9\n6 4\n6 6\n6 7\n7 1\n7 3\n7 7\n8 1\n8 5\n8 10\n9 2\n10 4\n10 9\n\nSample Output 2\n\n4\n26\n22\n10\n2\n0\n0\n0\n0\n0\n\nSample Input 3\n\n1000000000 1000000000 0\n\nSample Output 3\n\n999999996000000004\n0\n0\n0\n0\n0\n0\n0\n0\n0", "sample_input": "4 5 8\n1 1\n1 4\n1 5\n2 3\n3 1\n3 2\n3 4\n4 4\n"}, "reference_outputs": ["0\n0\n0\n2\n4\n0\n0\n0\n0\n0\n"], "source_document_id": "p04000", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a grid with H rows and W columns. At first, all cells were painted white.\n\nSnuke painted N of these cells. The i-th ( 1 \\leq i \\leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.\n\nCompute the following:\n\nFor each integer j ( 0 \\leq j \\leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?\n\nConstraints\n\n3 \\leq H \\leq 10^9\n\n3 \\leq W \\leq 10^9\n\n0 \\leq N \\leq min(10^5,H×W)\n\n1 \\leq a_i \\leq H (1 \\leq i \\leq N)\n\n1 \\leq b_i \\leq W (1 \\leq i \\leq N)\n\n(a_i, b_i) \\neq (a_j, b_j) (i \\neq j)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nH W N\na_1 b_1\n:\na_N b_N\n\nOutput\n\nPrint 10 lines.\nThe (j+1)-th ( 0 \\leq j \\leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.\n\nSample Input 1\n\n4 5 8\n1 1\n1 4\n1 5\n2 3\n3 1\n3 2\n3 4\n4 4\n\nSample Output 1\n\n0\n0\n0\n2\n4\n0\n0\n0\n0\n0\n\nThere are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.\n\nSample Input 2\n\n10 10 20\n1 1\n1 4\n1 9\n2 5\n3 10\n4 2\n4 7\n5 9\n6 4\n6 6\n6 7\n7 1\n7 3\n7 7\n8 1\n8 5\n8 10\n9 2\n10 4\n10 9\n\nSample Output 2\n\n4\n26\n22\n10\n2\n0\n0\n0\n0\n0\n\nSample Input 3\n\n1000000000 1000000000 0\n\nSample Output 3\n\n999999996000000004\n0\n0\n0\n0\n0\n0\n0\n0\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5531, "cpu_time_ms": 789, "memory_kb": 30436}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s292071109", "group_id": "codeNet:p04000", "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(defmacro dx (form)\n (let ((tmp (gensym)))\n `(let ((,tmp ,form))\n (declare (dynamic-extent ,tmp))\n ,tmp)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (n (read))\n (table (make-hash-table :test #'equal :size n))\n (res (make-array 10 :element-type 'uint32 :initial-element 0)))\n (declare (uint31 h w n))\n (dotimes (i n)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (declare (uint32 a b))\n (setf (gethash (cons a b) table) t)))\n (labels ((frob (y x)\n (declare (int32 y x))\n (if (or (< y 0) (< x 0))\n 0\n (let ((res 0))\n (declare (uint32 res))\n (when (gethash (dx (cons y x)) table)\n (incf res))\n (when (gethash (dx (cons (+ y 1) x)) table)\n (incf res))\n (when (gethash (dx (cons (+ y 2) x)) table)\n (incf res))\n (when (gethash (dx (cons y (+ x 1))) table)\n (incf res))\n (when (gethash (dx (cons (+ y 1) (+ x 1))) table)\n (incf res))\n (when (gethash (dx (cons (+ y 2) (+ x 1))) table)\n (incf res))\n (when (gethash (dx (cons y (+ x 2))) table)\n (incf res))\n (when (gethash (dx (cons (+ y 1) (+ x 2))) table)\n (incf res))\n (when (gethash (dx (cons (+ y 2) (+ x 2))) table)\n (incf res))\n res))))\n (loop for (y . x) of-type (uint32 . uint32) being each hash-key of table\n do (when (< (+ y 2) h)\n (when (< (+ x 2) w)\n (incf (aref res (frob y x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob y (- x 1)))))\n (incf (aref res (frob y (- x 2)))))\n (when (< (+ y 1) h)\n (when (< (+ x 2) w)\n (incf (aref res (frob (- y 1) x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob (- y 1) (- x 1)))))\n (incf (aref res (frob (- y 1) (- x 2)))))\n (when (< (+ x 2) w)\n (incf (aref res (frob (- y 2) x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob (- y 2) (- x 1)))))\n (incf (aref res (frob (- y 2) (- x 2)))))\n (loop for i from 1 to 9\n do (setf (aref res i) (/ (aref res i) i)))\n (println (- (* (- h 2) (- w 2))\n (reduce #'+ res :start 1)))\n (loop for i from 1 to 9\n do (println (aref res i))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1563413995, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04000.html", "problem_id": "p04000", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04000/input.txt", "sample_output_relpath": "derived/input_output/data/p04000/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04000/Lisp/s292071109.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s292071109", "user_id": "u352600849"}, "prompt_components": {"gold_output": "0\n0\n0\n2\n4\n0\n0\n0\n0\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(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(defmacro dx (form)\n (let ((tmp (gensym)))\n `(let ((,tmp ,form))\n (declare (dynamic-extent ,tmp))\n ,tmp)))\n\n(defun main ()\n (declare #.OPT)\n (let* ((h (read))\n (w (read))\n (n (read))\n (table (make-hash-table :test #'equal :size n))\n (res (make-array 10 :element-type 'uint32 :initial-element 0)))\n (declare (uint31 h w n))\n (dotimes (i n)\n (let ((a (- (read-fixnum) 1))\n (b (- (read-fixnum) 1)))\n (declare (uint32 a b))\n (setf (gethash (cons a b) table) t)))\n (labels ((frob (y x)\n (declare (int32 y x))\n (if (or (< y 0) (< x 0))\n 0\n (let ((res 0))\n (declare (uint32 res))\n (when (gethash (dx (cons y x)) table)\n (incf res))\n (when (gethash (dx (cons (+ y 1) x)) table)\n (incf res))\n (when (gethash (dx (cons (+ y 2) x)) table)\n (incf res))\n (when (gethash (dx (cons y (+ x 1))) table)\n (incf res))\n (when (gethash (dx (cons (+ y 1) (+ x 1))) table)\n (incf res))\n (when (gethash (dx (cons (+ y 2) (+ x 1))) table)\n (incf res))\n (when (gethash (dx (cons y (+ x 2))) table)\n (incf res))\n (when (gethash (dx (cons (+ y 1) (+ x 2))) table)\n (incf res))\n (when (gethash (dx (cons (+ y 2) (+ x 2))) table)\n (incf res))\n res))))\n (loop for (y . x) of-type (uint32 . uint32) being each hash-key of table\n do (when (< (+ y 2) h)\n (when (< (+ x 2) w)\n (incf (aref res (frob y x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob y (- x 1)))))\n (incf (aref res (frob y (- x 2)))))\n (when (< (+ y 1) h)\n (when (< (+ x 2) w)\n (incf (aref res (frob (- y 1) x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob (- y 1) (- x 1)))))\n (incf (aref res (frob (- y 1) (- x 2)))))\n (when (< (+ x 2) w)\n (incf (aref res (frob (- y 2) x))))\n (when (< (+ x 1) w)\n (incf (aref res (frob (- y 2) (- x 1)))))\n (incf (aref res (frob (- y 2) (- x 2)))))\n (loop for i from 1 to 9\n do (setf (aref res i) (/ (aref res i) i)))\n (println (- (* (- h 2) (- w 2))\n (reduce #'+ res :start 1)))\n (loop for i from 1 to 9\n do (println (aref res i))))))\n\n#-swank (main)\n", "problem_context": "Score : 400 points\n\nProblem Statement\n\nWe have a grid with H rows and W columns. At first, all cells were painted white.\n\nSnuke painted N of these cells. The i-th ( 1 \\leq i \\leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.\n\nCompute the following:\n\nFor each integer j ( 0 \\leq j \\leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?\n\nConstraints\n\n3 \\leq H \\leq 10^9\n\n3 \\leq W \\leq 10^9\n\n0 \\leq N \\leq min(10^5,H×W)\n\n1 \\leq a_i \\leq H (1 \\leq i \\leq N)\n\n1 \\leq b_i \\leq W (1 \\leq i \\leq N)\n\n(a_i, b_i) \\neq (a_j, b_j) (i \\neq j)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nH W N\na_1 b_1\n:\na_N b_N\n\nOutput\n\nPrint 10 lines.\nThe (j+1)-th ( 0 \\leq j \\leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.\n\nSample Input 1\n\n4 5 8\n1 1\n1 4\n1 5\n2 3\n3 1\n3 2\n3 4\n4 4\n\nSample Output 1\n\n0\n0\n0\n2\n4\n0\n0\n0\n0\n0\n\nThere are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.\n\nSample Input 2\n\n10 10 20\n1 1\n1 4\n1 9\n2 5\n3 10\n4 2\n4 7\n5 9\n6 4\n6 6\n6 7\n7 1\n7 3\n7 7\n8 1\n8 5\n8 10\n9 2\n10 4\n10 9\n\nSample Output 2\n\n4\n26\n22\n10\n2\n0\n0\n0\n0\n0\n\nSample Input 3\n\n1000000000 1000000000 0\n\nSample Output 3\n\n999999996000000004\n0\n0\n0\n0\n0\n0\n0\n0\n0", "sample_input": "4 5 8\n1 1\n1 4\n1 5\n2 3\n3 1\n3 2\n3 4\n4 4\n"}, "reference_outputs": ["0\n0\n0\n2\n4\n0\n0\n0\n0\n0\n"], "source_document_id": "p04000", "source_text": "Score : 400 points\n\nProblem Statement\n\nWe have a grid with H rows and W columns. At first, all cells were painted white.\n\nSnuke painted N of these cells. The i-th ( 1 \\leq i \\leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.\n\nCompute the following:\n\nFor each integer j ( 0 \\leq j \\leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?\n\nConstraints\n\n3 \\leq H \\leq 10^9\n\n3 \\leq W \\leq 10^9\n\n0 \\leq N \\leq min(10^5,H×W)\n\n1 \\leq a_i \\leq H (1 \\leq i \\leq N)\n\n1 \\leq b_i \\leq W (1 \\leq i \\leq N)\n\n(a_i, b_i) \\neq (a_j, b_j) (i \\neq j)\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nH W N\na_1 b_1\n:\na_N b_N\n\nOutput\n\nPrint 10 lines.\nThe (j+1)-th ( 0 \\leq j \\leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.\n\nSample Input 1\n\n4 5 8\n1 1\n1 4\n1 5\n2 3\n3 1\n3 2\n3 4\n4 4\n\nSample Output 1\n\n0\n0\n0\n2\n4\n0\n0\n0\n0\n0\n\nThere are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.\n\nSample Input 2\n\n10 10 20\n1 1\n1 4\n1 9\n2 5\n3 10\n4 2\n4 7\n5 9\n6 4\n6 6\n6 7\n7 1\n7 3\n7 7\n8 1\n8 5\n8 10\n9 2\n10 4\n10 9\n\nSample Output 2\n\n4\n26\n22\n10\n2\n0\n0\n0\n0\n0\n\nSample Input 3\n\n1000000000 1000000000 0\n\nSample Output 3\n\n999999996000000004\n0\n0\n0\n0\n0\n0\n0\n0\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 5183, "cpu_time_ms": 773, "memory_kb": 30436}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s255360613", "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;; DEFINE-INTEGER-PACK and DEFINE-CONS-PACK are so to say poor man's variants of\n;; DEFSTRUCT. Both \"structures\" can only have slots of fixed unsigned\n;; bytes. DEFINE-INTEGER-PACK handles the concatenated slots as UNSIGNED-BYTE\n;; and DEFINE-CONS-PACK handles them as (CONS (UNSIGNED-BYTE 62) (UNSIGNED-BYTE\n;; 62)).\n\n;; Example:\n;; The following form defines the type NODE as (UNSIGNED-BYTE 9):\n;; (define-integer-pack node (slot1 3) (slot2 5) (slot3 1))\n;; This macro in addition defines relevant utilities: NODE-SLOT1, NODE-SLOT2,\n;; NODE-SLOT3, setters and getters, PACK-NODE, the constructor, and\n;; WITH-UNPACKING-NODE, the destructuring-bind-style macro.\n;; \n;; DEFINE-CONS-PACK is almost the same as DEFINE-INTEGER-PACK though it will be\n;; suitable for the total bits in the range [63, 124].\n\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-integer-pack (name &rest slot-descriptions)\n (assert slot-descriptions () \"~A has no slots.\" name)\n (let* ((packer-name (intern (%concat-name \"PACK\" name)))\n (unpacker-macro-name (intern (%concat-name \"WITH-UNPACKING\" name)))\n (total-size 0)\n (slots (loop with position = 0\n for (slot-name slot-size) in slot-descriptions\n collect (progn (check-type slot-name symbol)\n (check-type slot-size (integer 1))\n (list slot-name slot-size position))\n do (incf position slot-size)\n finally (setq total-size position)))\n (revslots (reverse slots))\n (new-value (gensym \"NEW-VALUE\"))\n (tmp (gensym)))\n `(progn\n (deftype ,name () '(unsigned-byte ,total-size))\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-name slot-size slot-position) in slots\n for accessor-name = (intern (%concat-name name slot-name))\n append `((declaim (inline ,accessor-name\n (setf ,accessor-name)))\n (defun ,accessor-name (,name)\n (declare (type ,name ,name))\n (ldb (byte ,slot-size ,slot-position) ,name))\n (defun (setf ,accessor-name) (,new-value ,name)\n (declare (type ,name ,name))\n (setf (ldb (byte ,slot-size ,slot-position) ,name) ,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 _) in slots\n collect `(type (unsigned-byte ,slot-size) ,slot-name )))\n (let ((,tmp ,(caar revslots)))\n (declare (type (unsigned-byte ,total-size) ,tmp))\n ,@(loop for (slot-name slot-size _) in (cdr revslots)\n collect `(setq ,tmp (logxor ,slot-name\n (the (unsigned-byte ,total-size)\n (ash ,tmp ,slot-size)))))\n ,tmp))\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 (declare (type (unsigned-byte ,,total-size) ,',tmp))\n (let* ,(loop for var in vars\n for rest on ',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) ,',tmp))\n ,@(when (cdr rest)\n `((setq ,',tmp (ash ,',tmp ,(- slot-size))))))))\n ,@body))))))\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 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(define-integer-pack elm (station 20) (color 20) (dist 20))\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 #'eql :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 0 q)\n (setf (aref dist-seq 0) 0)\n (loop until (queue-empty-p q)\n for element = (dequeue q)\n do (with-unpacking-elm (station prevcolor dist) element\n ;; (dbg station prevcolor dist)\n (when (= station (- n 1))\n (println dist)\n (return-from main))\n (let* ((node (pack-elm station prevcolor 0))\n (old-dist (gethash node dists)))\n (when (or (null old-dist)\n (< dist (the uint31 old-dist)))\n (setf (gethash node dists) dist)\n (dolist (node (aref graph station))\n (let* ((nextstop (car node))\n (nextcolor (cdr node))\n (nextdist (if (= nextcolor prevcolor) dist (+ dist 1))))\n (declare (uint32 nextcolor nextdist))\n (when (and (null (gethash node dists))\n (<= nextdist (aref dist-seq nextstop)))\n (minf (aref dist-seq nextstop) nextdist)\n (if (= nextcolor prevcolor)\n (enqueue-front (pack-elm nextstop nextcolor nextdist) q)\n (enqueue (pack-elm nextstop nextcolor nextdist) q)))))))))\n (println -1)))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566351001, "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/s255360613.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s255360613", "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;; DEFINE-INTEGER-PACK and DEFINE-CONS-PACK are so to say poor man's variants of\n;; DEFSTRUCT. Both \"structures\" can only have slots of fixed unsigned\n;; bytes. DEFINE-INTEGER-PACK handles the concatenated slots as UNSIGNED-BYTE\n;; and DEFINE-CONS-PACK handles them as (CONS (UNSIGNED-BYTE 62) (UNSIGNED-BYTE\n;; 62)).\n\n;; Example:\n;; The following form defines the type NODE as (UNSIGNED-BYTE 9):\n;; (define-integer-pack node (slot1 3) (slot2 5) (slot3 1))\n;; This macro in addition defines relevant utilities: NODE-SLOT1, NODE-SLOT2,\n;; NODE-SLOT3, setters and getters, PACK-NODE, the constructor, and\n;; WITH-UNPACKING-NODE, the destructuring-bind-style macro.\n;; \n;; DEFINE-CONS-PACK is almost the same as DEFINE-INTEGER-PACK though it will be\n;; suitable for the total bits in the range [63, 124].\n\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-integer-pack (name &rest slot-descriptions)\n (assert slot-descriptions () \"~A has no slots.\" name)\n (let* ((packer-name (intern (%concat-name \"PACK\" name)))\n (unpacker-macro-name (intern (%concat-name \"WITH-UNPACKING\" name)))\n (total-size 0)\n (slots (loop with position = 0\n for (slot-name slot-size) in slot-descriptions\n collect (progn (check-type slot-name symbol)\n (check-type slot-size (integer 1))\n (list slot-name slot-size position))\n do (incf position slot-size)\n finally (setq total-size position)))\n (revslots (reverse slots))\n (new-value (gensym \"NEW-VALUE\"))\n (tmp (gensym)))\n `(progn\n (deftype ,name () '(unsigned-byte ,total-size))\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-name slot-size slot-position) in slots\n for accessor-name = (intern (%concat-name name slot-name))\n append `((declaim (inline ,accessor-name\n (setf ,accessor-name)))\n (defun ,accessor-name (,name)\n (declare (type ,name ,name))\n (ldb (byte ,slot-size ,slot-position) ,name))\n (defun (setf ,accessor-name) (,new-value ,name)\n (declare (type ,name ,name))\n (setf (ldb (byte ,slot-size ,slot-position) ,name) ,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 _) in slots\n collect `(type (unsigned-byte ,slot-size) ,slot-name )))\n (let ((,tmp ,(caar revslots)))\n (declare (type (unsigned-byte ,total-size) ,tmp))\n ,@(loop for (slot-name slot-size _) in (cdr revslots)\n collect `(setq ,tmp (logxor ,slot-name\n (the (unsigned-byte ,total-size)\n (ash ,tmp ,slot-size)))))\n ,tmp))\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 (declare (type (unsigned-byte ,,total-size) ,',tmp))\n (let* ,(loop for var in vars\n for rest on ',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) ,',tmp))\n ,@(when (cdr rest)\n `((setq ,',tmp (ash ,',tmp ,(- slot-size))))))))\n ,@body))))))\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 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(define-integer-pack elm (station 20) (color 20) (dist 20))\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 #'eql :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 0 q)\n (setf (aref dist-seq 0) 0)\n (loop until (queue-empty-p q)\n for element = (dequeue q)\n do (with-unpacking-elm (station prevcolor dist) element\n ;; (dbg station prevcolor dist)\n (when (= station (- n 1))\n (println dist)\n (return-from main))\n (let* ((node (pack-elm station prevcolor 0))\n (old-dist (gethash node dists)))\n (when (or (null old-dist)\n (< dist (the uint31 old-dist)))\n (setf (gethash node dists) dist)\n (dolist (node (aref graph station))\n (let* ((nextstop (car node))\n (nextcolor (cdr node))\n (nextdist (if (= nextcolor prevcolor) dist (+ dist 1))))\n (declare (uint32 nextcolor nextdist))\n (when (and (null (gethash node dists))\n (<= nextdist (aref dist-seq nextstop)))\n (minf (aref dist-seq nextstop) nextdist)\n (if (= nextcolor prevcolor)\n (enqueue-front (pack-elm nextstop nextcolor nextdist) q)\n (enqueue (pack-elm nextstop nextcolor nextdist) 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 9981, "cpu_time_ms": 3158, "memory_kb": 350948}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s301396769", "group_id": "codeNet:p04005", "input_text": "(defun solve(a b c)\n (let* ((l (sort (list a b c) #'<=)))\n (if (some #'evenp l)\n 0\n (* (first l) (second l)))))\n\n(defun main()\n (let ((a (read))\n (b (read))\n (c (read)))\n (princ (solve a b c))))\n\n(main)\n", "language": "Lisp", "metadata": {"date": 1593477969, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s301396769.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s301396769", "user_id": "u425762225"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defun solve(a b c)\n (let* ((l (sort (list a b c) #'<=)))\n (if (some #'evenp l)\n 0\n (* (first l) (second l)))))\n\n(defun main()\n (let ((a (read))\n (b (read))\n (c (read)))\n (princ (solve a b c))))\n\n(main)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 24356}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s057384761", "group_id": "codeNet:p04005", "input_text": "(defparameter *IN* (read-line))\n\n(defparameter *A* (parse-integer (subseq *IN* 0 1)))\n(defparameter *B* (parse-integer (subseq *IN* 2 3)))\n(defparameter *C* (parse-integer (subseq *IN* 4 5)))\n\n(defparameter *ANS* (if (= (or (mod *A* 2) (mod *B* 2) (mod *C* 2)) 0)\n\t\t\t0\n\t\t\t(min (* *A* *B*) (* *B* *C*) (* *C* *A*))))\n(princ *ANS*)", "language": "Lisp", "metadata": {"date": 1473555717, "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/s057384761.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s057384761", "user_id": "u678875535"}, "prompt_components": {"gold_output": "9\n", "input_to_evaluate": "(defparameter *IN* (read-line))\n\n(defparameter *A* (parse-integer (subseq *IN* 0 1)))\n(defparameter *B* (parse-integer (subseq *IN* 2 3)))\n(defparameter *C* (parse-integer (subseq *IN* 4 5)))\n\n(defparameter *ANS* (if (= (or (mod *A* 2) (mod *B* 2) (mod *C* 2)) 0)\n\t\t\t0\n\t\t\t(min (* *A* *B*) (* *B* *C*) (* *C* *A*))))\n(princ *ANS*)", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 195, "memory_kb": 10344}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s161130922", "group_id": "codeNet:p04007", "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 print-matrix))\n(defun print-matrix (array &key (separator #\\ ) (key #'identity) (row-start 0) row-end (col-start 0) col-end)\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 do (unless (= j col-start)\n (princ separator))\n (write (funcall key (aref array i j))))\n (terpri))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (plan (make-array (list h w) :element-type 'bit))\n (res1 (make-array (list h w) :element-type 'base-char :initial-element #\\.))\n (res2 (make-array (list h w) :element-type 'base-char :initial-element #\\.)))\n (dotimes (i h)\n (setf (aref res1 i 0) #\\#)\n (when (evenp i)\n (dotimes (j w)\n (setf (aref res1 i j) #\\#))))\n (dotimes (i h)\n (setf (aref res2 i (- w 1)) #\\#)\n (when (oddp i)\n (dotimes (j w)\n (setf (aref res2 i j) #\\#))))\n (dotimes (i h)\n (let ((line (read-line)))\n (dotimes (j w)\n (when (char= #\\# (aref line j))\n (setf (aref res1 i j) #\\#\n (aref res2 i j) #\\#)))))\n (let ((*print-escape* nil))\n (print-matrix res1 :separator \"\")\n (terpri)\n (print-matrix res2 :separator \"\"))))\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 5\n.....\n.#.#.\n.....\n.#.#.\n.....\n\"\n \".....\n#####\n#....\n#####\n.....\n\n.###.\n.#.#.\n.#.#.\n.#.#.\n.....\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7 13\n.............\n.###.###.###.\n.#.#.#...#...\n.###.#...#...\n.#.#.#.#.#...\n.#.#.###.###.\n.............\n\"\n \".............\n.###########.\n.###.###.###.\n.###.###.###.\n.###.###.###.\n.###.###.###.\n.............\n\n.............\n.###.###.###.\n.#.#.#...#...\n.###.#...#...\n.#.#.#.#.#...\n.#.#########.\n.............\n\")))\n", "language": "Lisp", "metadata": {"date": 1585018966, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04007.html", "problem_id": "p04007", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04007/input.txt", "sample_output_relpath": "derived/input_output/data/p04007/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04007/Lisp/s161130922.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s161130922", "user_id": "u352600849"}, "prompt_components": {"gold_output": ".....\n#####\n#....\n#####\n.....\n\n.###.\n.#.#.\n.#.#.\n.#.#.\n.....\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 print-matrix))\n(defun print-matrix (array &key (separator #\\ ) (key #'identity) (row-start 0) row-end (col-start 0) col-end)\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 do (unless (= j col-start)\n (princ separator))\n (write (funcall key (aref array i j))))\n (terpri))))\n\n(defmacro dbg (&rest forms)\n #+swank\n (if (= (length forms) 1)\n `(format *error-output* \"~A => ~A~%\" ',(car forms) ,(car forms))\n `(format *error-output* \"~A => ~A~%\" ',forms `(,,@forms)))\n #-swank (declare (ignore forms)))\n\n(defmacro define-int-types (&rest bits)\n `(progn\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"UINT~A\" b)) () '(unsigned-byte ,b))) bits)\n ,@(mapcar (lambda (b) `(deftype ,(intern (format nil \"INT~A\" b)) () '(signed-byte ,b))) bits)))\n(define-int-types 2 4 7 8 15 16 31 32 62 63 64)\n\n(declaim (inline println))\n(defun println (obj &optional (stream *standard-output*))\n (let ((*read-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 (plan (make-array (list h w) :element-type 'bit))\n (res1 (make-array (list h w) :element-type 'base-char :initial-element #\\.))\n (res2 (make-array (list h w) :element-type 'base-char :initial-element #\\.)))\n (dotimes (i h)\n (setf (aref res1 i 0) #\\#)\n (when (evenp i)\n (dotimes (j w)\n (setf (aref res1 i j) #\\#))))\n (dotimes (i h)\n (setf (aref res2 i (- w 1)) #\\#)\n (when (oddp i)\n (dotimes (j w)\n (setf (aref res2 i j) #\\#))))\n (dotimes (i h)\n (let ((line (read-line)))\n (dotimes (j w)\n (when (char= #\\# (aref line j))\n (setf (aref res1 i j) #\\#\n (aref res2 i j) #\\#)))))\n (let ((*print-escape* nil))\n (print-matrix res1 :separator \"\")\n (terpri)\n (print-matrix res2 :separator \"\"))))\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 5\n.....\n.#.#.\n.....\n.#.#.\n.....\n\"\n \".....\n#####\n#....\n#####\n.....\n\n.###.\n.#.#.\n.#.#.\n.#.#.\n.....\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"7 13\n.............\n.###.###.###.\n.#.#.#...#...\n.###.#...#...\n.#.#.#.#.#...\n.#.#.###.###.\n.............\n\"\n \".............\n.###########.\n.###.###.###.\n.###.###.###.\n.###.###.###.\n.###.###.###.\n.............\n\n.............\n.###.###.###.\n.#.#.#...#...\n.###.#...#...\n.#.#.#.#.#...\n.#.#########.\n.............\n\")))\n", "problem_context": "Score : 700 points\n\nProblem Statement\n\nSnuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.\n\nSnuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.\n\nCiel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.\n\nAfterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.\n\nYou are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is #, otherwise a_{ij} is .. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is ..\n\nFind a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.\n\nConstraints\n\n3≤H,W≤500\n\na_{ij} is # or ..\n\nIf i=1,H or j=1,W, then a_{ij} is ..\n\nAt least one of a_{ij} is #.\n\nInput\n\nThe input 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 a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:\n\nThe first H lines should describe the positions of the red cells.\n\nThe following 1 line should be empty.\n\nThe following H lines should describe the positions of the blue cells.\n\nThe description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.\n\nSample Input 1\n\n5 5\n.....\n.#.#.\n.....\n.#.#.\n.....\n\nSample Output 1\n\n.....\n#####\n#....\n#####\n.....\n\n.###.\n.#.#.\n.#.#.\n.#.#.\n.....\n\nOne possible pair of the set of the positions of the red cells and the blue cells is as follows:\n\nSample Input 2\n\n7 13\n.............\n.###.###.###.\n.#.#.#...#...\n.###.#...#...\n.#.#.#.#.#...\n.#.#.###.###.\n.............\n\nSample Output 2\n\n.............\n.###########.\n.###.###.###.\n.###.###.###.\n.###.###.###.\n.###.###.###.\n.............\n\n.............\n.###.###.###.\n.#.#.#...#...\n.###.#...#...\n.#.#.#.#.#...\n.#.#########.\n.............\n\nOne possible pair of the set of the positions of the red cells and the blue cells is as follows:", "sample_input": "5 5\n.....\n.#.#.\n.....\n.#.#.\n.....\n"}, "reference_outputs": [".....\n#####\n#....\n#####\n.....\n\n.###.\n.#.#.\n.#.#.\n.#.#.\n.....\n"], "source_document_id": "p04007", "source_text": "Score : 700 points\n\nProblem Statement\n\nSnuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.\n\nSnuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.\n\nCiel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.\n\nAfterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.\n\nYou are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is #, otherwise a_{ij} is .. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is ..\n\nFind a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.\n\nConstraints\n\n3≤H,W≤500\n\na_{ij} is # or ..\n\nIf i=1,H or j=1,W, then a_{ij} is ..\n\nAt least one of a_{ij} is #.\n\nInput\n\nThe input 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 a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:\n\nThe first H lines should describe the positions of the red cells.\n\nThe following 1 line should be empty.\n\nThe following H lines should describe the positions of the blue cells.\n\nThe description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.\n\nSample Input 1\n\n5 5\n.....\n.#.#.\n.....\n.#.#.\n.....\n\nSample Output 1\n\n.....\n#####\n#....\n#####\n.....\n\n.###.\n.#.#.\n.#.#.\n.#.#.\n.....\n\nOne possible pair of the set of the positions of the red cells and the blue cells is as follows:\n\nSample Input 2\n\n7 13\n.............\n.###.###.###.\n.#.#.#...#...\n.###.#...#...\n.#.#.#.#.#...\n.#.#.###.###.\n.............\n\nSample Output 2\n\n.............\n.###########.\n.###.###.###.\n.###.###.###.\n.###.###.###.\n.###.###.###.\n.............\n\n.............\n.###.###.###.\n.#.#.#...#...\n.###.#...#...\n.#.#.#.#.#...\n.#.#########.\n.............\n\nOne possible pair of the set of the positions of the red cells and the blue cells is as follows:", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 412, "memory_kb": 21480}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s402968162", "group_id": "codeNet:p04008", "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 (k (read))\n (k-1 (- k 1))\n ;; (graph (make-array n :element-type 'uint32 :initial-element 0))\n (revgraph (make-array n :element-type 'list :initial-element nil))\n (neighbors (make-array n :element-type 'bit :initial-element 0))\n (res 0))\n (dotimes (i n)\n (let ((a (- (read-fixnum) 1)))\n (if (zerop i)\n (unless (zerop a)\n (incf res))\n (push i (aref revgraph a)))\n (when (zerop a)\n (setf (aref neighbors i) 1))))\n #>neighbors\n (labels ((dfs (v parent)\n (let ((depth 0))\n (dolist (child (aref revgraph v))\n (unless (= child parent)\n (maxf depth (+ 1 (dfs child v)))))\n (assert (<= depth k-1))\n (if (= depth k-1)\n (progn\n (unless (or (zerop v)\n (= (aref neighbors v) 1))\n (incf res))\n -1)\n depth))))\n (dfs 0 -1)\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\n2 3 1\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n1 1 2 2\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 2\n4 1 2 3 1 2 3 4\n\"\n \"3\n\")))\n", "language": "Lisp", "metadata": {"date": 1585022108, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04008.html", "problem_id": "p04008", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04008/input.txt", "sample_output_relpath": "derived/input_output/data/p04008/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04008/Lisp/s402968162.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s402968162", "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 ;; 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 (k (read))\n (k-1 (- k 1))\n ;; (graph (make-array n :element-type 'uint32 :initial-element 0))\n (revgraph (make-array n :element-type 'list :initial-element nil))\n (neighbors (make-array n :element-type 'bit :initial-element 0))\n (res 0))\n (dotimes (i n)\n (let ((a (- (read-fixnum) 1)))\n (if (zerop i)\n (unless (zerop a)\n (incf res))\n (push i (aref revgraph a)))\n (when (zerop a)\n (setf (aref neighbors i) 1))))\n #>neighbors\n (labels ((dfs (v parent)\n (let ((depth 0))\n (dolist (child (aref revgraph v))\n (unless (= child parent)\n (maxf depth (+ 1 (dfs child v)))))\n (assert (<= depth k-1))\n (if (= depth k-1)\n (progn\n (unless (or (zerop v)\n (= (aref neighbors v) 1))\n (incf res))\n -1)\n depth))))\n (dfs 0 -1)\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\n2 3 1\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"4 2\n1 1 2 2\n\"\n \"0\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"8 2\n4 1 2 3 1 2 3 4\n\"\n \"3\n\")))\n", "problem_context": "Score : 800 points\n\nProblem Statement\n\nThere are N towns in Snuke Kingdom, conveniently numbered 1 through N.\nTown 1 is the capital.\n\nEach town in the kingdom has a Teleporter, a facility that instantly transports a person to another place.\nThe destination of the Teleporter of town i is town a_i (1≤a_i≤N).\nIt is guaranteed that one can get to the capital from any town by using the Teleporters some number of times.\n\nKing Snuke loves the integer K.\nThe selfish king wants to change the destination of the Teleporters so that the following holds:\n\nStarting from any town, one will be at the capital after using the Teleporters exactly K times in total.\n\nFind the minimum number of the Teleporters whose destinations need to be changed in order to satisfy the king's desire.\n\nConstraints\n\n2≤N≤10^5\n\n1≤a_i≤N\n\nOne can get to the capital from any town by using the Teleporters some number of times.\n\n1≤K≤10^9\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 minimum number of the Teleporters whose destinations need to be changed in order to satisfy King Snuke's desire.\n\nSample Input 1\n\n3 1\n2 3 1\n\nSample Output 1\n\n2\n\nChange the destinations of the Teleporters to a = (1,1,1).\n\nSample Input 2\n\n4 2\n1 1 2 2\n\nSample Output 2\n\n0\n\nThere is no need to change the destinations of the Teleporters, since the king's desire is already satisfied.\n\nSample Input 3\n\n8 2\n4 1 2 3 1 2 3 4\n\nSample Output 3\n\n3\n\nFor example, change the destinations of the Teleporters to a = (1,1,2,1,1,2,2,4).", "sample_input": "3 1\n2 3 1\n"}, "reference_outputs": ["2\n"], "source_document_id": "p04008", "source_text": "Score : 800 points\n\nProblem Statement\n\nThere are N towns in Snuke Kingdom, conveniently numbered 1 through N.\nTown 1 is the capital.\n\nEach town in the kingdom has a Teleporter, a facility that instantly transports a person to another place.\nThe destination of the Teleporter of town i is town a_i (1≤a_i≤N).\nIt is guaranteed that one can get to the capital from any town by using the Teleporters some number of times.\n\nKing Snuke loves the integer K.\nThe selfish king wants to change the destination of the Teleporters so that the following holds:\n\nStarting from any town, one will be at the capital after using the Teleporters exactly K times in total.\n\nFind the minimum number of the Teleporters whose destinations need to be changed in order to satisfy the king's desire.\n\nConstraints\n\n2≤N≤10^5\n\n1≤a_i≤N\n\nOne can get to the capital from any town by using the Teleporters some number of times.\n\n1≤K≤10^9\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 minimum number of the Teleporters whose destinations need to be changed in order to satisfy King Snuke's desire.\n\nSample Input 1\n\n3 1\n2 3 1\n\nSample Output 1\n\n2\n\nChange the destinations of the Teleporters to a = (1,1,1).\n\nSample Input 2\n\n4 2\n1 1 2 2\n\nSample Output 2\n\n0\n\nThere is no need to change the destinations of the Teleporters, since the king's desire is already satisfied.\n\nSample Input 3\n\n8 2\n4 1 2 3 1 2 3 4\n\nSample Output 3\n\n3\n\nFor example, change the destinations of the Teleporters to a = (1,1,2,1,1,2,2,4).", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 6582, "cpu_time_ms": 233, "memory_kb": 31804}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s209902440", "group_id": "codeNet:p04012", "input_text": "(defun outer (l1 l2)\n (union (set-difference l1 l2)\n (set-difference l2 l1)))\n\n(defun solve (l tl)\n (cond \n ((null l) (if (null tl) \"Yes\" \"No\"))\n (t (solve (cdr l) (outer tl (list (car l)))))))\n\n(defun main ()\n (let ((str (read-line)))\n (princ (solve (loop :as c \n :across str \n :collect c) \n '()))))\n\n(main)\n \n ", "language": "Lisp", "metadata": {"date": 1592513799, "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/s209902440.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s209902440", "user_id": "u606976120"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(defun outer (l1 l2)\n (union (set-difference l1 l2)\n (set-difference l2 l1)))\n\n(defun solve (l tl)\n (cond \n ((null l) (if (null tl) \"Yes\" \"No\"))\n (t (solve (cdr l) (outer tl (list (car l)))))))\n\n(defun main ()\n (let ((str (read-line)))\n (princ (solve (loop :as c \n :across str \n :collect c) \n '()))))\n\n(main)\n \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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 396, "cpu_time_ms": 14, "memory_kb": 3944}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s831784814", "group_id": "codeNet:p04012", "input_text": "(setq s(sort(concatenate'list(read-line))#'char<))\n(princ(if(=(mod(length s)2)1)\"No\"(if(>(loop for i from 0 to(1-(/(length s)2))count(char/=(nth(* i 2)s)(nth(1+(* i 2))s)))0)\"No\"\"Yes\")))", "language": "Lisp", "metadata": {"date": 1537904981, "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/s831784814.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s831784814", "user_id": "u657913472"}, "prompt_components": {"gold_output": "Yes\n", "input_to_evaluate": "(setq s(sort(concatenate'list(read-line))#'char<))\n(princ(if(=(mod(length s)2)1)\"No\"(if(>(loop for i from 0 to(1-(/(length s)2))count(char/=(nth(* i 2)s)(nth(1+(* i 2))s)))0)\"No\"\"Yes\")))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 150, "memory_kb": 13544}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s502647713", "group_id": "codeNet:p04013", "input_text": "(defvar *b*)\n(defvar *cache*)\n(defvar *x*)\n\n(defun binomial (n)\n\t(setf *b* (make-array (list n n)))\n\t(dotimes (i n)\n\t\t(setf (aref *b* 0 i) 0)\n\t\t(setf (aref *b* i i) 1))\n\t(loop :for i :from 1 :below n :do\n\t\t (loop :for j :from 1 :below i :do\n\t\t\t\t(setf (aref *b* i j) (+ (aref *b* (1- i) (1- j)) (aref *b* (1- i) j))))))\n\n(defun s (a k i)\n\t(cond ((< a 0) 0)\n\t\t\t\t((< k 0) 0)\n\t\t\t\t((zerop k) (if (zerop a) 1 0))\n\t\t\t\t((> i a) 0)\n\t\t\t\t((= i 51) 0)\n\t\t\t\t(t (let ((key (+ (* a 51 51) (* k 51) i)))\n\t\t\t\t\t\t (if (aref *cache* key)\n\t\t\t\t\t\t\t\t (aref *cache* key)\n\t\t\t\t\t\t\t\t (let ((c (s a k (1+ i))))\n\t\t\t\t\t\t\t\t\t (loop :for j :from 1 :to (aref *x* i) :do\n\t\t\t\t\t\t\t\t\t\t\t(incf c (* (aref *b* (1+ (aref *x* i)) (1+ j))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t (s (- a (* i j)) (- k j) (1+ i)))))\n\t\t\t\t\t\t\t\t\t (setf (aref *cache* key) c)\n\t\t\t\t\t\t\t\t\t c))))))\n\n(let ((n (read))\n\t\t\t(a (read)))\n\t(binomial (+ n 2))\n\t(setf *cache* (make-array (expt 51 4) :initial-element nil))\n\t(setf *x* (make-array 51 :initial-element 0))\n\t(loop :repeat n :do (incf (aref *x* (read))))\n\t(format t \"~a~%\" (loop :for i :from 1 :to n :sum (s (* a i) i 0))))\n", "language": "Lisp", "metadata": {"date": 1522923941, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "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/s502647713.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s502647713", "user_id": "u132434645"}, "prompt_components": {"gold_output": "5\n", "input_to_evaluate": "(defvar *b*)\n(defvar *cache*)\n(defvar *x*)\n\n(defun binomial (n)\n\t(setf *b* (make-array (list n n)))\n\t(dotimes (i n)\n\t\t(setf (aref *b* 0 i) 0)\n\t\t(setf (aref *b* i i) 1))\n\t(loop :for i :from 1 :below n :do\n\t\t (loop :for j :from 1 :below i :do\n\t\t\t\t(setf (aref *b* i j) (+ (aref *b* (1- i) (1- j)) (aref *b* (1- i) j))))))\n\n(defun s (a k i)\n\t(cond ((< a 0) 0)\n\t\t\t\t((< k 0) 0)\n\t\t\t\t((zerop k) (if (zerop a) 1 0))\n\t\t\t\t((> i a) 0)\n\t\t\t\t((= i 51) 0)\n\t\t\t\t(t (let ((key (+ (* a 51 51) (* k 51) i)))\n\t\t\t\t\t\t (if (aref *cache* key)\n\t\t\t\t\t\t\t\t (aref *cache* key)\n\t\t\t\t\t\t\t\t (let ((c (s a k (1+ i))))\n\t\t\t\t\t\t\t\t\t (loop :for j :from 1 :to (aref *x* i) :do\n\t\t\t\t\t\t\t\t\t\t\t(incf c (* (aref *b* (1+ (aref *x* i)) (1+ j))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t (s (- a (* i j)) (- k j) (1+ i)))))\n\t\t\t\t\t\t\t\t\t (setf (aref *cache* key) c)\n\t\t\t\t\t\t\t\t\t c))))))\n\n(let ((n (read))\n\t\t\t(a (read)))\n\t(binomial (+ n 2))\n\t(setf *cache* (make-array (expt 51 4) :initial-element nil))\n\t(setf *x* (make-array 51 :initial-element 0))\n\t(loop :repeat n :do (incf (aref *x* (read))))\n\t(format t \"~a~%\" (loop :for i :from 1 :to n :sum (s (* a i) i 0))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 370, "memory_kb": 80096}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s110849002", "group_id": "codeNet:p04021", "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;;; 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 ((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(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)))))\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. 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 (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* ((n (read))\n (as (make-array n :element-type 'uint32)))\n (declare (uint32 n))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (let ((sorted-as (sort (copy-seq as) #'<))\n (parities (make-array n :element-type 'bit :initial-element 0))\n (seq1 (make-array n :element-type 'uint32 :initial-element 0))\n (seq2 (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (when (oddp (bisect-left sorted-as (aref as i)))\n (setf (aref parities i) 1)))\n (let ((index0 0)\n (index1 1))\n (dotimes (i n)\n (if (zerop (aref parities i))\n (progn (setf (aref seq1 i) index0)\n (incf index0 2))\n (progn (setf (aref seq1 i) index1)\n (incf index1 2)))))\n (let ((index0 1)\n (index1 0))\n (dotimes (i n)\n (if (zerop (aref parities i))\n (progn (setf (aref seq2 i) index0)\n (incf index0 2))\n (progn (setf (aref seq2 i) index1)\n (incf index1 2)))))\n (dbg seq1 seq2)\n (println (min (calc-inversion-number! seq1 #'<)\n (if (evenp n)\n (calc-inversion-number! seq2 #'<)\n most-positive-fixnum))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566851263, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04021.html", "problem_id": "p04021", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04021/input.txt", "sample_output_relpath": "derived/input_output/data/p04021/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04021/Lisp/s110849002.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s110849002", "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 (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;;; 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 ((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(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)))))\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. 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 (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* ((n (read))\n (as (make-array n :element-type 'uint32)))\n (declare (uint32 n))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (let ((sorted-as (sort (copy-seq as) #'<))\n (parities (make-array n :element-type 'bit :initial-element 0))\n (seq1 (make-array n :element-type 'uint32 :initial-element 0))\n (seq2 (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (when (oddp (bisect-left sorted-as (aref as i)))\n (setf (aref parities i) 1)))\n (let ((index0 0)\n (index1 1))\n (dotimes (i n)\n (if (zerop (aref parities i))\n (progn (setf (aref seq1 i) index0)\n (incf index0 2))\n (progn (setf (aref seq1 i) index1)\n (incf index1 2)))))\n (let ((index0 1)\n (index1 0))\n (dotimes (i n)\n (if (zerop (aref parities i))\n (progn (setf (aref seq2 i) index0)\n (incf index0 2))\n (progn (setf (aref seq2 i) index1)\n (incf index1 2)))))\n (dbg seq1 seq2)\n (println (min (calc-inversion-number! seq1 #'<)\n (if (evenp n)\n (calc-inversion-number! seq2 #'<)\n most-positive-fixnum))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke got an integer sequence of length N from his mother, as a birthday present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are pairwise distinct.\nHe is sorting this sequence in increasing order.\nWith supernatural power, he can perform the following two operations on the sequence in any order:\n\nOperation 1: choose 2 consecutive elements, then reverse the order of those elements.\n\nOperation 2: choose 3 consecutive elements, then reverse the order of those elements.\n\nSnuke likes Operation 2, but not Operation 1. Find the minimum number of Operation 1 that he has to perform in order to sort the sequence in increasing order.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9\n\nIf i ≠ j, then A_i ≠ A_j.\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 minimum number of times Operation 1 that Snuke has to perform.\n\nSample Input 1\n\n4\n2\n4\n3\n1\n\nSample Output 1\n\n1\n\nThe given sequence can be sorted as follows:\n\nFirst, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n\nThen, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not possible to sort the sequence with less number of Operation 1, thus the answer is 1.\n\nSample Input 2\n\n5\n10\n8\n5\n3\n2\n\nSample Output 2\n\n0", "sample_input": "4\n2\n4\n3\n1\n"}, "reference_outputs": ["1\n"], "source_document_id": "p04021", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke got an integer sequence of length N from his mother, as a birthday present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are pairwise distinct.\nHe is sorting this sequence in increasing order.\nWith supernatural power, he can perform the following two operations on the sequence in any order:\n\nOperation 1: choose 2 consecutive elements, then reverse the order of those elements.\n\nOperation 2: choose 3 consecutive elements, then reverse the order of those elements.\n\nSnuke likes Operation 2, but not Operation 1. Find the minimum number of Operation 1 that he has to perform in order to sort the sequence in increasing order.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9\n\nIf i ≠ j, then A_i ≠ A_j.\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 minimum number of times Operation 1 that Snuke has to perform.\n\nSample Input 1\n\n4\n2\n4\n3\n1\n\nSample Output 1\n\n1\n\nThe given sequence can be sorted as follows:\n\nFirst, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n\nThen, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not possible to sort the sequence with less number of Operation 1, thus the answer is 1.\n\nSample Input 2\n\n5\n10\n8\n5\n3\n2\n\nSample Output 2\n\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13411, "cpu_time_ms": 338, "memory_kb": 55912}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s637841564", "group_id": "codeNet:p04021", "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;;; 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 ((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(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)))))\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. 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 (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* ((n (read))\n (as (make-array n :element-type 'uint32)))\n (declare (uint32 n))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (let ((sorted-as (sort (copy-seq as) #'<))\n (parities (make-array n :element-type 'bit :initial-element 0))\n (seq1 (make-array n :element-type 'uint32 :initial-element 0))\n (seq2 (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (when (oddp (bisect-left sorted-as (aref as i)))\n (setf (aref parities i) 1)))\n (let ((index0 0)\n (index1 1))\n (dotimes (i n)\n (if (zerop (aref parities i))\n (progn (setf (aref seq1 i) index0)\n (incf index0 2))\n (progn (setf (aref seq1 i) index1)\n (incf index1 2)))))\n (let ((index0 1)\n (index1 0))\n (dotimes (i n)\n (if (zerop (aref parities i))\n (progn (setf (aref seq2 i) index0)\n (incf index0 2))\n (progn (setf (aref seq2 i) index1)\n (incf index1 2)))))\n (dbg seq1 seq2)\n (println (min (calc-inversion-number! seq1 #'<)\n (calc-inversion-number! seq2 #'<))))))\n\n#-swank (main)\n", "language": "Lisp", "metadata": {"date": 1566851131, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04021.html", "problem_id": "p04021", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04021/input.txt", "sample_output_relpath": "derived/input_output/data/p04021/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04021/Lisp/s637841564.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s637841564", "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 (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;;; 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 ((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(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)))))\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. 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 (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* ((n (read))\n (as (make-array n :element-type 'uint32)))\n (declare (uint32 n))\n (dotimes (i n) (setf (aref as i) (read-fixnum)))\n (let ((sorted-as (sort (copy-seq as) #'<))\n (parities (make-array n :element-type 'bit :initial-element 0))\n (seq1 (make-array n :element-type 'uint32 :initial-element 0))\n (seq2 (make-array n :element-type 'uint32 :initial-element 0)))\n (dotimes (i n)\n (when (oddp (bisect-left sorted-as (aref as i)))\n (setf (aref parities i) 1)))\n (let ((index0 0)\n (index1 1))\n (dotimes (i n)\n (if (zerop (aref parities i))\n (progn (setf (aref seq1 i) index0)\n (incf index0 2))\n (progn (setf (aref seq1 i) index1)\n (incf index1 2)))))\n (let ((index0 1)\n (index1 0))\n (dotimes (i n)\n (if (zerop (aref parities i))\n (progn (setf (aref seq2 i) index0)\n (incf index0 2))\n (progn (setf (aref seq2 i) index1)\n (incf index1 2)))))\n (dbg seq1 seq2)\n (println (min (calc-inversion-number! seq1 #'<)\n (calc-inversion-number! seq2 #'<))))))\n\n#-swank (main)\n", "problem_context": "Score : 600 points\n\nProblem Statement\n\nSnuke got an integer sequence of length N from his mother, as a birthday present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are pairwise distinct.\nHe is sorting this sequence in increasing order.\nWith supernatural power, he can perform the following two operations on the sequence in any order:\n\nOperation 1: choose 2 consecutive elements, then reverse the order of those elements.\n\nOperation 2: choose 3 consecutive elements, then reverse the order of those elements.\n\nSnuke likes Operation 2, but not Operation 1. Find the minimum number of Operation 1 that he has to perform in order to sort the sequence in increasing order.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9\n\nIf i ≠ j, then A_i ≠ A_j.\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 minimum number of times Operation 1 that Snuke has to perform.\n\nSample Input 1\n\n4\n2\n4\n3\n1\n\nSample Output 1\n\n1\n\nThe given sequence can be sorted as follows:\n\nFirst, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n\nThen, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not possible to sort the sequence with less number of Operation 1, thus the answer is 1.\n\nSample Input 2\n\n5\n10\n8\n5\n3\n2\n\nSample Output 2\n\n0", "sample_input": "4\n2\n4\n3\n1\n"}, "reference_outputs": ["1\n"], "source_document_id": "p04021", "source_text": "Score : 600 points\n\nProblem Statement\n\nSnuke got an integer sequence of length N from his mother, as a birthday present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are pairwise distinct.\nHe is sorting this sequence in increasing order.\nWith supernatural power, he can perform the following two operations on the sequence in any order:\n\nOperation 1: choose 2 consecutive elements, then reverse the order of those elements.\n\nOperation 2: choose 3 consecutive elements, then reverse the order of those elements.\n\nSnuke likes Operation 2, but not Operation 1. Find the minimum number of Operation 1 that he has to perform in order to sort the sequence in increasing order.\n\nConstraints\n\n1 ≦ N ≦ 10^5\n\n0 ≦ A_i ≦ 10^9\n\nIf i ≠ j, then A_i ≠ A_j.\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 minimum number of times Operation 1 that Snuke has to perform.\n\nSample Input 1\n\n4\n2\n4\n3\n1\n\nSample Output 1\n\n1\n\nThe given sequence can be sorted as follows:\n\nFirst, reverse the order of the last three elements. The sequence is now: 2,1,3,4.\n\nThen, reverse the order of the first two elements. The sequence is now: 1,2,3,4.\n\nIn this sequence of operations, Operation 1 is performed once. It is not possible to sort the sequence with less number of Operation 1, thus the answer is 1.\n\nSample Input 2\n\n5\n10\n8\n5\n3\n2\n\nSample Output 2\n\n0", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 13327, "cpu_time_ms": 505, "memory_kb": 68452}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s142067138", "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(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 ((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": 1584948301, "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/s142067138.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Time Limit Exceeded", "submission_id": "s142067138", "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(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 ((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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 11798, "cpu_time_ms": 5257, "memory_kb": 74336}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s522261467", "group_id": "codeNet:p04029", "input_text": "(let ((n (read)))\n (print (/ (* n (+ 1 n)) 2)))\n", "language": "Lisp", "metadata": {"date": 1553323844, "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/s522261467.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s522261467", "user_id": "u166060166"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(let ((n (read)))\n (print (/ (* 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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 96, "memory_kb": 10212}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s081377569", "group_id": "codeNet:p04029", "input_text": "(defun f(n)(if(= n 0)0(+(f(1- n))n)))\n(princ(f(read)))", "language": "Lisp", "metadata": {"date": 1552606831, "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/s081377569.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s081377569", "user_id": "u994767958"}, "prompt_components": {"gold_output": "6\n", "input_to_evaluate": "(defun f(n)(if(= n 0)0(+(f(1- n))n)))\n(princ(f(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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 10, "memory_kb": 3300}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s972732644", "group_id": "codeNet:p04030", "input_text": "(defun frontspace (l)\n (if (null l)\n nil\n (if (eq (car l) #\\B)\n (frontspace (cdr l))\n (cons (car l) (frontspace (cddr l))))))\n\n(setq lst1 (reverse (concatenate 'list \"01B0\")))\n(setq lst2 (reverse (concatenate 'list \"0BB1\")))\n\n(frontspace lst1)\n(frontspace lst2)\n", "language": "Lisp", "metadata": {"date": 1594408824, "filename_ext": "l", "original_language": "Common Lisp (SBCL 2.0.3)", "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/s972732644.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s972732644", "user_id": "u336541610"}, "prompt_components": {"gold_output": "00\n", "input_to_evaluate": "(defun frontspace (l)\n (if (null l)\n nil\n (if (eq (car l) #\\B)\n (frontspace (cdr l))\n (cons (car l) (frontspace (cddr l))))))\n\n(setq lst1 (reverse (concatenate 'list \"01B0\")))\n(setq lst2 (reverse (concatenate 'list \"0BB1\")))\n\n(frontspace lst1)\n(frontspace lst2)\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 16, "memory_kb": 23524}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s314251188", "group_id": "codeNet:p04030", "input_text": "(format t \"~{~A~}~%\" (labels ((f (list acc)\n (if list\n (case (car list)\n (#\\0 (f (cdr list) (cons 0 acc)))\n (#\\1 (f (cdr list) (cons 1 acc)))\n (#\\B (f (cdr list) (cdr acc))))\n (reverse acc))))\n (f (coerce (read-line) 'list) nil)))", "language": "Lisp", "metadata": {"date": 1504639564, "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/s314251188.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s314251188", "user_id": "u140665374"}, "prompt_components": {"gold_output": "00\n", "input_to_evaluate": "(format t \"~{~A~}~%\" (labels ((f (list acc)\n (if list\n (case (car list)\n (#\\0 (f (cdr list) (cons 0 acc)))\n (#\\1 (f (cdr list) (cons 1 acc)))\n (#\\B (f (cdr list) (cdr acc))))\n (reverse acc))))\n (f (coerce (read-line) 'list) nil)))", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 440, "cpu_time_ms": 9, "memory_kb": 3304}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s553291720", "group_id": "codeNet:p04032", "input_text": "(defun take (n l)\n (if (or (zerop n) (null l))\n nil\n (cons (car l) (take (1- n) (cdr l)))))\n\n(defun group (n l)\n (if (null l)\n nil\n (cons (take n l) (group n (cdr l)))))\n\n(defun check (c)\n (if (member (car c) (cdr c))\n c\n (check (cdr c))))\n\n(defparameter ans '(-1 . -1))\n(defun solve (s)\n (loop\n for i from 1 to (length s)\n for c in (group 3 s)\n if (check c)\n do (setf ans (cons i (+ i 2))) and return ans))\n\n(solve (concatenate 'list (read-line)))\n(format t \"~a ~a~%\" (car ans) (cdr ans))\n", "language": "Lisp", "metadata": {"date": 1471140332, "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/s553291720.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Wrong Answer", "submission_id": "s553291720", "user_id": "u328322317"}, "prompt_components": {"gold_output": "2 5\n", "input_to_evaluate": "(defun take (n l)\n (if (or (zerop n) (null l))\n nil\n (cons (car l) (take (1- n) (cdr l)))))\n\n(defun group (n l)\n (if (null l)\n nil\n (cons (take n l) (group n (cdr l)))))\n\n(defun check (c)\n (if (member (car c) (cdr c))\n c\n (check (cdr c))))\n\n(defparameter ans '(-1 . -1))\n(defun solve (s)\n (loop\n for i from 1 to (length s)\n for c in (group 3 s)\n if (check c)\n do (setf ans (cons i (+ i 2))) and return ans))\n\n(solve (concatenate 'list (read-line)))\n(format t \"~a ~a~%\" (car ans) (cdr ans))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 538, "cpu_time_ms": 2113, "memory_kb": 72844}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s923088591", "group_id": "codeNet:p04033", "input_text": "(let ((a (read))\n (b (read)))\n (format t \"~a~%\"\n (cond ((> a 0) \"Positive\")\n ((>= b 0) \"Zero\")\n ((zerop (mod (- a b) 2)) \"Negative\")\n (t \"Positive\"))))\n", "language": "Lisp", "metadata": {"date": 1532428284, "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/s923088591.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s923088591", "user_id": "u132434645"}, "prompt_components": {"gold_output": "Positive\n", "input_to_evaluate": "(let ((a (read))\n (b (read)))\n (format t \"~a~%\"\n (cond ((> a 0) \"Positive\")\n ((>= b 0) \"Zero\")\n ((zerop (mod (- a b) 2)) \"Negative\")\n (t \"Positive\"))))\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 143, "memory_kb": 13540}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s594531399", "group_id": "codeNet:p04040", "input_text": "#include \nusing namespace std;\n#define M 1000000007\n\nint modexp(int x, int e, int m) {\n long long ans = 1, p = x % m;\n while (e > 0) {\n if (e % 2 != 0) ans = ans * p % m;\n p = p * p % m;\n e >>= 1;\n }\n return ans;\n}\n\nlong long fact[200001], facti[200001];\n\nlong long C(int n, int k) {\n if (n < 0 || k < 0 || k > n) return 0;\n return fact[n] * facti[k] % M * facti[n-k] % M;\n}\n\nint main(int argc, char** argv) {\n int h, w, a, b; cin >> h >> w >> a >> b;\n fact[0] = 1; facti[0] = 1;\n for (int i = 1; i <= h+w; i++) {\n fact[i] = fact[i-1] * i % M;\n facti[i] = modexp(fact[i], M-2, M);\n }\n long long ans = 0;\n for (int i = 1; i <= h-a; i++) ans += C(i+b-2, i-1) * C(h+w-b-i-1, h-i) % M;\n cout << ans % M << endl;\n}\n", "language": "Lisp", "metadata": {"date": 1540039599, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04040.html", "problem_id": "p04040", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04040/input.txt", "sample_output_relpath": "derived/input_output/data/p04040/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04040/Lisp/s594531399.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s594531399", "user_id": "u374416262"}, "prompt_components": {"gold_output": "2\n", "input_to_evaluate": "#include \nusing namespace std;\n#define M 1000000007\n\nint modexp(int x, int e, int m) {\n long long ans = 1, p = x % m;\n while (e > 0) {\n if (e % 2 != 0) ans = ans * p % m;\n p = p * p % m;\n e >>= 1;\n }\n return ans;\n}\n\nlong long fact[200001], facti[200001];\n\nlong long C(int n, int k) {\n if (n < 0 || k < 0 || k > n) return 0;\n return fact[n] * facti[k] % M * facti[n-k] % M;\n}\n\nint main(int argc, char** argv) {\n int h, w, a, b; cin >> h >> w >> a >> b;\n fact[0] = 1; facti[0] = 1;\n for (int i = 1; i <= h+w; i++) {\n fact[i] = fact[i-1] * i % M;\n facti[i] = modexp(fact[i], M-2, M);\n }\n long long ans = 0;\n for (int i = 1; i <= h-a; i++) ans += C(i+b-2, i-1) * C(h+w-b-i-1, h-i) % M;\n cout << ans % M << endl;\n}\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": "p04040", "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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 153, "memory_kb": 9828}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s598831781", "group_id": "codeNet:p04045", "input_text": "(let* ((n (read))\n (m (read))\n (lst (loop :repeat m :collect (read))))\n (defun f (k) (if (loop :for x :in (int-to-list k) :never (find x lst))\n (princ k)\n (f (1+ k))))\n (f n))", "language": "Lisp", "metadata": {"date": 1560794221, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04045.html", "problem_id": "p04045", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04045/input.txt", "sample_output_relpath": "derived/input_output/data/p04045/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04045/Lisp/s598831781.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Runtime Error", "submission_id": "s598831781", "user_id": "u610490393"}, "prompt_components": {"gold_output": "2000\n", "input_to_evaluate": "(let* ((n (read))\n (m (read))\n (lst (loop :repeat m :collect (read))))\n (defun f (k) (if (loop :for x :in (int-to-list k) :never (find x lst))\n (princ k)\n (f (1+ k))))\n (f n))", "problem_context": "Score : 300 points\n\nProblem Statement\n\nIroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.\n\nShe is shopping, and now paying at the cashier.\nHer total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).\n\nHowever, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.\n\nFind the amount of money that she will hand to the cashier.\n\nConstraints\n\n1 ≦ N < 10000\n\n1 ≦ K < 10\n\n0 ≦ D_1 < D_2 < … < D_K≦9\n\n\\{D_1,D_2,...,D_K\\} ≠ \\{1,2,3,4,5,6,7,8,9\\}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K\nD_1 D_2 … D_K\n\nOutput\n\nPrint the amount of money that Iroha will hand to the cashier.\n\nSample Input 1\n\n1000 8\n1 3 4 5 6 7 8 9\n\nSample Output 1\n\n2000\n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.\n\nSample Input 2\n\n9999 1\n0\n\nSample Output 2\n\n9999", "sample_input": "1000 8\n1 3 4 5 6 7 8 9\n"}, "reference_outputs": ["2000\n"], "source_document_id": "p04045", "source_text": "Score : 300 points\n\nProblem Statement\n\nIroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.\n\nShe is shopping, and now paying at the cashier.\nHer total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).\n\nHowever, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.\n\nFind the amount of money that she will hand to the cashier.\n\nConstraints\n\n1 ≦ N < 10000\n\n1 ≦ K < 10\n\n0 ≦ D_1 < D_2 < … < D_K≦9\n\n\\{D_1,D_2,...,D_K\\} ≠ \\{1,2,3,4,5,6,7,8,9\\}\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN K\nD_1 D_2 … D_K\n\nOutput\n\nPrint the amount of money that Iroha will hand to the cashier.\n\nSample Input 1\n\n1000 8\n1 3 4 5 6 7 8 9\n\nSample Output 1\n\n2000\n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.\n\nSample Input 2\n\n9999 1\n0\n\nSample Output 2\n\n9999", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported 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": 182, "memory_kb": 15460}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s525000900", "group_id": "codeNet:p04048", "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 (x (read)))\n (labels ((recur (x y)\n (dbg x y)\n (assert (>= x y))\n (multiple-value-bind (quot rem) (floor x y)\n (if (zerop rem)\n (- (* quot y 2) y)\n (+ (* quot y 2) (recur y rem))))))\n (let ((l (- n x))\n (r x))\n (println\n (+ l r (recur (max l r) (min 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 (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 2\n\"\n \"12\n\")))\n", "language": "Lisp", "metadata": {"date": 1584860828, "filename_ext": "l", "original_language": "Common Lisp (SBCL 1.1.14)", "problem_description_relpath": "problem_descriptions/p04048.html", "problem_id": "p04048", "resource_group": "low_resource", "sample_input_relpath": "derived/input_output/data/p04048/input.txt", "sample_output_relpath": "derived/input_output/data/p04048/output.txt", "source_dataset": "Project CodeNet", "source_relpath": "data/p04048/Lisp/s525000900.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s525000900", "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 ;; 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 (labels ((recur (x y)\n (dbg x y)\n (assert (>= x y))\n (multiple-value-bind (quot rem) (floor x y)\n (if (zerop rem)\n (- (* quot y 2) y)\n (+ (* quot y 2) (recur y rem))))))\n (let ((l (- n x))\n (r x))\n (println\n (+ l r (recur (max l r) (min 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 (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 2\n\"\n \"12\n\")))\n", "problem_context": "Score : 500 points\n\nProblem Statement\n\nSnuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light.\n\nThree mirrors of length N are set so that they form an equilateral triangle.\nLet the vertices of the triangle be a, b and c.\n\nInside the triangle, the rifle is placed at the point p on segment ab such that ap = X.\n(The size of the rifle is negligible.)\nNow, the rifle is about to fire a ray of Mysterious Light in the direction of bc.\n\nThe ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as \"ordinary\" light.\nThere is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!\nWhen the ray comes back to the rifle, the ray will be absorbed.\n\nThe following image shows the ray's trajectory where N = 5 and X = 2.\n\nIt can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X.\nFind the total length of the ray's trajectory.\n\nConstraints\n\n2≦N≦10^{12}\n\n1≦X≦N-1\n\nN and X are integers.\n\nPartial Points\n\n300 points will be awarded for passing the test set satisfying N≦1000.\n\nAnother 200 points will be awarded for passing the test set without additional constraints.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN X\n\nOutput\n\nPrint the total length of the ray's trajectory.\n\nSample Input 1\n\n5 2\n\nSample Output 1\n\n12\n\nRefer to the image in the Problem Statement section.\nThe total length of the trajectory is 2+3+2+2+1+1+1 = 12.", "sample_input": "5 2\n"}, "reference_outputs": ["12\n"], "source_document_id": "p04048", "source_text": "Score : 500 points\n\nProblem Statement\n\nSnuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light.\n\nThree mirrors of length N are set so that they form an equilateral triangle.\nLet the vertices of the triangle be a, b and c.\n\nInside the triangle, the rifle is placed at the point p on segment ab such that ap = X.\n(The size of the rifle is negligible.)\nNow, the rifle is about to fire a ray of Mysterious Light in the direction of bc.\n\nThe ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as \"ordinary\" light.\nThere is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!\nWhen the ray comes back to the rifle, the ray will be absorbed.\n\nThe following image shows the ray's trajectory where N = 5 and X = 2.\n\nIt can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X.\nFind the total length of the ray's trajectory.\n\nConstraints\n\n2≦N≦10^{12}\n\n1≦X≦N-1\n\nN and X are integers.\n\nPartial Points\n\n300 points will be awarded for passing the test set satisfying N≦1000.\n\nAnother 200 points will be awarded for passing the test set without additional constraints.\n\nInput\n\nThe input is given from Standard Input in the following format:\n\nN X\n\nOutput\n\nPrint the total length of the ray's trajectory.\n\nSample Input 1\n\n5 2\n\nSample Output 1\n\n12\n\nRefer to the image in the Problem Statement section.\nThe total length of the trajectory is 2+3+2+2+1+1+1 = 12.", "split": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 3881, "cpu_time_ms": 44, "memory_kb": 9700}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s728375024", "group_id": "codeNet:p04049", "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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (k/2 (floor k 2))\n (res 0)\n (graph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint32 n k res))\n (dotimes (i (- n 1))\n (let ((a (- (read) 1))\n (b (- (read) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v parent depth max)\n (declare (int32 v parent depth max))\n (let ((res 1))\n (declare (uint32 res))\n (unless (= depth max)\n (dolist (child (aref graph v))\n (unless (= (the uint32 child) parent)\n (incf res (dfs child v (+ depth 1) max)))))\n res)))\n (if (evenp k)\n (dotimes (root n)\n (maxf res (dfs root -1 0 k/2)))\n (dotimes (root1 n)\n (dolist (root2 (aref graph root1))\n (when (< root1 root2)\n (maxf res (+ (dfs root1 root2 0 k/2)\n (dfs root2 root1 0 k/2))))))))\n (println (- 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 \"6 2\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 5\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1584877742, "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/s728375024.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s728375024", "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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (k/2 (floor k 2))\n (res 0)\n (graph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint32 n k res))\n (dotimes (i (- n 1))\n (let ((a (- (read) 1))\n (b (- (read) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v parent depth max)\n (declare (int32 v parent depth max))\n (let ((res 1))\n (declare (uint32 res))\n (unless (= depth max)\n (dolist (child (aref graph v))\n (unless (= (the uint32 child) parent)\n (incf res (dfs child v (+ depth 1) max)))))\n res)))\n (if (evenp k)\n (dotimes (root n)\n (maxf res (dfs root -1 0 k/2)))\n (dotimes (root1 n)\n (dolist (root2 (aref graph root1))\n (when (< root1 root2)\n (maxf res (+ (dfs root1 root2 0 k/2)\n (dfs root2 root1 0 k/2))))))))\n (println (- 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 \"6 2\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 5\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"0\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4884, "cpu_time_ms": 138, "memory_kb": 18920}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s781649958", "group_id": "codeNet:p04049", "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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (k/2 (floor k 2))\n (res 0)\n (graph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint32 n k res))\n (dotimes (i (- n 1))\n (let ((a (- (read) 1))\n (b (- (read) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v parent depth max)\n (declare (int32 v parent depth max))\n (let ((res 1))\n (declare (uint32 res))\n (unless (= depth max)\n (dolist (child (aref graph v))\n (unless (= (the uint32 child) parent)\n (incf res (dfs child v (+ depth 1) max)))))\n res)))\n (if (evenp k)\n (dotimes (root n)\n (maxf res (dfs root -1 0 k/2)))\n (dotimes (root1 n)\n (dolist (root2 (aref graph root1))\n (maxf res (+ (dfs root1 root2 0 k/2)\n (dfs root2 root1 0 k/2)))))))\n (println (- 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 \"6 2\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 5\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1584877703, "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/s781649958.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s781649958", "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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (k/2 (floor k 2))\n (res 0)\n (graph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint32 n k res))\n (dotimes (i (- n 1))\n (let ((a (- (read) 1))\n (b (- (read) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v parent depth max)\n (declare (int32 v parent depth max))\n (let ((res 1))\n (declare (uint32 res))\n (unless (= depth max)\n (dolist (child (aref graph v))\n (unless (= (the uint32 child) parent)\n (incf res (dfs child v (+ depth 1) max)))))\n res)))\n (if (evenp k)\n (dotimes (root n)\n (maxf res (dfs root -1 0 k/2)))\n (dotimes (root1 n)\n (dolist (root2 (aref graph root1))\n (maxf res (+ (dfs root1 root2 0 k/2)\n (dfs root2 root1 0 k/2)))))))\n (println (- 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 \"6 2\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 5\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"0\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4843, "cpu_time_ms": 308, "memory_kb": 31204}, "variant": "low_resource"} {"dataset": "codeNet", "domain": "code_generation", "example_id": "codeNet:Lisp:s121209435", "group_id": "codeNet:p04049", "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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (k/2 (floor k 2))\n (res 0)\n (graph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint32 n k res))\n (dotimes (i (- n 1))\n (let ((a (- (read) 1))\n (b (- (read) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v parent depth max)\n (declare (int32 v parent depth max))\n (let ((res 1))\n (declare (uint32 res))\n (unless (= depth max)\n (dolist (child (aref graph v))\n (unless (= child parent)\n (incf res (dfs child v (+ depth 1) max)))))\n res)))\n (if (evenp k)\n (dotimes (root n)\n (maxf res (dfs root -1 0 k/2)))\n (dotimes (root1 n)\n (dolist (root2 (aref graph root1))\n (maxf res (+ (dfs root1 root2 0 k/2)\n (dfs root2 root1 0 k/2)))))))\n (println (- 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 \"6 2\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 5\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"0\n\")))\n", "language": "Lisp", "metadata": {"date": 1584877635, "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/s121209435.l", "split_policy": "Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.", "status": "Accepted", "submission_id": "s121209435", "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(defun main ()\n (declare #.OPT)\n (let* ((n (read))\n (k (read))\n (k/2 (floor k 2))\n (res 0)\n (graph (make-array n :element-type 'list :initial-element nil)))\n (declare (uint32 n k res))\n (dotimes (i (- n 1))\n (let ((a (- (read) 1))\n (b (- (read) 1)))\n (push a (aref graph b))\n (push b (aref graph a))))\n (labels ((dfs (v parent depth max)\n (declare (int32 v parent depth max))\n (let ((res 1))\n (declare (uint32 res))\n (unless (= depth max)\n (dolist (child (aref graph v))\n (unless (= child parent)\n (incf res (dfs child v (+ depth 1) max)))))\n res)))\n (if (evenp k)\n (dotimes (root n)\n (maxf res (dfs root -1 0 k/2)))\n (dotimes (root1 n)\n (dolist (root2 (aref graph root1))\n (maxf res (+ (dfs root1 root2 0 k/2)\n (dfs root2 root1 0 k/2)))))))\n (println (- 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 \"6 2\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"2\n\"))\n (it.bese.fiveam:is\n (common-lisp-user::io-equal \"6 5\n1 2\n3 2\n4 2\n1 6\n5 6\n\"\n \"0\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": "validation", "target_descriptions": {"code_size_bytes": "Submitted source-code file size, in bytes.", "cpu_time_ms": "Execution CPU time reported by official Project CodeNet metadata, in milliseconds.", "memory_kb": "Peak memory usage reported by official Project CodeNet metadata, in kilobytes."}, "targets": {"code_size_bytes": 4830, "cpu_time_ms": 323, "memory_kb": 33376}, "variant": "low_resource"}