about summary refs log tree commit diff
path: root/codechef/qabc.lisp
blob: 7c9619b90d507b170202630517206aff46561e0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(defun read-list (str)
  (read-from-string (concatenate 'string "(" str ")")))

(defun qabc (seq n &optional (a1 0) (a2 0))
  (if (< n 3)
      (if (every #'zerop (mapcar #'- (list a1 a2) seq)) "TAK" "NIE")
      (let ((a0 (- (first seq) a1)))
        (if (< a0 0)
            "NIE"
            (qabc (rest seq) (1- n) (+ a2 (* a0 2)) (* a0 3))))))

(let ((tests (read)))
  (dotimes (i tests)
    (let* ((n (read))
           (a (read-list (read-line)))
           (b (read-list (read-line))))
      (princ (qabc (mapcar #'- b a) n))
      (fresh-line))))