import Data.List (inits, maximumBy)
import Data.Maybe (fromMaybe)

repstring :: String -> Maybe String

repstring [] = Nothing

repstring [_] = Nothing
repstring xs
  | any (`notElem` "01") xs = Nothing
  | otherwise = longest xs
  where
    
    lxs = length xs
    
    lq2 = lxs `quot` 2
    
    
    subrepeat x = (x, take lxs $ concat $ repeat x)
    
    sndValid (_, ys) = ys == xs
    
    
    possible = map subrepeat . take lq2 . tail . inits
    
    
    valid = map fst . filter sndValid . possible
    
    compLength a b = compare (length a) (length b)
    
    
    longest ys = case valid ys of
      [] -> Nothing
      zs -> Just $ maximumBy compLength zs

main :: IO ()
main =
  mapM_ processIO examples
  where
    examples =
      [ "1001110011",
        "1110111011",
        "0010010010",
        "1010101010",
        "1111111111",
        "0100101101",
        "0100100",
        "101",
        "11",
        "00",
        "1"
      ]
    process = fromMaybe "Not a rep string" . repstring
    processIO xs = do
      putStr (xs <> ": ")
      putStrLn $ process xs