Problem:


博士が愛した符号

博士 : ピーター君、ついにやったよ。

ピーター : どうしました、デビッド博士？またくだらない発明ですか？

博士 : この表だよ、この表。

文字符号

（空白）101

'000000

,000011

-10010001

.010001

?000001

A100101

B10011010

文字符号

 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

ピーター : なんですか? この表は。

博士 : いいから、言う通りにしてみなさい。まず、お前の名前を紙に書いてごらん。

ピーター : はい"PETER POTTER" っと。

博士 : そうしたら、１文字ずつ、この表の「符号」に置き換えるのだよ。

ピーター : えーと"P" を「111」にして"E" を「110」して…結構面倒ですね。

111 110 00111 110 1000 101 111 00101 00111 00111 110 1000

           になりました。なんだか、バーコードみたいですね。

博士 : よろしい。そうしたら、置き換えた文字列を全部つなげて、５文字ごとに区切ってみなさい。

ピーター : はいはい、つなげて区切ると。

11111 00011 11101 00010 11110 01010 01110 01111 10100 0

           こんな感じになりました。けど、最後の「0」だけのやつはどうしますか?

博士 : ０を付け加えて５文字にしておいてくれ。

ピーター : えーと最後が０が1個だけだから０をあと４つ加えてやればいいんですね。できました。

11111 00011 11101 00010 11110 01010 01110 01111 10100 00000

博士 : 次はこの表を使うのだ。

符号文字

 00000 A

 00001 B

 00010 C

 00011 D

 00100 E

 00101 F

 00110 G

 00111 H

符号文字

 01000 I

 01001 J

 01010 K

 01011 L

 01100 M

 01101 N

 01110 O

 01111 P

符号文字

 10000 Q

 10001 R

 10010 S

 10011 T

 10100 U

 10101 V

 10110 W

 10111 X

符号文字

 11000 Y

 11001 Z

 11010 （空白）

 11011 .

 11100 ,

 11101 -

 11110 '

 11111 ?

ピーター : これをどう使うんですか…そうか!今度は符号から文字に置き換えるのか!

博士 : そうそう。「11111」だったら「?」に、「00011」だったら「D」にとやってゆけばいいんだよ。

ピーター : これは単純ですね……えーと「?D-C'KOPUA」になりました。でも意味不明ですよ。

博士 : 文字数を数えてごらん。

ピーター : １０文字ですよ。あっ、「PETER POTTER」は１２文字だったのに２文字減っています。

博士 : そう、この表を使えば文字を減らすことができるのだよ。じゃあ今度はこの文章で同じことをやっ
       てごらん。

PETER PIPER PICKED A PECK OF PICKLED PEPPERS. A PECK OF PICKLED PEPPERS
PETER PIPER PICKED. IF PETER PIPER PICKED A PECK OF PICKLED PEPPERS, WHERE'S
THE PECK OF PICKLED PEPPERS PETER PIPER PICKED?

ピーター : ぎょぎょ、行が分かれていますが、どうするんですか?

博士 : 紙の都合で３行になってしまったが、改行文字のかわりに空白がある長い１行だと思っておくれ。

ピーター : はいはい。行と行の間にあるのは空白だと。しかし面倒だな……。

博士 : だったらプログラムにやらせればいいではないか。

ということで、ピーターの代わりに、読み込んだ文字列を符号に変換し出力するプログラムを作成してください。

入力

複数のデータセットが与えられます。各データセットに文字列１行（表に含まれる文字からなる）が与えられます。文字列に含まれる文字の数は 1 文字以上 100 文字以下です。

データセットの数は 200 を超えません。

出力

各データセットごとに、変換後の文字列を１行に出力してください。

Sample Input

PETER POTTER

Output for the Sample Input

?D-C'KOPUA



Sample input:
PETER POTTER


Sample output:
?D-C'KOPUA

Submission status: Accepted

Solution code:
d1 = {" ":"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",}
d2 = {"00000":"A","00001":"B","00010":"C","00011":"D","00100":"E","00101":"F","00110":"G","00111":"H","01000":"I","01001":"J","01010":"K","01011":"L","01100":"M","01101":"N","01110":"O","01111":"P","10000":"Q","10001":"R","10010":"S","10011":"T","10100":"U","10101":"V","10110":"W","10111":"X","11000":"Y","11001":"Z","11010":" ","11011":".","11100":",","11101":"-","11110":"'","11111":"?"}

while True:
	try:
		c,dc = "",""
		inp = raw_input()
		for a in inp:
			c += d1[a]
		if len(c)%5 != 0:
			c += "0"*(5-len(c)%5)
		for i in range(0,len(c),5):
			dc += d2[c[i:i+5]]
		print dc
	except:
		break

Submission status: Accepted

Solution code:
encode = {
' ':'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'}

decode = {
"00000":"A",
"00001":"B",
"00010":"C",
"00011":"D",
"00100":"E",
"00101":"F",
"00110":"G",
"00111":"H",
"01000":"I",
"01001":"J",
"01010":"K",
"01011":"L",
"01100":"M",
"01101":"N",
"01110":"O",
"01111":"P",
"10000":"Q",
"10001":"R",
"10010":"S",
"10011":"T",
"10100":"U",
"10101":"V",
"10110":"W",
"10111":"X",
"11000":"Y",
"11001":"Z",
"11010":" ",
"11011":".",
"11100":",",
"11101":"-",
"11110":"'",
"11111":"?"}

while True:
	try:
		string = raw_input()
	except EOFError:
		break		

	e, ans = "", ""
	for s in string:
		e += encode[s]
	tmp = []
	while len(e) > 4:
		tmp.append(e[0:5])
		e = e[5:]
	if len(e) != 0:
		e += '0' * (5 - len(e))
		tmp.append(e)

	for s in tmp:
		ans += decode[s]
	print ans

Submission status: Accepted

Solution code:
import sys
A=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"
B="101 000000 000011 10010001 010001 000001 100101 10011010 "\
  "0101 0001 110 01001 10011011 010000 0111 10011000 "\
  "0110 00100 10011001 10011110 00101 111 10011111 1000 "\
  "00110 00111 10011100 10011101 000010 10010010 10010011 10010000".split()
C="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"
d1={}
for i in range(32):d1[A[i]]=B[i]
for s in sys.stdin:
  x=""
  for c in s[:-1]:x+=d1[c]
  x+="0"*(-len(x)%5)
  s=""
  for i in range(0,len(x),5):s+=C[int(x[i:i+5],2)]
  print s

Submission status: Accepted

Solution code:
import sys
L="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
A=" ',-.?"+L
B="101 000000 000011 10010001 010001 000001 100101 10011010 "\
  "0101 0001 110 01001 10011011 010000 0111 10011000 "\
  "0110 00100 10011001 10011110 00101 111 10011111 1000 "\
  "00110 00111 10011100 10011101 000010 10010010 10010011 10010000".split()
C=L+" .,-'?"
for s in sys.stdin:
  x=""
  for c in s[:-1]:x+=B[A.index(c)]
  x+="0"*(-len(x)%5)
  s=""
  for i in range(0,len(x),5):s+=C[int(x[i:i+5],2)]
  print s

Submission status: Accepted

Solution code:
chA = {' ':'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'}

chB = {'00000':'A', '00001':'B', '00010':'C', '00011':'D', '00100':'E', '00101':'F',
       '00110':'G', '00111':'H', '01000':'I', '01001':'J', '01010':'K', '01011':'L',
       '01100':'M', '01101':'N', '01110':'O', '01111':'P', '10000':'Q', '10001':'R',
       '10010':'S', '10011':'T', '10100':'U', '10101':'V', '10110':'W', '10111':'X',
       '11000':'Y', '11001':'Z', '11010':' ', '11011':'.', '11100':',', '11101':'-', '11110':"'", '11111':'?'}


while True:
    try:
        s = input()

    except EOFError:
        break
    
    chlst = ''
    numlst = []
    anslst = ''
    for i in s:
        if i == '\\':
            chlst = chlst + chA[' ']
        else:
            chlst = chlst + chA[i]

    if len(chlst)%5 != 0:
        for k in range(5-(len(chlst)%5)):
            chlst += '0'

    for j in range(len(chlst)//5):
        numlst.append(chlst[5*j: 5*j+5])

    for l in numlst:
        anslst = anslst + chB[l]

    print(anslst)

Submission status: Accepted

Solution code:
table1 = {" ":"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"}

table2 = {"00000":"A", "00001":"B", "00010":"C", "00011":"D", "00100":"E",
        "00101":"F", "00110":"G", "00111":"H", "01000":"I", "01001":"J",
        "01010":"K", "01011":"L", "01100":"M", "01101":"N", "01110":"O",
        "01111":"P", "10000":"Q", "10001":"R", "10010":"S", "10011":"T",
        "10100":"U", "10101":"V", "10110":"W", "10111":"X", "11000":"Y",
        "11001":"Z", "11010":" ", "11011":".", "11100":",", "11101":"-",
        "11110":"'", "11111":"?"}

def convert1(str):
  convert = ""
  for s in str:
    convert += table1[s]
  return convert

def convert2(str):
  convert = ""
  index = 0
  
  while index + 5 < len(str):
    convert += table2[str[index:index + 5]]
    index += 5
  # 末尾は0で埋めてある
  if str[index:]:
    convert += table2[str[index:] + "0" * (5 - len(str) + index)]
  
  return convert

while True:
  try:
    s = input()
    c1 = convert1(s)
    c2 = convert2(c1)
    print(c2)
  except:
    break

Submission status: Accepted

Solution code:
_encode={
    " ":"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"
}

def encode(c):
    return _encode[c]

def decode(s):
    num=0
    for i,c in enumerate(s):
        if c=="1":
            num+=2**(4-i)
    if num<26:
        return chr(ord('A')+num)
    elif num==26:
        return " "
    elif num==27:
        return "."
    elif num==28:
        return ","
    elif num==29:
        return "-"
    elif num==30:
        return "'"
    else:
        return "?"


while True:
    try:
        s=input()
        encoded=""
        for c in s:
            encoded+=encode(c)
        while(len(encoded)%5!=0):
            encoded+="0"
        decoded=""
        for i in range(len(encoded)//5):
            decoded+=decode(encoded[5*i:5*i+5])
        print(decoded)
    except EOFError:
        break

Submission status: Accepted

Solution code:

L = { " ": "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" }


M = { "00000": "A",
      "00001": "B",
      "00010": "C",
      "00011": "D",
      "00100": "E",
      "00101": "F",
      "00110": "G",
      "00111": "H",
      "01000": "I",
      "01001": "J",
      "01010": "K",
      "01011": "L",
      "01100": "M",
      "01101": "N",
      "01110": "O",
      "01111": "P",
      "10000": "Q",
      "10001": "R",
      "10010": "S",
      "10011": "T",
      "10100": "U",
      "10101": "V",
      "10110": "W",
      "10111": "X",
      "11000": "Y",
      "11001": "Z",
      "11010": " ",
      "11011": ".",
      "11100": ",",
      "11101": "-",
      "11110": "'",
      "11111": "?" }



while True:
    try:
        s = input()
    except:
        break

    t = ""
    for i in s:
        t += L[i]
    t += "0" * ( (-len(t))%5 )

    o = ""
    for i in range( len(t) // 5 ):
        u = t[i*5:i*5+5]
        o += M[u]
    print(o)

Submission status: Accepted

Solution code:
first_dict = {'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", ' ': "101", "'": "000000",
              ',': "000011", '-': "10010001", '.': "010001", '?': "000001"}
second_dict = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
               'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '.', ',', '-',
               "'", '?']
while 1:
    try:
        N = list(input())
        num = ""
        first = []
        for i in N: num += first_dict[i]
        if len(num) % 5 != 0:
            for i in range(5 - (len(num) % 5)):
                num += "0"
        count = 0
        number = ""
        for j in num:
            number += j
            count += 1
            if count == 5:
                number += " "
                count = 0
        key = number.split()
        answer = ""
        for k in key:
            pas = int(k[4]) * 1 + int(k[3]) * 2 + int(k[2]) * 4 + int(k[1]) * 8 + int(k[0]) * 16
            answer += second_dict[pas]
        print(answer)

    except:
        break

Submission status: Accepted

Solution code:
while 1:
    try:
        s=input()
        s_r=""
        c1=[" ","'",",","-",".","?","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
        c2=["101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"]
        c3=[" ",".",",","-","'","?"]
        for i in s:
            s_r+=c2[c1.index(i)]
        while len(s_r)%5>0:s_r+="0"
        ans=""
        for i in range(len(s_r)//5):
            s_r_n=int(s_r[:5],2)
            if s_r_n<26:
                ans+=chr(65+s_r_n)
            else:
                ans+=c3[s_r_n-26]
            s_r=s_r[5:]
        print(ans)
    except:break

Submission status: Accepted

Solution code:
signlist = ["101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010",
            "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000",
            "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000",
            "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011",
            "10010000"]

char = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"
charlist = list(char)
decode = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"
decodelist = list(decode)

while 1:
    try:
        sentence = input()
    except EOFError:
        break

    sentence = list(sentence)
    encode = ""
    for s in sentence:
        num = charlist.index(s)
        encode += signlist[num]

    tmp = len(encode) % 5
    if tmp != 0:
        encode += "0" * (5-tmp)

    encodelist = []
    for i in range(0, len(encode), 5):
        encodelist.append(encode[i:i+5])

    ans = ""
    for e in encodelist:
        dec_e = int(e, 2)
        ans += decodelist[dec_e]

    print(ans)

Submission status: Accepted

Solution code:
from itertools import chain
import sys

table1 = dict(zip(
    chain(" ',-.?", map(chr, range(65, 91))),
    "101 000000 000011 10010001 010001 000001 100101 10011010\
    0101 0001 110 01001 10011011 010000 0111 10011000\
    0110 00100 10011001 10011110 00101 111 10011111 1000\
    00110 00111 10011100 10011101 000010 10010010 10010011 10010000".split()
))
table2 = dict(enumerate(chain(map(chr, range(65, 91)), " .,-'?")))

for l in sys.stdin:
    code = "".join(table1[c] for c in l.rstrip("\n"))
    code += "0"*(5-(len(code)%5)) if len(code)%5 else ""
    print("".join(table2[int(code[i*5:(i+1)*5], 2)] for i in range(len(code)//5)))

Submission status: Runtime Error

Solution code:
class Code:
    def __init__(self): 
        True

        self.cd1 = {" ":"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"}
        self.cd2 = {"00000":"A","00001":"B","00010":"C","00011":"D","00100":"E","00101":"F","00110":"G","00111":"H","01000":"I","01001":"J","01010":"K","01011":"L","01100":"M","01101":"N","01110":"O","01111":"P","10000":"Q","10001":"R","10010":"S","10011":"T","10100":"U","10101":"V","10110":"W","10111":"X","11000":"Y","11001":"Z","11010":" ","11011":".","11100":",","11101":"-","11110":"'","11111":"?"}

    def code1(self,s):
        t0 = list(map(lambda x:self.cd1[x], s))
        t1 = ''.join(t0)
        t = list(t1)
        t0 = t
        u = []
        while len(t) > 0:
            u.append(t[0:5])
            t[0:5]=[]
            if len(u[-1]) != 5:
                u[-1] = (u[-1] + ['0']*4)[0:5]
                v = list(map(lambda x:''.join(x), u))
                return(v)

    def code2(self,s):
        t = []
        for i in s: 
            t.append(self.cd2[i])
        u = ''.join(t)
        return(u)

if __name__ == "__main__":
    cd = Code()
    while True:
        try:
            s = input().strip()
            t = cd.code1(s)
            u = cd.code2(t)
            print(u)

        except EOFError:
            break

Submission status: Runtime Error

Solution code:
class Code:
    def __init__(self): 
        self.cd1 = {" ":"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"}
        self.cd2 = {"00000":"A","00001":"B","00010":"C","00011":"D","00100":"E","00101":"F","00110":"G","00111":"H","01000":"I","01001":"J","01010":"K","01011":"L","01100":"M","01101":"N","01110":"O","01111":"P","10000":"Q","10001":"R","10010":"S","10011":"T","10100":"U","10101":"V","10110":"W","10111":"X","11000":"Y","11001":"Z","11010":" ","11011":".","11100":",","11101":"-","11110":"'","11111":"?"}

    def code1(self,s):
        t0 = list(map(lambda x:self.cd1[x], s))
        t1 = ''.join(t0)
        t = list(t1)
        t0 = t
        u = []
        while len(t) > 0:
            u.append(t[0:5])
            t[0:5]=[]
            if len(u[-1]) != 5:
                u[-1] = (u[-1] + ['0']*4)[0:5]
                v = list(map(lambda x:''.join(x), u))
                return(v)

    def code2(self,s):
        t = []
        for i in s: 
            t.append(self.cd2[i])
        u = ''.join(t)
        return(u)

if __name__ == "__main__":
    cd = Code()
    while True:
        try:
            s = input().strip()
            t = cd.code1(s)
            u = cd.code2(t)
            print(u)

        except EOFError:
            break

Submission status: Runtime Error

Solution code:
a='101'.join(''.join(d[c]for c in e.strip())for e in sys.stdin)
l=len(a)+4
b=a.ljust(l//5*5,'0')
print(''.join("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[int(b[i:i+5],2)]for i in range(0,l,5)))

Submission status: Runtime Error

Solution code:
import sys
d={' ':'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'}

a='101'.join(''.join(d[c]for c in e.strip())for e in sys.stdin)
l=len(a)+4
b=a.ljust(l//5*5,'0')
print(''.join("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[int(b[i:i+5],2)]for i in range(0,l,5)))

Submission status: Runtime Error

Solution code:
import sys
d={' ':'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'}

a='101'.join(''.join(d[c]for c in e.strip())for e in sys.stdin)
l=len(a)+4
b=a.ljust(l//5*5,'0')
print(''.join("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[int(b[i:i+5],2)]for i in range(0,l,5)))

Submission status: Runtime Error

Solution code:
import sys
d={' ':'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'}
for e in sys.stdin:
 a=''.join(d[c]for c in e.strip())
 l=len(a)+4
 b=a.ljust(l//5*5,'0')
 print(''.join("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[int(b[i:i+5],2)]for i in range(0,l,5)))

Submission status: Runtime Error

Solution code:
import sys
d={' ':'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'}
for e in sys.stdin:
 a=''.join(d[c]for c in e.strip())
 l=len(a)+4
 #b=a.ljust(l//5*5,'0')
 b=a+'0'*(-len(a)%5)
 print(''.join("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[int(b[i:i+5],2)]for i in range(0,l,5)))

Submission status: Runtime Error

Solution code:
import sys
d={' ':'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'}
for e in sys.stdin:
 a=''.join(d[c]for c in e.strip())
 b=a+'0'*(-len(a)%5)
 print(''.join("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[int(b[i:i+5],2)]for i in range(0,len(a)+4,5)))

Submission status: Runtime Error

Solution code:
dic1 = {" ":"101", "'":"000000", ",":"000011", "-":"10010001", "?":"000001",
        "A":"100101", "B":"10011010", "C":"0101", "D":"0101", "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"}

dic2 = {"00000":"A", "00001":"B", "00010":"C", "00011":"D", "00100":"E",
        "00101":"F", "00110":"G", "00111":"H", "01000":"I", "01001":"J",
        "01010":"K", "01011":"L", "01100":"M", "01101":"N", "01110":"O",
        "01111":"P", "10000":"Q", "10001":"R", "10010":"S", "10011":"T",
        "10100":"U", "10101":"V", "10110":"W", "10111":"X", "11000":"Y",
        "11001":"Z", "11010":" ", "11011":".", "11100":",", "11101":"-",
        "11110":"'", "11111":"?"}

def to_digit(ss):
  ret = ""
  for s in ss:
    ret += dic1[s]
  return ret

def to_alpha(digit):
  ret = ""
  ind = 0
  end = len(digit)

  while ind + 5 < end:
    ret += dic2[digit[ind:ind + 5]]
    ind += 5

  if digit[ind:]:
    ret += dic2[digit[ind:] + "0" * (5 - end + ind)]

  return ret

while True:
  try:
    ss = input()
    print(to_alpha(to_digit(ss)))
  except EOFError:
    break

Submission status: Runtime Error

Solution code:
dic1 = {" ":"101", "'":"000000", ",":"000011", "-":"10010001", "?":"000001",
        "A":"100101", "B":"10011010", "C":"0101", "D":"0101", "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"}

dic2 = {"00000":"A", "00001":"B", "00010":"C", "00011":"D", "00100":"E",
        "00101":"F", "00110":"G", "00111":"H", "01000":"I", "01001":"J",
        "01010":"K", "01011":"L", "01100":"M", "01101":"N", "01110":"O",
        "01111":"P", "10000":"Q", "10001":"R", "10010":"S", "10011":"T",
        "10100":"U", "10101":"V", "10110":"W", "10111":"X", "11000":"Y",
        "11001":"Z", "11010":" ", "11011":".", "11100":",", "11101":"-",
        "11110":"'", "11111":"?"}

def to_digit(ss):
  ret = ""
  for s in ss:
    ret += dic1[s]
  return ret

def to_alpha(digit):
  ret = ""
  ind = 0
  end = len(digit)

  while ind + 5 < end:
    ret += dic2[digit[ind:ind + 5]]
    ind += 5

  if digit[ind:]:
    ret += dic2[digit[ind:] + "0" * (5 - end + ind)]

  return ret

print(to_alpha(to_digit(input())))

Submission status: Runtime Error

Solution code:
d1={
" ":"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"}
d2={
"00000":"A",
"00001":"B",
"00010":"C",
"00011":"D",
"00100":"E",
"00101":"F",
"00110":"G",
"00111":"H",
"01000":"I",
"01001":"J",
"01010":"K",
"01011":"L",
"01100":"M",
"01101":"N",
"01110":"O",
"01111":"P",
"10000":"Q",
"10001":"R",
"10010":"S",
"10011":"T",
"10100":"U",
"10101":"V",
"10110":"W",
"10111":"X",
"11000":"Y",
"11001":"Z",
"11010":" ",
"11011":".",
"11100":",",
"11101":"-",
"11110":"'",
"11111":"?"}
while 1:
    s=raw_input()
    s1,ans="",""
    for w in s:
        s1+=d1[w]
    s1+="0"*(5-len(s1)%5)
    for i in range(len(s1)/5):
        ans+=d2[s1[:5]]
        s1=s1[5:]
    print ans

Submission status: Runtime Error

Solution code:
encode = {' ':'101', '\'':'000000', ',':'000011', '-':'1001000', '.':'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', 'X':'10010000'}
decode = {'00000':'A', '00001':'B', '00010':'C', '00011':'D', '00100':'E','00101':'F','00110':'G','00111':'H','01000':'I','01001':'J','01010':'K','01011':'L','01100':'M','01101':'N','01110':'O','01111':'P','10000':'Q','10001':'R','10010':'S','10011':'T','10100':'U','10101':'V','10110':'W','10111':'X','11000':'Y','11001':'Z','11010':' ','11011':'.','11100':',','11101':'-','11110':'\'','11111':'?'}

while True:
	try:
		string = list(raw_input())
		
		# encode
		code = ""
		for s in string:
			code += encode[s]
		i = 0
		tmp = []
		while i+5 <= len(code):
			tmp.append(code[i:i+5])
			code = code[i+5:]
		if len(code) != 0:
			code += '0' * (5 - len(code))
			tmp.append(code)

		# decode
		ans = ""
		for s in tmp:
			ans += decode[s]
		print ans
	except EOFError:
		break

Submission status: Runtime Error

Solution code:
encode = {' ':'101', '\'':'000000', ',':'000011', '-':'1001000', '.':'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', 'X':'10010000'}
decode = {'00000':'A', '00001':'B', '00010':'C', '00011':'D', '00100':'E','00101':'F','00110':'G','00111':'H','01000':'I','01001':'J','01010':'K','01011':'L','01100':'M','01101':'N','01110':'O','01111':'P','10000':'Q','10001':'R','10010':'S','10011':'T','10100':'U','10101':'V','10110':'W','10111':'X','11000':'Y','11001':'Z','11010':' ','11011':'.','11100':',','11101':'-','11110':'\'','11111':'?'}

while True:
	try:
		string = list(raw_input().replace("\n", ""))
		
		# encode
		code = ""
		for s in string:
			code += encode[s]
		i = 0
		tmp = []
		while i+5 <= len(code):
			tmp.append(code[i:i+5])
			code = code[i+5:]
		if len(code) != 0:
			code += '0' * (5 - len(code))
			tmp.append(code)

		# decode
		ans = ""
		for s in tmp:
			ans += decode[s]
		print ans
	except EOFError:
		break

Submission status: Runtime Error

Solution code:
encode = {' ':'101', '\'':'000000', ',':'000011', '-':'1001000', '.':'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', 'X':'10010000'}
decode = {'00000':'A', '00001':'B', '00010':'C', '00011':'D', '00100':'E','00101':'F','00110':'G','00111':'H','01000':'I','01001':'J','01010':'K','01011':'L','01100':'M','01101':'N','01110':'O','01111':'P','10000':'Q','10001':'R','10010':'S','10011':'T','10100':'U','10101':'V','10110':'W','10111':'X','11000':'Y','11001':'Z','11010':' ','11011':'.','11100':',','11101':'-','11110':'\'','11111':'?'}

while True:
	try:
		string = raw_input()
	except EOFError:
		break		

	# encode
	e, ans = "", ""
	for s in string:
		e += encode[s]
	tmp = []
	while len(e) > 4:
		tmp.append(e[0:5])
		e = e[5:]
	if len(e) != 0:
		e += '0' * (5 - len(e))
		tmp.append(e)
	print tmp

	# decode
	for s in tmp:
		ans += decode[s]
	print ans

Submission status: Runtime Error

Solution code:
import sys
A=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"
B="101 000000 000011 10010001 010001 000001 100101 10011010 "\
  "0101 0001 110 01001 10011011 010000 0111 10011000 "\
  "0110 00100 10011001 10011110 00101 111 10011111 1000 "\
  "00110 00111 10011100 10011101 000010 10010010 10010011 10010000".split()
C="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"
d1={}
for i in range(26):d1[A[i]]=B[i]
for s in sys.stdin:
  x=""
  for c in s[:-1]:x+=d1[c]
  x+="0"*(-len(x)%5)
  s=""
  for i in range(0,len(x),5):s+=C[int(x[i:i+5],2)]
  print s