type Binary = String

main = interact $ unlines.map (readNumLine.concat.map (toBin code_charTable)).lines

toBin :: [(Char,String)] -> Char -> String
toBin list char = case lookup char list of
                    Just b -> b
                    Nothing -> ""

readNumLine :: String -> String
readNumLine (x:xs) = rnl [x] xs

rnl _   []   = []
rnl acc line = case lookup acc char_codeTable of
                 Just c -> c:readNumLine line
                 Nothing -> rnl (acc++[head line]) $ tail line

bin2dec :: Binary -> Int
bin2dec = foldl (\x y -> 2*x +y) 0.map (\x -> read [x])

dec2bin :: Int -> Binary
dec2bin = concat.map show.reverse.i2b
    where i2b 0 = []
          i2b n = mod n 2: i2b (div n 2)

showBin :: Int -> Binary -> String
showBin d n = if length n <= d then replicate (d- length n) '0' ++ n
                               else n

charTable = ['A','B'..'Z'] ++ [' ','.',',','-','\'','?']
codeTable = map (showBin 5.dec2bin) $ [0..31]
code_charTable = zip charTable codeTable
char_codeTable = [("101",' '),("000000",'\''),("000011",','),("10010001",'-')
                 ,("010001",'.'),("000001",'?'),("100101",'A'),("10011010",'B')
                 ,("0101",'C'),("0001",'D'),("110",'E'),("01001",'F'),("10011011",'G')
                 ,("010000",'H'),("0111",'I'),("10011000",'J'),("0110",'K'),("00100",'L')
                 ,("10011001",'M'),("10011110",'N'),("00101",'O'),("111",'P')
                 ,("10011111",'Q'),("1000",'R'),("00110",'S'),("00111",'T'),("10011100",'U')
                 ,("10011101",'V'),("000010",'W'),("10010010",'X'),("10010011",'Y'),("10010000",'Z')]