letToCode :: Char -> String
letToCode ch = case ch of
                ' ' -> "101"
                '\''-> "000000"
                ',' -> "000011"
                '-' -> "10010001"
                '.' -> "010001"
                '?' -> "000001"
                'A' -> "100101"
                'B' -> "10011010"
                'C' -> "0101"
                'D' -> "0001"
                'E' -> "110"
                'F' -> "01001"
                'G' -> "10011011"
                'H' -> "010000"
                'I' -> "0111"
                'J' -> "10011000"
                'K' -> "0110"
                'L' -> "00100"
                'M' -> "10011001"
                'N' -> "10011110"
                'O' -> "00101"
                'P' -> "111"
                'Q' -> "10011111"
                'R' -> "1000"
                'S' -> "00110"
                'T' -> "00111"
                'U' -> "10011100"
                'V' -> "10011101"
                'W' -> "000010"
                'X' -> "10010010"
                'Y' -> "10010011"
                'Z' -> "10010000"

binToDec str = sum$zipWith(*)(iterate(*2)1)(map(\x->if x=='1' then 1 else 0)(reverse str))

codeToLet :: String -> Char
codeToLet bin = let dec = binToDec bin
                in case dec of
                    0 -> 'A'
                    1 -> 'B'
                    2 -> 'C'
                    3 -> 'D'
                    4 -> 'E'
                    5 -> 'F'
                    6 -> 'G'
                    7 -> 'H'
                    8 -> 'I'
                    9 -> 'J'
                    10 -> 'K'
                    11 -> 'L'
                    12 -> 'M'
                    13 -> 'N'
                    14 -> 'O'
                    15 -> 'P'
                    16 -> 'Q'
                    17 -> 'R'
                    18 -> 'S'
                    19 -> 'T'
                    20 -> 'U'
                    21 -> 'V'
                    22 -> 'W'
                    23 -> 'X'
                    24 -> 'Y'
                    25 -> 'Z'
                    26 -> ' '
                    27 -> '.'
                    28 -> ','
                    29 -> '-'
                    30 -> '\''
                    31 -> '?'

splitAtN _ []  = []
splitAtN n str = fst(splitAt n str) : (splitAtN n (snd(splitAt n str)))

strAddZero str = let len = length str
                 in if len`mod`5==0 then str else str ++ (replicate (5-len`mod`5) '0')


main = do{
    getContents>>=mapM_ putStrLn.map((map codeToLet).splitAtN 5.strAddZero.(foldr(++)"").(map letToCode)).lines;
}