(defun vector-append (vec1 vec2) (let ((len1 (length vec1)) (len2 (length vec2))) (let ((result (make-array (+ len1 len2) :element-type (array-element-type vec1)))) (dotimes (i len1) (setf (aref result i) (aref vec1 i))) (dotimes (i len2) (setf (aref result (+ i len1)) (aref vec2 i))) result))) (defun combinations (vec k) (if (= k 0) (vector) (when (not (zerop (length vec))) (let ((first (aref vec 0)) (rest (subseq vec 1))) (let ((with-first (mapcar (lambda (x) (vector first x)) (combinations rest (1- k))))) (vector-append with-first (combinations rest k))))))) (defun main (&rest argv) (declare (ignorable argv)) (let* ((n (read)) (k (read)) (a (make-array n)) (res 0) (m1 998) (m2 998244353)) (dotimes (i n) (setf (aref a i) (read))) (loop for i across (combinations a k) with s = (reduce #'+ i) when (>= (mod s m1) (mod s m2)) do (incf res)) (format t "~d~%" (mod res m1)))) (main)