   (:require
    [clojure.string :as str]))
 
-(defn binary-search [_ _]
-  1)
+(defn binary-search [value items]
+  (loop [begin 0
+         end (-> (count items)
+                 (dec))]
+    (let [middle (-> (+ begin end)
+                     (quot 2))]
+      (if  (> begin end)
+        -1
+        (cond
+          (< (items middle) value)
+          (recur (inc middle)
+                 end)
 
-;; (defn binary-search [value items]
-;;   (loop [begin 0
-;;          end (-> (count items)
-;;                  (dec))
-;;          middle (-> (+ begin end)
-;;                     (quot 2))]
-;;     (if  (> begin end)
-;;       -1
-;;       (cond
-;;         (< (items middle) value)
-;;         (recur (inc middle)
-;;                end
-;;                (-> (+ begin end)
-;;                    (quot 2)))
+          (or (> (items middle) value)
+              (and (> middle 0)
+                   (== (items (dec middle)) value)))
+          (recur begin
+                 (dec middle))
 
-;;         (or (> (items middle) value)
-;;             (and (> middle 0)
-;;                  (== (items (dec middle)) value)))
-;;         (recur
-;;          begin
-;;          (dec middle)
-;;          (-> (+ begin end)
-;;              (quot 2)))
-
-;;         :else
-;;         (inc middle)))))
+          :default
+          (inc middle))))))
 
 (defn read-values [total]
   (loop [reverse-index total

    (let [[n q] (->> (str/split line #" ")
                     (map #(Integer/parseInt %)))
          marbles (sort (read-values n))
          all-queries (reverse (read-values q))]
      (when (and (not= n 0) (not= q 0))
        (process-and-print index marbles all-queries)
        (recur (read-line) (inc index))))))

(main)

    (if (== reverse-index 0)
      vals
      (recur (dec reverse-index)
             (concat vals [(Integer/parseInt (read-line))])))))


(defn process-print [index marbles queries]
  (printf "CASE# %d:%n" index)
  (loop [queries queries]
    (let [query (first queries)
          position (binary-search query marbles)]
      (if (>= position 0)
