import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
-- templete

b 'A' = [0,0,0,0,0]
b 'B' = [0,0,0,0,1]
b 'C' = [0,0,0,1,0]
b 'D' = [0,0,0,1,1]
b 'E' = [0,0,1,0,0]
b 'F' = [0,0,1,0,1]
b 'G' = [0,0,1,1,0]
b 'H' = [0,0,1,1,1]
b 'I' = [0,1,0,0,0]
b 'J' = [0,1,0,0,1]
b 'K' = [0,1,0,1,0]
b 'L' = [0,1,0,1,1]
b 'M' = [0,1,1,0,0]
b 'N' = [0,1,1,0,1]
b 'O' = [0,1,1,1,0]
b 'P' = [0,1,1,1,1]
b 'Q' = [1,0,0,0,0]
b 'R' = [1,0,0,0,1]
b 'S' = [1,0,0,1,0]
b 'T' = [1,0,0,1,1]
b 'U' = [1,0,1,0,0]
b 'V' = [1,0,1,0,1]
b 'W' = [1,0,1,1,0]
b 'X' = [1,0,1,1,1]
b 'Y' = [1,1,0,0,0]
b 'Z' = [1,1,0,0,1]
b ' ' = [1,1,0,1,0]
b '.' = [1,1,0,1,1]
b ',' = [1,1,1,0,0]
b '-' = [1,1,1,0,1]
b '\'' =[1,1,1,1,0]
b '?' = [1,1,1,1,1]
toBin s = concat $ map b s

d (1:0:1:s) = ' ' : d s
d (0:0:0:0:0:0:s) = '\'' : d s
d (0:0:0:0:1:1:s) = ',' : d s
d (1:0:0:1:0:0:0:1:s) = '-' : d s
d (0:1:0:0:0:1:s) = '.' : d s
d (0:0:0:0:0:1:s) = '?' : d s
d (1:0:0:1:0:1:s) = 'A' : d s
d (1:0:0:1:1:0:1:0:s) = 'B' : d s
d (0:1:0:1:s) = 'C' : d s
d (0:0:0:1:s) = 'D' : d s
d (1:1:0:s) = 'E' : d s
d (0:1:0:0:1:s) = 'F' : d s
d (1:0:0:1:1:0:1:1:s) = 'G' : d s
d (0:1:0:0:0:0:s) = 'H' : d s
d (0:1:1:1:s) = 'I' : d s
d (1:0:0:1:1:0:0:0:s) = 'J' : d s
d (0:1:1:0:s) = 'K' : d s
d (0:0:1:0:0:s) = 'L' : d s
d (1:0:0:1:1:0:0:1:s) = 'M' : d s
d (1:0:0:1:1:1:1:0:s) = 'N' : d s
d (0:0:1:0:1:s) = 'O' : d s
d (1:1:1:s) = 'P' : d s
d (1:0:0:1:1:1:1:1:s) = 'Q' : d s
d (1:0:0:0:s) = 'R' : d s
d (0:0:1:1:0:s) = 'S' : d s
d (0:0:1:1:1:s) = 'T' : d s
d (1:0:0:1:1:1:0:0:s) = 'U' : d s
d (1:0:0:1:1:1:0:1:s) = 'V' : d s
d (0:0:0:0:1:0:s) = 'W' : d s
d (1:0:0:1:0:0:1:0:s) = 'X' : d s
d (1:0:0:1:0:0:1:1:s) = 'Y' : d s
d (1:0:0:1:0:0:0:0:s) = 'Z' : d s
d _ = []

main = lines <$> getContents >>= mapM_ (putStrLn . d . toBin)


Measured memory_bytes: 4188