Problem:


博士の暗号

博  士 : ?D-C'KOPUA

ピーター : どうしたんですか、デビッド博士? わけのわからないことを叫ぶのにはもう慣れましたが、
        今日は文章にすらなっていませんよ。

博  士 : ほれ。

ピーター : なんですか? この表は......ああ、予選の問題にこんなのがありました。表を使って文字を置き換え
       ると文字数が減るんですよね。まさか予選と本選で同じ問題を出して手を抜こうって気じゃないでし
       ょうね。

博  士 : 逆じゃよ。

ピーター : 逆? なるほど、今度は短くした文字列を元に戻そうって問題ですか。ということは「?D-C'KOPUA」の
      文字を、この表を使って「文字」から「符号」に置きかえるんですね......できましたよ。

11111 00011 11101 00010 11110 01010 01110 01111 10100 00000

博  士 : うむ。次はこれじゃ。

ピーター : そうそう、こんな表もありましたね。これを逆に使うんだから「符号」から「文字」に置き換えればいい
          んですね。でも、最初は「11111」ですが表にありませんよ?

博     士 : そういうときは、もっと短くするか、後ろとつなげるかしてみるのだよ。

ピ ー タ ー : じゃあ短くして......あ、 「111」ならあります。じゃあ最初は「P」ですね。そうすると残りは「11」ですが、
            これはぴったり合うのがないから次の「00011」から 1 文字借りて「110」にすればいいんですね。

博     士 : そうそう。つまり「E」だね。

ピ ー タ ー : それで残るのが「0011」なので、これも次から借りて「00111」にして「T」と......。全部できました。最
          後の「0000」は捨てちゃえばいいんですよね?

博     士 : そうじゃ、よろしい。次はこれじゃ。

?D-C'?-C'-LMGZN?FNJKN- WEYN?P'QMRWLPZLKKTPOVRGDI

博     士 : さらにこれじゃ。

?P'QNPY?IXX?IXXK.BI -G?R'RPP'RPOVWDMW?SWUVG'-LCMGQ

博     士 : 仕上げにこうじゃ。

?P'QMDUEQ GADKOQ ?SWUVG'-LCMG?X?IGX,PUL.?UL.VNQQI

ピ ー タ ー : しっかし面倒だなあ。博士、今度は自分でプログラムを作って下さいよ。

  ということで、博士のかわりに、上の文章を置き換えるプログラムを作成してください。

Input

複数のデータセットが与えられます。各データセットとして、１つの文字列（表に含まれる文字からなる 200 文字以下の文字列）が１行に与えられます。入力の終わりまで処理してください。データセットの数は 200 を超えません。

Output

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

Sample Input

?D-C'KOPUA

Output for the Sample Input

PETER POTTER



Sample input:
?D-C'KOPUA


Sample output:
PETER POTTER

Submission status: Wrong Answer

Solution code:
import sys
e="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"
d={'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'}
for a in sys.stdin:
 w=s=''
 for c in''.join([str(bin(e.index(c))[2:].zfill(5))for c in a.strip()]):
  w+=c
  if w in d:s+=d[w];w=''
 print(s)

Submission status: Wrong Answer

Solution code:
import sys
e="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"
d={'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'}
for a in sys.stdin:
 w=s=''
 for c in''.join([str(bin(e.index(c))[2:].zfill(5))for c in a.strip()]):
  w+=c
  if w in d:s+=d[w];w=''
 print(s)

Submission status: Wrong Answer

Solution code:
import sys
e="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"
d={'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'}
for a in sys.stdin:
 w=s=''
 for c in''.join(bin(e.index(c))[2:].zfill(5)for c in a.strip()):
  w+=c
  if w in d:s+=d[w];w=''
 print(s)

Submission status: Wrong Answer

Solution code:
import sys
d={'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'}
for a in sys.stdin:
 w=s=''
 for c in''.join(bin("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?".index(c))[2:].zfill(5)for c in a.strip()):
  w+=c
  if w in d:s+=d[w];w=''
 print(s)

Submission status: Wrong Answer

Solution code:
import sys
d={'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'}
for a in sys.stdin:
 w=s=""
 for c in"".join(bin("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?".index(c))[2:].zfill(5)for c in a.strip()):
  w+=c
  if w in d:s+=d[w];w=""
 print(s)

Submission status: Wrong Answer

Solution code:
import sys
d={'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'}
for a in sys.stdin:
 w=s=""
 for x in"".join(bin("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?".index(c))[2:].zfill(5)for c in a.strip()):
  w+=x
  if w in d:s+=d[w];w=""
 print(s)

Submission status: Wrong Answer

Solution code:
import sys
d={'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'}
for a in sys.stdin:
 w=s=""
 for x in"".join(bin("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?".index(c))[2:].zfill(5)for c in a.strip()):
  w+=x
  if w in d:s+=d[w];w=""
 print(s)

Submission status: Wrong Answer

Solution code:
import sys
d={'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'}
for a in sys.stdin:
 w=s=""
 for x in"".join(bin("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-\'?".index(c))[2:].zfill(5)for c in a.strip()):
  w+=x
  if w in d:s+=d[w];w=""
 print(s)

Submission status: Wrong Answer

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

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

S1 = input()
S2 = ""

for i in range(len(S1)):
    S2 = S2 + dict[S1[i]]

S3 = ""
while S2 != "":
    flag = False
    for i in range(3, len(S2)):
        s = S2[0:i]
        if s in dict2:
            S3 = S3 + dict2[s]
            S2 = S2[i:]
            flag = True
            break
    if flag == False:
        break

print(S3)

Submission status: Wrong Answer

Solution code:
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

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

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

N = list(get_input())

for l in range(len(N)):
    S1 = N[l]
    S2 = ""

    for i in range(len(S1)):
        S2 = S2 + dict[S1[i]]

    S3 = ""
    while S2 != "":
        flag = False
        for i in range(3, len(S2)):
            s = S2[0:i]
            if s in dict2:
                S3 = S3 + dict2[s]
                S2 = S2[i:]
                flag = True
                break
        if flag == False:
            break

    print(S3)

Submission status: Wrong Answer

Solution code:
import sys
def cv1(c):
    o=ord(c)
    if 65<=o<=90:
        return format(o-65,"05b")
    elif o==32:
        return "11010"
    elif o==46:
        return "11011"
    elif o==44:
        return "11100"
    elif o==45:
        return "11101"
    elif o==39:
        return "11110"
    elif o==63:
        return "11111"

d={"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"
   }
sk=sorted(d.keys(),key=lambda x:len(x))   

for t in sys.stdin:
    t=t.strip()
    cn=0
    st=[]
    ta="".join([cv1(i) for i in t])

    while 1:
        for (j,i) in enumerate(sk):
            if ta[cn:cn+len(i)]==i:
                st.extend([d[i]])
                cn+=len(i)
                break
        if j==31:break
    print("".join(st))

Submission status: Wrong Answer

Solution code:
import sys
def cv1(c):
    o=ord(c)
    if 65<=o<=90:
        return format(o-65,"05b")
    elif o==32:
        return "11010"
    elif o==46:
        return "11011"
    elif o==44:
        return "11100"
    elif o==45:
        return "11101"
    elif o==39:
        return "11110"
    elif o==63:
        return "11111"

d={"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"
   }
sk=sorted(d.keys(),key=lambda x:len(x))   

for t in sys.stdin:
    t=t.strip("\n")
    cn=0
    st=[]
    ta="".join([cv1(i) for i in t])
    #print(ta)

    while 1:
        for (j,i) in enumerate(sk):
            if ta[cn:cn+len(i)]==i:
                st.extend([d[i]])
                cn+=len(i)
                break
        if j==31:break
    print("".join(st))

Submission status: Wrong Answer

Solution code:
import sys
def cv1(c):
    o=ord(c)
    if 65<=o<=90:
        return format(o-65,"05b")
    elif o==32:
        return "11010"
    elif o==46:
        return "11011"
    elif o==44:
        return "11100"
    elif o==45:
        return "11101"
    elif o==39:
        return "11110"
    elif o==63:
        return "11111"

d={"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"
   }
sk=sorted(d.keys(),key=lambda x:len(x))   

for t in sys.stdin:
    cn=0
    st=[]
    ta="".join([cv1(i) for i in t[:-1]])

    while 1:
        for (j,i) in enumerate(sk):
            if ta[cn:cn+len(i)]==i:
                st.extend([d[i]])
                cn+=len(i)
                break
        if j==31:break
    print("".join(st))

Submission status: Wrong Answer

Solution code:
import sys
def cv1(c):
    o=ord(c)
    if 65<=o<=90:
        return format(o-65,"05b")
    elif o==32:
        return "11010"
    elif o==46:
        return "11011"
    elif o==44:
        return "11100"
    elif o==45:
        return "11101"
    elif o==39:
        return "11110"
    elif o==63:
        return "11111"

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

sk=sorted(d.keys(),key=lambda x:len(x))   
def main(args):
    for t in sys.stdin:
        cn=0
        st=[]
        ta="".join([cv1(i) for i in t[:-1]])

        while 1:
            for (j,i) in enumerate(sk):
                if ta[cn:cn+len(i)]==i:
                    st.extend([d[i]])
                    cn+=len(i)
                    break
            if j==31:break
        print("".join(st))

if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
tableA,tableB = {},{}
def main():
    make_table()
    s = "".join(map(lambda c: tableA[c],raw_input()))
    tmp,ans = "",""
    for c in s:
        tmp += c
        if tmp in tableB:
            ans += tableB[tmp]
            tmp = ""
    print ans
    
def make_table():
    global tableA,tableB
    tableA={
        "A":"00000",
        "B":"00001",
        "C":"00010",
        "D":"00011",
        "E":"00100",
        "F":"00101",
        "G":"00110",
        "H":"00111",
        "I":"01000",
        "J":"01001",
        "K":"01010",
        "L":"01011",
        "M":"01100",
        "N":"01101",
        "O":"01110",
        "P":"01111",
        "Q":"10000",
        "R":"10001",
        "S":"10010",
        "T":"10011",
        "U":"10100",
        "V":"10101",
        "W":"10110",
        "X":"10111", 
        "Y":"11000",
        "Z":"11001",
        " ":"11010",
        ".":"11011",
        ",":"11100",
        "-":"11101",
        "\'":"11110",
        "?":"11111"}
    tableB ={
        "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'}

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
tableA,tableB = {},{}
def main():
    make_table()
    s = "".join(map(lambda c: tableA[c],raw_input()))
    tmp,ans = "",""
    for c in s:
        tmp += c
        if tmp in tableB:
            ans += tableB[tmp]
            tmp = ""
    print ans
    
def make_table():
    global tableA,tableB
    tableA={
        "A":"00000",
        "B":"00001",
        "C":"00010",
        "D":"00011",
        "E":"00100",
        "F":"00101",
        "G":"00110",
        "H":"00111",
        "I":"01000",
        "J":"01001",
        "K":"01010",
        "L":"01011",
        "M":"01100",
        "N":"01101",
        "O":"01110",
        "P":"01111",
        "Q":"10000",
        "R":"10001",
        "S":"10010",
        "T":"10011",
        "U":"10100",
        "V":"10101",
        "W":"10110",
        "X":"10111", 
        "Y":"11000",
        "Z":"11001",
        " ":"11010",
        ".":"11011",
        ",":"11100",
        "-":"11101",
        "\'":"11110",
        "?":"11111"}
    tableB ={
        "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'}

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


code_table = {chr(65+i): '{:05b}'.format(i) for i in range(26)}
code_table.update({' ': '11010', '.': '11011', ',': '11100', '-': '11101',
                   "'": '11110', '?': '11111'})

decrypt = {
    '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'}


def main():
    for line in stdin:
        buf = ''
        for c in ''.join(code_table[c] for c in line.rstrip()):
            buf += c
            plain = decrypt.get(buf)
            if plain:
                print(plain, end='')
                buf = ''
        print()
    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


code_table = {chr(65+i): '{:05b}'.format(i) for i in range(26)}
code_table.update({' ': '11010', '.': '11011', ',': '11100', '-': '11101',
                   "'": '11110', '?': '11111'})


def decrypt(it):
    if int(next(it)):
        if int(next(it)):
            if int(next(it)):
                return 'P'
            else:
                return 'E'
        else:
            if int(next(it)):
                return ' '
            else:
                if int(next(it)):
                    if int(next(it)):
                        if int(next(it)):
                            if int(next(it)):
                                if int(next(it)):
                                    return 'Q'
                                else:
                                    return 'N'
                            else:
                                if int(next(it)):
                                    return 'V'
                                else:
                                    return 'U'
                        else:
                            if int(next(it)):
                                if int(next(it)):
                                    return 'G'
                                else:
                                    return 'B'
                            else:
                                if int(next(it)):
                                    return 'M'
                                else:
                                    return 'J'
                    else:
                        if int(next(it)):
                            return 'A'
                        else:
                            if int(next(it)):
                                if int(next(it)):
                                    return 'Y'
                                else:
                                    return 'X'
                            else:
                                if int(next(it)):
                                    return '-'
                                else:
                                    return 'Z'
                else:
                    return 'R'
    else:
        if int(next(it)):
            if int(next(it)):
                if int(next(it)):
                    return 'I'
                else:
                    return 'K'
            else:
                if int(next(it)):
                    return 'C'
                else:
                    if int(next(it)):
                        return 'F'
                    else:
                        if int(next(it)):
                            return '.'
                        else:
                            return 'H'
        else:
            if int(next(it)):
                if int(next(it)):
                    if int(next(it)):
                        return 'T'
                    else:
                        return 'S'
                else:
                    if int(next(it)):
                        return 'O'
                    else:
                        return 'L'
            else:
                if int(next(it)):
                    return 'D'
                else:
                    if int(next(it)):
                        if int(next(it)):
                            return ','
                        else:
                            return 'W'
                    else:
                        if int(next(it)):
                            return '?'
                        else:
                            return "'"


def main():
    for line in stdin:
        it = iter(''.join(code_table[c] for c in line.rstrip()))
        try:
            while 1:
                print(decrypt(it), end='')
        except StopIteration:
            print()
    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
ctob={"A":"00000", "B":"00001", "C":"00010", "D":"00011", "E":"00100", "F":"00101", "G":"00110", "H":"00111", "I":"01000", "J":"01001", "K":"01010", "L":"01011", "M":"01100", "N":"01101", "O":"01110", "P":"01111", "Q":"10000", "R":"10001", "S":"10010", "T":"10011", "U":"10100", "V":"10101", "W":"10110", "X":"10111", "Y":"11000", "Z":"11001", " ":"11010", ".":"11011", ",":"11100", "-":"11101", "'":"11110", "?":"11111"}
btoc={'0110': 'K', '0111': 'I', '111': 'P', '110': 'E', '10011010': 'B', '10011011': 'G', '000011': ',', '000010': 'W', '10011111': 'Q', '10011110': 'N', '100101': 'A', '01001': 'F', '00111': 'T', '00110': 'S', '10010010': 'X', '0001': 'D', '0101': 'C', '10010000': 'Z', '10010001': '-', '101': ' ', '10011001': 'M', '10011000': 'J', '10011100': 'U', '10011101': 'V', '000000': "'", '000001': '?', '010001': '.', '010000': 'H', '10010011': 'Y', '00100': 'L', '00101': 'O', '1000': 'R'}

while 1:
	try:
		a=raw_input()
		b=""
		for w in a:
			b+=ctob[w]
		sp=0
		ans=""
		for i in range(1,len(b)):
			if b[sp:i] in btoc:
				ans+=btoc[b[sp:i]]
				sp=i
		print ans
	except:
		break

Submission status: Wrong Answer

Solution code:
ctob={"A":"00000", "B":"00001", "C":"00010", "D":"00011", "E":"00100", "F":"00101", "G":"00110", "H":"00111", "I":"01000", "J":"01001", "K":"01010", "L":"01011", "M":"01100", "N":"01101", "O":"01110", "P":"01111", "Q":"10000", "R":"10001", "S":"10010", "T":"10011", "U":"10100", "V":"10101", "W":"10110", "X":"10111", "Y":"11000", "Z":"11001", " ":"11010", ".":"11011", ",":"11100", "-":"11101", "'":"11110", "?":"11111"}
btoc={'0110': 'K', '0111': 'I', '111': 'P', '110': 'E', '10011010': 'B', '10011011': 'G', '000011': ',', '000010': 'W', '10011111': 'Q', '10011110': 'N', '100101': 'A', '01001': 'F', '00111': 'T', '00110': 'S', '10010010': 'X', '0001': 'D', '0101': 'C', '10010000': 'Z', '10010001': '-', '101': ' ', '10011001': 'M', '10011000': 'J', '10011100': 'U', '10011101': 'V', '000000': "'", '000001': '?', '010001': '.', '010000': 'H', '10010011': 'Y', '00100': 'L', '00101': 'O', '1000': 'R'}

a,ans="",""
while 1:
	try:
		a+=raw_input()
	except:
		break	
b=""
for w in a:
	b+=ctob[w]
sp=0
for i in range(1,len(b)):
	if b[sp:i] in btoc:
		ans+=btoc[b[sp:i]]
		sp=i
print ans

Submission status: Time Limit Exceeded

Solution code:
import string
s = {i : "{:05b}".format(c) for i, c in zip(string.ascii_uppercase+" .,-'?", range(32))}
code = {'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'}

while True:
    try:
        data = input()
    except:
        break
    d = ''.join(s[c] for c in data)
    ans = ""
    a, i = 0, 3
    while a+i != len(d):
        i = 3
        while True:
            if code.get(d[a:a+i], None) is not None:
                ans += code[d[a:a+i]]
                a += i
                break
            i += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import string
s = {i : "{:05b}".format(c) for i, c in zip(string.ascii_uppercase+" .,-'?", range(32))}
code = {'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'}

while True:
    try:
        data = input()
    except:
        break
    d = ''.join(s[c] for c in data)
    ans = ""
    a, i = 0, 3
    while a+i != len(d):
        i = 3
        while i<9:
            if code.get(d[a:a+i], None) is not None:
                ans += code[d[a:a+i]]
                a += i
                break
            i += 1
    print(ans)

Submission status: Accepted

Solution code:
while(True):
    try:
        s = input()
    except:
        break
    ec = dict([t,str(bin(i))[2:].zfill(5)] for i,t in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"))
    c = "".join(ec[e] for e in s)
    dc = {"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"}
    ans = ""
    i=0
    while(i<len(c)):
        for j in range(3,9):
            try: ans += dc[c[i:i+j]]; i+=j; break
            except: continue
        else:
            break
    print(ans)

Submission status: Accepted

Solution code:
import sys

def f1(s): return "".join([d0[c] for c in s])

d0={"M":"10010","N":"10011"}
a="ABCD";
for i in range(4): d0[a[i]]=format(i,"02b")
a="EFGHIJKL"
for i in range(8): d0[a[i]]=format(i,"03b")
L0="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
L1=" ',-.?"+L0
L2=L0+" .,-'?"

dc={}
a="J,EE,EH,MF,GF,EF,IJ,NG,BB,AB,K,BF,NH,GE,BD,NE,BC,"\
  "AI,NF,NK,AJ,L,NL,CA,AK,AL,NI,NJ,EG,MG,MH,ME".split(",")
for i,e in enumerate(a): dc[f1(e)]=L1[i]
ec={}
for i in range(32): ec[L2[i]]=format(i,"05b")
for s0 in sys.stdin:
  s1="".join([ec[c] for c in s0.strip("\n")])
  s=""
  x=""
  for c in s1:
    s+=c
    if s in dc: x+=dc[s]; s=""
  print x