(defn patterns
  [s]
  (let [s-len (count s)]
    (loop [n 1, acc []]
      (if (> n (/ s-len 2))
        (if (empty? acc)
          0
          (apply max acc))
        (let [pattern (take n s)
              pattern-cycle (cycle pattern)]
          (if (= (take s-len pattern-cycle) s)
            (do
              (recur (inc n)
                     (cons s-len acc)))
            (recur (inc n)
                   acc)))))))

(defn search-part-s
  [s]
  (loop [part-s (seq s), acc []]
    (if-not (> (count part-s) 0)
      (apply max acc)
      (let [maxlen (patterns part-s)]
        (recur (butlast part-s)
               (cons maxlen acc))))))

(let [args (-> (line-seq (java.io.BufferedReader. *in*))
               first
               butlast)]
  (println (search-part-s args)))
