(require '[clojure.string :as str])

(defn getCharIdx [s c sidx]
  (if (nil? sidx) nil
      (str/index-of s c sidx)))

(defn inc2 [a]
  (if (nil? a) nil
      (inc a)))

(defn luckyPin2 [n s]
  (->>
   (for [i (range 1000)
         :let [a (format "%03d" i)
               a0 (get a 0)
               a1 (get a 1)
               a2 (get a 2)]
          :when (some? 
                 (getCharIdx s a2
                              (inc2 (getCharIdx s a1
                                              (inc2 (getCharIdx s a0 0))))))
         ]
     a)
   (count)
   ))

(println (luckyPin2 (read-line) (read-line)))
